github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/chunks/chunk_store.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // This file incorporates work covered by the following copyright and 16 // permission notice: 17 // 18 // Copyright 2016 Attic Labs, Inc. All rights reserved. 19 // Licensed under the Apache License, version 2.0: 20 // http://www.apache.org/licenses/LICENSE-2.0 21 22 package chunks 23 24 import ( 25 "context" 26 "errors" 27 "io" 28 29 "github.com/dolthub/dolt/go/store/hash" 30 ) 31 32 // ChunkStore is the core storage abstraction in noms. We can put data 33 // anyplace we have a ChunkStore implementation for. 34 type ChunkStore interface { 35 // Get the Chunk for the value of the hash in the store. If the hash is 36 // absent from the store EmptyChunk is returned. 37 Get(ctx context.Context, h hash.Hash) (Chunk, error) 38 39 // GetMany gets the Chunks with |hashes| from the store. On return, 40 // |foundChunks| will have been fully sent all chunks which have been 41 // found. Any non-present chunks will silently be ignored. 42 GetMany(ctx context.Context, hashes hash.HashSet, found func(*Chunk)) error 43 44 // Returns true iff the value at the address |h| is contained in the 45 // store 46 Has(ctx context.Context, h hash.Hash) (bool, error) 47 48 // Returns a new HashSet containing any members of |hashes| that are 49 // absent from the store. 50 HasMany(ctx context.Context, hashes hash.HashSet) (absent hash.HashSet, err error) 51 52 // Put caches c in the ChunkSource. Upon return, c must be visible to 53 // subsequent Get and Has calls, but must not be persistent until a call 54 // to Flush(). Put may be called concurrently with other calls to Put(), 55 // Get(), GetMany(), Has() and HasMany(). 56 Put(ctx context.Context, c Chunk) error 57 58 // Returns the NomsVersion with which this ChunkSource is compatible. 59 Version() string 60 61 // Rebase brings this ChunkStore into sync with the persistent storage's 62 // current root. 63 Rebase(ctx context.Context) error 64 65 // Root returns the root of the database as of the time the ChunkStore 66 // was opened or the most recent call to Rebase. 67 Root(ctx context.Context) (hash.Hash, error) 68 69 // Commit atomically attempts to persist all novel Chunks and update the 70 // persisted root hash from last to current (or keeps it the same). 71 // If last doesn't match the root in persistent storage, returns false. 72 Commit(ctx context.Context, current, last hash.Hash) (bool, error) 73 74 // Stats may return some kind of struct that reports statistics about the 75 // ChunkStore instance. The type is implementation-dependent, and impls 76 // may return nil 77 Stats() interface{} 78 79 // StatsSummary may return a string containing summarized statistics for 80 // this ChunkStore. It must return "Unsupported" if this operation is not 81 // supported. 82 StatsSummary() string 83 84 // Close tears down any resources in use by the implementation. After 85 // Close(), the ChunkStore may not be used again. It is NOT SAFE to call 86 // Close() concurrently with any other ChunkStore method; behavior is 87 // undefined and probably crashy. 88 io.Closer 89 } 90 91 // ChunkStoreGarbageCollector is a ChunkStore that supports garbage collection. 92 type ChunkStoreGarbageCollector interface { 93 ChunkStore 94 95 // MarkAndSweepChunks expects |keepChunks| to receive the chunk hashes 96 // that should be kept in the chunk store. Once |keepChunks| is closed 97 // and MarkAndSweepChunks returns, the chunk store will only have the 98 // chunks sent on |keepChunks| and will have removed all other content 99 // from the ChunkStore. 100 MarkAndSweepChunks(ctx context.Context, last hash.Hash, keepChunks <-chan []hash.Hash) error 101 } 102 103 // ChunkStoreVersionGetter is a ChunkStore that supports getting the manifest's 104 // storage version 105 type ChunkStoreVersionGetter interface { 106 ChunkStore 107 108 // GetManifestStorageVersion returns the storage version of the Chunkstore's manifest 109 GetManifestStorageVersion(ctx context.Context) (string, error) 110 } 111 112 var ErrUnsupportedOperation = errors.New("operation not supported") 113 114 var ErrGCGenerationExpired = errors.New("garbage collection generation expired")