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