Files
dolt/chunks/chunk_store.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

57 lines
1.9 KiB
Go

package chunks
import (
"fmt"
"io"
"github.com/attic-labs/noms/ref"
)
// ChunkStore is the core storage abstraction in noms. We can put data anyplace we have a ChunkStore implementation for.
type ChunkStore interface {
ChunkSource
ChunkSink
RootTracker
}
// Factory allows the creation of namespaced ChunkStore instances. The details of how namespaces are separated is left up to the particular implementation of Factory and ChunkStore.
type Factory interface {
CreateStore(ns string) ChunkStore
// Shutter shuts down the factory. Subsequent calls to CreateStore() will fail.
Shutter()
}
// RootTracker allows querying and management of the root of an entire tree of references. The "root" is the single mutable variable in a ChunkStore. It can store any ref, but it is typically used by higher layers (such as DataStore) to store a ref to a value that represents the current state and entire history of a datastore.
type RootTracker interface {
Root() ref.Ref
UpdateRoot(current, last ref.Ref) bool
}
// ChunkSource is a place to get chunks from.
type ChunkSource interface {
// Get gets a reader for the value of the Ref in the store. If the ref is absent from the store nil is returned.
Get(ref ref.Ref) Chunk
// Returns true iff the value at the address |ref| is contained in the source
Has(ref ref.Ref) bool
}
// ChunkSink is a place to put chunks.
type ChunkSink interface {
// Put writes c into the ChunkSink, blocking until the operation is complete.
Put(c Chunk)
// PutMany tries to write chunks into the sink. It will block as it handles as many as possible, then return a BackpressureError containing the rest (if any).
PutMany(chunks []Chunk) BackpressureError
io.Closer
}
// BackpressureError is a slice of Chunk that indicates some chunks could not be Put(). Caller is free to try to Put them again later.
type BackpressureError []Chunk
func (b BackpressureError) Error() string {
return fmt.Sprintf("Tried to Put %d too many Chunks", len(b))
}