Documentation ¶
Overview ¶
Package chunks provides facilities for representing, storing, and fetching content-addressed chunks of Noms data.
Index ¶
- Variables
- func Deserialize(reader io.Reader, chunkChan chan<- *Chunk) (err error)
- func NewMemoryStoreFactory() *memoryStoreFactory
- func Serialize(chunk Chunk, writer io.Writer)
- type AbsentManyRequest
- type AbsentRequest
- type CSMetricWrapper
- func (csMW *CSMetricWrapper) Close() error
- func (csMW *CSMetricWrapper) Commit(ctx context.Context, current, last hash.Hash) (bool, error)
- func (csMW *CSMetricWrapper) Get(ctx context.Context, h hash.Hash) (Chunk, error)
- func (csMW *CSMetricWrapper) GetMany(ctx context.Context, hashes hash.HashSet, found func(context.Context, *Chunk)) error
- func (csMW *CSMetricWrapper) Has(ctx context.Context, h hash.Hash) (bool, error)
- func (csMW *CSMetricWrapper) HasMany(ctx context.Context, hashes hash.HashSet) (absent hash.HashSet, err error)
- func (csMW *CSMetricWrapper) Put(ctx context.Context, c Chunk) error
- func (csMW *CSMetricWrapper) Rebase(ctx context.Context) error
- func (csMW *CSMetricWrapper) Root(ctx context.Context) (hash.Hash, error)
- func (csMW *CSMetricWrapper) Stats() interface{}
- func (csMW *CSMetricWrapper) StatsSummary() string
- func (csMW *CSMetricWrapper) Version() string
- type CSMetrics
- type Chunk
- type ChunkStore
- type ChunkStoreGarbageCollector
- type ChunkWriter
- type DebugLogger
- type GenerationalCS
- type GetManyRequest
- type GetRequest
- type LoggingChunkStore
- type MemoryStorage
- func (ms *MemoryStorage) Get(ctx context.Context, h hash.Hash) (Chunk, error)
- func (ms *MemoryStorage) Has(ctx context.Context, r hash.Hash) (bool, error)
- func (ms *MemoryStorage) Len() int
- func (ms *MemoryStorage) NewView() ChunkStore
- func (ms *MemoryStorage) NewViewWithDefaultFormat() ChunkStore
- func (ms *MemoryStorage) Root(ctx context.Context) hash.Hash
- func (ms *MemoryStorage) Update(current, last hash.Hash, novel map[hash.Hash]Chunk) bool
- type MemoryStoreView
- func (ms *MemoryStoreView) Close() error
- func (ms *MemoryStoreView) Commit(ctx context.Context, current, last hash.Hash) (bool, error)
- func (ms *MemoryStoreView) Get(ctx context.Context, h hash.Hash) (Chunk, error)
- func (ms *MemoryStoreView) GetMany(ctx context.Context, hashes hash.HashSet, found func(context.Context, *Chunk)) error
- func (ms *MemoryStoreView) Has(ctx context.Context, h hash.Hash) (bool, error)
- func (ms *MemoryStoreView) HasMany(ctx context.Context, hashes hash.HashSet) (hash.HashSet, error)
- func (ms *MemoryStoreView) Len() int
- func (ms *MemoryStoreView) MarkAndSweepChunks(ctx context.Context, last hash.Hash, keepChunks <-chan []hash.Hash, ...) error
- func (ms *MemoryStoreView) Put(ctx context.Context, c Chunk) error
- func (ms *MemoryStoreView) Rebase(ctx context.Context) error
- func (ms *MemoryStoreView) Root(ctx context.Context) (hash.Hash, error)
- func (ms *MemoryStoreView) Stats() interface{}
- func (ms *MemoryStoreView) StatsSummary() string
- func (ms *MemoryStoreView) Version() string
- type OutstandingAbsent
- type OutstandingAbsentMany
- type OutstandingGet
- type OutstandingGetMany
- type OutstandingRequest
- type PrefixChunkStore
- type ReadBatch
- type ReadRequest
- type TestStorage
- type TestStoreFactory
- type TestStoreView
- func (s *TestStoreView) Get(ctx context.Context, h hash.Hash) (Chunk, error)
- func (s *TestStoreView) GetMany(ctx context.Context, hashes hash.HashSet, found func(context.Context, *Chunk)) error
- func (s *TestStoreView) Has(ctx context.Context, h hash.Hash) (bool, error)
- func (s *TestStoreView) HasMany(ctx context.Context, hashes hash.HashSet) (hash.HashSet, error)
- func (s *TestStoreView) Hases() int
- func (s *TestStoreView) MarkAndSweepChunks(ctx context.Context, last hash.Hash, keepChunks <-chan []hash.Hash, ...) error
- func (s *TestStoreView) Put(ctx context.Context, c Chunk) error
- func (s *TestStoreView) Reads() int
- func (s *TestStoreView) Writes() int
Constants ¶
This section is empty.
Variables ¶
var EmptyChunk = NewChunk([]byte{})
var ErrGCGenerationExpired = errors.New("garbage collection generation expired")
var ErrNothingToCollect = errors.New("no changes since last gc")
var ErrUnsupportedOperation = errors.New("operation not supported")
Functions ¶
func Deserialize ¶
Deserialize reads off of |reader| until EOF, sending chunks to chunkChan in the order they are read. Objects sent over chunkChan are *Chunk.
func NewMemoryStoreFactory ¶
func NewMemoryStoreFactory() *memoryStoreFactory
Types ¶
type AbsentManyRequest ¶
type AbsentManyRequest struct {
// contains filtered or unexported fields
}
func NewAbsentManyRequest ¶
func (AbsentManyRequest) Hashes ¶
func (h AbsentManyRequest) Hashes() hash.HashSet
func (AbsentManyRequest) Outstanding ¶
func (h AbsentManyRequest) Outstanding() OutstandingRequest
type AbsentRequest ¶
type AbsentRequest struct {
// contains filtered or unexported fields
}
func NewAbsentRequest ¶
func NewAbsentRequest(r hash.Hash, ch chan<- bool) AbsentRequest
func (AbsentRequest) Hashes ¶
func (h AbsentRequest) Hashes() hash.HashSet
func (AbsentRequest) Outstanding ¶
func (h AbsentRequest) Outstanding() OutstandingRequest
type CSMetricWrapper ¶
type CSMetricWrapper struct { TotalChunkGets int32 TotalChunkHasChecks int32 TotalChunkPuts int32 // contains filtered or unexported fields }
CSMetricWrapper is a ChunkStore implementation that wraps a ChunkStore, and collects metrics on the calls.
func NewCSMetricWrapper ¶
func NewCSMetricWrapper(cs ChunkStore) *CSMetricWrapper
NewCSMetricWrapper returns a new CSMetricWrapper
func (*CSMetricWrapper) Close ¶
func (csMW *CSMetricWrapper) Close() error
Close tears down any resources in use by the implementation. After Close(), the ChunkStore may not be used again. It is NOT SAFE to call Close() concurrently with any other ChunkStore method; behavior is undefined and probably crashy.
func (*CSMetricWrapper) Commit ¶
Commit atomically attempts to persist all novel Chunks and update the persisted root hash from last to current (or keeps it the same). If last doesn't match the root in persistent storage, returns false.
func (*CSMetricWrapper) Get ¶
Get the Chunk for the value of the hash in the store. If the hash is absent from the store EmptyChunk is returned.
func (*CSMetricWrapper) GetMany ¶
func (csMW *CSMetricWrapper) GetMany(ctx context.Context, hashes hash.HashSet, found func(context.Context, *Chunk)) error
GetMany gets the Chunks with |hashes| from the store. On return, |foundChunks| will have been fully sent all chunks which have been found. Any non-present chunks will silently be ignored.
func (*CSMetricWrapper) Has ¶
Returns true iff the value at the address |h| is contained in the store
func (*CSMetricWrapper) HasMany ¶
func (csMW *CSMetricWrapper) HasMany(ctx context.Context, hashes hash.HashSet) (absent hash.HashSet, err error)
Returns a new HashSet containing any members of |hashes| that are absent from the store.
func (*CSMetricWrapper) Put ¶
func (csMW *CSMetricWrapper) Put(ctx context.Context, c Chunk) error
Put caches c in the ChunkSource. Upon return, c must be visible to subsequent Get and Has calls, but must not be persistent until a call to Flush(). Put may be called concurrently with other calls to Put(), Get(), GetMany(), Has() and HasMany().
func (*CSMetricWrapper) Rebase ¶
func (csMW *CSMetricWrapper) Rebase(ctx context.Context) error
Rebase brings this ChunkStore into sync with the persistent storage's current root.
func (*CSMetricWrapper) Root ¶
Root returns the root of the database as of the time the ChunkStore was opened or the most recent call to Rebase.
func (*CSMetricWrapper) Stats ¶
func (csMW *CSMetricWrapper) Stats() interface{}
Stats may return some kind of struct that reports statistics about the ChunkStore instance. The type is implementation-dependent, and impls may return nil
func (*CSMetricWrapper) StatsSummary ¶
func (csMW *CSMetricWrapper) StatsSummary() string
StatsSummary may return a string containing summarized statistics for this ChunkStore. It must return "Unsupported" if this operation is not supported.
func (*CSMetricWrapper) Version ¶
func (csMW *CSMetricWrapper) Version() string
Returns the NomsVersion with which this ChunkSource is compatible.
type CSMetrics ¶
type CSMetrics struct { TotalChunkGets int32 TotalChunkHasChecks int32 TotalChunkPuts int32 Delegate interface{} DelegateSummary string }
CSMetrics contains the metrics aggregated by a CSMetricsWrapper
func NewCSMetrics ¶
func NewCSMetrics(csMW *CSMetricWrapper) CSMetrics
NewCSMetrics creates a CSMetrics instance
type Chunk ¶
type Chunk struct {
// contains filtered or unexported fields
}
Chunk is a unit of stored data in noms
func DeserializeData ¶
DeserializeData deserializes a chunk from a byte array
func NewChunk ¶
NewChunk creates a new Chunk backed by data. This means that the returned Chunk has ownership of this slice of memory.
func NewChunkWithHash ¶
NewChunkWithHash creates a new chunk with a known hash. The hash is not re-calculated or verified. This should obviously only be used in cases where the caller already knows the specified hash is correct.
type ChunkStore ¶
type ChunkStore interface { // Get the Chunk for the value of the hash in the store. If the hash is // absent from the store EmptyChunk is returned. Get(ctx context.Context, h hash.Hash) (Chunk, error) // GetMany gets the Chunks with |hashes| from the store. On return, // |foundChunks| will have been fully sent all chunks which have been // found. Any non-present chunks will silently be ignored. GetMany(ctx context.Context, hashes hash.HashSet, found func(context.Context, *Chunk)) error // Returns true iff the value at the address |h| is contained in the // store Has(ctx context.Context, h hash.Hash) (bool, error) // Returns a new HashSet containing any members of |hashes| that are // absent from the store. HasMany(ctx context.Context, hashes hash.HashSet) (absent hash.HashSet, err error) // Put caches c in the ChunkSource. Upon return, c must be visible to // subsequent Get and Has calls, but must not be persistent until a call // to Flush(). Put may be called concurrently with other calls to Put(), // Get(), GetMany(), Has() and HasMany(). Put(ctx context.Context, c Chunk) error // Returns the NomsVersion with which this ChunkSource is compatible. Version() string // Rebase brings this ChunkStore into sync with the persistent storage's // current root. Rebase(ctx context.Context) error // Root returns the root of the database as of the time the ChunkStore // was opened or the most recent call to Rebase. Root(ctx context.Context) (hash.Hash, error) // Commit atomically attempts to persist all novel Chunks and update the // persisted root hash from last to current (or keeps it the same). // If last doesn't match the root in persistent storage, returns false. Commit(ctx context.Context, current, last hash.Hash) (bool, error) // Stats may return some kind of struct that reports statistics about the // ChunkStore instance. The type is implementation-dependent, and impls // may return nil Stats() interface{} // StatsSummary may return a string containing summarized statistics for // this ChunkStore. It must return "Unsupported" if this operation is not // supported. StatsSummary() string // Close tears down any resources in use by the implementation. After // Close(), the ChunkStore may not be used again. It is NOT SAFE to call // Close() concurrently with any other ChunkStore method; behavior is // undefined and probably crashy. io.Closer }
ChunkStore is the core storage abstraction in noms. We can put data anyplace we have a ChunkStore implementation for.
type ChunkStoreGarbageCollector ¶
type ChunkStoreGarbageCollector interface { ChunkStore // MarkAndSweepChunks expects |keepChunks| to receive the chunk hashes // that should be kept in the chunk store. Once |keepChunks| is closed // and MarkAndSweepChunks returns, the chunk store will only have the // chunks sent on |keepChunks| and will have removed all other content // from the ChunkStore. MarkAndSweepChunks(ctx context.Context, last hash.Hash, keepChunks <-chan []hash.Hash, dest ChunkStore) error }
ChunkStoreGarbageCollector is a ChunkStore that supports garbage collection.
type ChunkWriter ¶
type ChunkWriter struct {
// contains filtered or unexported fields
}
ChunkWriter wraps an io.WriteCloser, additionally providing the ability to grab the resulting Chunk for all data written through the interface. Calling Chunk() or Close() on an instance disallows further writing.
func NewChunkWriter ¶
func NewChunkWriter() *ChunkWriter
func (*ChunkWriter) Chunk ¶
func (w *ChunkWriter) Chunk() Chunk
Chunk() closes the writer and returns the resulting Chunk.
func (*ChunkWriter) Close ¶
func (w *ChunkWriter) Close() error
Close() closes computes the hash and Puts it into the ChunkSink Note: The Write() method never returns an error. Instead, like other noms interfaces, errors are reported via panic.
type DebugLogger ¶
type DebugLogger interface {
Logf(fmt string, args ...interface{})
}
type GenerationalCS ¶
type GenerationalCS interface { NewGen() ChunkStoreGarbageCollector OldGen() ChunkStoreGarbageCollector }
GenerationalCS is an interface supporting the getting old gen and new gen chunk stores
type GetManyRequest ¶
type GetManyRequest struct {
// contains filtered or unexported fields
}
func NewGetManyRequest ¶
func (GetManyRequest) Hashes ¶
func (g GetManyRequest) Hashes() hash.HashSet
func (GetManyRequest) Outstanding ¶
func (g GetManyRequest) Outstanding() OutstandingRequest
type GetRequest ¶
type GetRequest struct {
// contains filtered or unexported fields
}
func NewGetRequest ¶
func NewGetRequest(r hash.Hash, ch chan<- *Chunk) GetRequest
func (GetRequest) Hashes ¶
func (g GetRequest) Hashes() hash.HashSet
func (GetRequest) Outstanding ¶
func (g GetRequest) Outstanding() OutstandingRequest
type LoggingChunkStore ¶
type LoggingChunkStore interface { ChunkStore SetLogger(logger DebugLogger) }
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage provides a "persistent" storage layer to back multiple MemoryStoreViews. A MemoryStorage instance holds the ground truth for the root and set of chunks that are visible to all MemoryStoreViews vended by NewView(), allowing them to implement the transaction-style semantics that ChunkStore requires.
func (*MemoryStorage) Get ¶
Get retrieves the Chunk with the Hash h, returning EmptyChunk if it's not present.
func (*MemoryStorage) Has ¶
Has returns true if the Chunk with the Hash h is present in ms.data, false if not.
func (*MemoryStorage) Len ¶
func (ms *MemoryStorage) Len() int
Len returns the number of Chunks in ms.data.
func (*MemoryStorage) NewView ¶
func (ms *MemoryStorage) NewView() ChunkStore
NewView vends a MemoryStoreView backed by this MemoryStorage. It's initialized with the currently "persisted" root.
func (*MemoryStorage) NewViewWithDefaultFormat ¶
func (ms *MemoryStorage) NewViewWithDefaultFormat() ChunkStore
NewViewWithVersion vends a MemoryStoreView backed by this MemoryStorage. It's initialized with the currently "persisted" root. Uses the default format.
type MemoryStoreView ¶
type MemoryStoreView struct {
// contains filtered or unexported fields
}
MemoryStoreView is an in-memory implementation of store.ChunkStore. Useful mainly for tests. The proper way to get one: storage := &MemoryStorage{} ms := storage.NewView()
func (*MemoryStoreView) Close ¶
func (ms *MemoryStoreView) Close() error
func (*MemoryStoreView) Len ¶
func (ms *MemoryStoreView) Len() int
func (*MemoryStoreView) MarkAndSweepChunks ¶
func (ms *MemoryStoreView) MarkAndSweepChunks(ctx context.Context, last hash.Hash, keepChunks <-chan []hash.Hash, dest ChunkStore) error
func (*MemoryStoreView) Stats ¶
func (ms *MemoryStoreView) Stats() interface{}
func (*MemoryStoreView) StatsSummary ¶
func (ms *MemoryStoreView) StatsSummary() string
func (*MemoryStoreView) Version ¶
func (ms *MemoryStoreView) Version() string
type OutstandingAbsent ¶
type OutstandingAbsent chan<- bool
func (OutstandingAbsent) Fail ¶
func (oh OutstandingAbsent) Fail()
type OutstandingAbsentMany ¶
type OutstandingAbsentMany struct {
// contains filtered or unexported fields
}
func (OutstandingAbsentMany) Fail ¶
func (ohm OutstandingAbsentMany) Fail()
type OutstandingGet ¶
type OutstandingGet chan<- *Chunk
func (OutstandingGet) Fail ¶
func (r OutstandingGet) Fail()
type OutstandingGetMany ¶
type OutstandingGetMany struct {
// contains filtered or unexported fields
}
func (OutstandingGetMany) Fail ¶
func (ogm OutstandingGetMany) Fail()
type OutstandingRequest ¶
type PrefixChunkStore ¶
type ReadBatch ¶
type ReadBatch map[hash.Hash][]OutstandingRequest
ReadBatch represents a set of queued Get/Has requests, each of which are blocking on a receive channel for a response.
type ReadRequest ¶
type ReadRequest interface { Hashes() hash.HashSet Outstanding() OutstandingRequest }
type TestStorage ¶
type TestStorage struct {
MemoryStorage
}
func (*TestStorage) NewView ¶
func (t *TestStorage) NewView() *TestStoreView
type TestStoreFactory ¶
type TestStoreFactory struct {
// contains filtered or unexported fields
}
func NewTestStoreFactory ¶
func NewTestStoreFactory() *TestStoreFactory
func (*TestStoreFactory) CreateStore ¶
func (f *TestStoreFactory) CreateStore(ns string) ChunkStore
func (*TestStoreFactory) Shutter ¶
func (f *TestStoreFactory) Shutter()
type TestStoreView ¶
type TestStoreView struct { ChunkStore // contains filtered or unexported fields }
func (*TestStoreView) Hases ¶
func (s *TestStoreView) Hases() int
func (*TestStoreView) MarkAndSweepChunks ¶
func (s *TestStoreView) MarkAndSweepChunks(ctx context.Context, last hash.Hash, keepChunks <-chan []hash.Hash, dest ChunkStore) error
func (*TestStoreView) Reads ¶
func (s *TestStoreView) Reads() int
func (*TestStoreView) Writes ¶
func (s *TestStoreView) Writes() int