Files
dolt/chunks/put_cache.go
Chris Masone d8a2d285e9 Pull DataStore API over the wire and kill chunks.HTTPStore
This patch is unfortunately large, but it seemed necessary to make all
these changes at once to transition away from having an HTTP
ChunkStore that could allow for invalid state in the DB. Now, we have
a RemoteDataStoreClient that allows for reading and writing of Values,
and performs validation on the server side before persisting chunks.
The semantics of DataStore are that written values can be read back
out immediately, but are not guaranteed to be persistent until after
Commit() The semantics are now that Put() blocks until the Chunk is
persisted, and the new PutMany() can be used to write a number of
Chunks all at once.

From a command-line tool point of view, -h and -h-auth still work as
expected.
2016-04-12 14:08:58 -07:00

52 lines
921 B
Go

package chunks
import (
"sync"
"github.com/attic-labs/noms/ref"
)
func newUnwrittenPutCache() *unwrittenPutCache {
return &unwrittenPutCache{map[ref.Ref]Chunk{}, &sync.Mutex{}}
}
type unwrittenPutCache struct {
unwrittenPuts map[ref.Ref]Chunk
mu *sync.Mutex
}
func (p *unwrittenPutCache) Add(c Chunk) bool {
p.mu.Lock()
defer p.mu.Unlock()
if _, ok := p.unwrittenPuts[c.Ref()]; !ok {
p.unwrittenPuts[c.Ref()] = c
return true
}
return false
}
func (p *unwrittenPutCache) Has(c Chunk) (has bool) {
p.mu.Lock()
defer p.mu.Unlock()
_, has = p.unwrittenPuts[c.Ref()]
return
}
func (p *unwrittenPutCache) Get(r ref.Ref) Chunk {
p.mu.Lock()
defer p.mu.Unlock()
if c, ok := p.unwrittenPuts[r]; ok {
return c
}
return EmptyChunk
}
func (p *unwrittenPutCache) Clear(chunks []Chunk) {
p.mu.Lock()
defer p.mu.Unlock()
for _, c := range chunks {
delete(p.unwrittenPuts, c.Ref())
}
}