github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/pkg/graveler/committed/range_manager.go (about) 1 package committed 2 3 import ( 4 "context" 5 6 "github.com/treeverse/lakefs/pkg/graveler" 7 ) 8 9 //go:generate go run github.com/golang/mock/mockgen@v1.6.0 -source=range_manager.go -destination=mock/range_manager.go -package=mock 10 11 // ID is an identifier for a Range 12 type ID string 13 14 // Namespace is namespace for ID ranges 15 type Namespace string 16 17 // Key and Value types for to be stored in any Range of the MetaRange 18 type Key []byte 19 20 func (k Key) Copy() Key { 21 c := make([]byte, len(k)) 22 copy(c, k) 23 return c 24 } 25 26 type ( 27 Value []byte 28 Record struct { 29 Key Key 30 Value Value 31 } 32 ) 33 34 type ValueIterator interface { 35 Next() bool 36 SeekGE(id Key) 37 Value() *Record 38 Err() error 39 Close() 40 } 41 42 var ErrNotFound = graveler.ErrNotFound 43 44 type RangeManager interface { 45 // Exists returns true if id references a Range. 46 Exists(ctx context.Context, ns Namespace, id ID) (bool, error) 47 48 // GetValue returns the value matching key in the Range referenced by id. If id not 49 // found, it return (nil, ErrNotFound). 50 GetValue(ctx context.Context, ns Namespace, id ID, key Key) (*Record, error) 51 52 // GetValueGE returns the first value keyed at or after key in the Range referenced by 53 // id. If all values are keyed before key, it returns (nil, ErrNotFound). 54 GetValueGE(ctx context.Context, ns Namespace, id ID, key Key) (*Record, error) 55 56 // NewRangeIterator returns an iterator over values in the Range with ID. 57 NewRangeIterator(ctx context.Context, ns Namespace, pid ID) (ValueIterator, error) 58 59 // GetWriter returns a new Range writer instance 60 GetWriter(ctx context.Context, ns Namespace, metadata graveler.Metadata) (RangeWriter, error) 61 62 // GetURI returns a URI from which to read the contents of id. If id does not exist 63 // it may return a URI that resolves nowhere rather than an error. 64 GetURI(ctx context.Context, ns Namespace, id ID) (string, error) 65 } 66 67 // WriteResult is the result of a completed write of a Range 68 type WriteResult struct { 69 // ID is the identifier for the written Range. 70 // Calculated by an hash function to all keys and values' identity. 71 RangeID ID 72 73 // First is the first key in the Range. 74 First Key 75 76 // Last is the last key in the Range. 77 Last Key 78 79 // Count is the number of records in the Range. 80 Count int 81 82 // EstimatedRangeSizeBytes is Approximate size of each Range 83 EstimatedRangeSizeBytes uint64 84 } 85 86 // RangeWriter is an abstraction for writing Ranges. 87 // Written records must be sorted by key. 88 type RangeWriter interface { 89 // WriteRecord appends the given record to the Range. 90 WriteRecord(record Record) error 91 92 // SetMetadata associates metadata value (which will be stringify when the writer is 93 // closed and added to the resulting range ID) with key. 94 SetMetadata(key, value string) 95 96 // GetApproximateSize returns an estimate of the current written size of the Range. 97 GetApproximateSize() uint64 98 99 // Close flushes all records to the disk and returns the WriteResult. 100 Close() (*WriteResult, error) 101 102 // Abort terminates the non-closed file and removes all traces. 103 Abort() error 104 105 // ShouldBreakAtKey returns true if should break range after the given key 106 ShouldBreakAtKey(key graveler.Key, params *Params) bool 107 }