/
index.go
95 lines (75 loc) · 2.3 KB
/
index.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
package index
import (
"context"
)
// QueryPagesCallback from an IndexQuery.
type QueryPagesCallback func(Query, ReadBatchResult) bool
// Client for the read path.
type ReadClient interface {
QueryPages(ctx context.Context, queries []Query, callback QueryPagesCallback) error
}
// Client for the write path.
type WriteClient interface {
NewWriteBatch() WriteBatch
BatchWrite(context.Context, WriteBatch) error
}
// Client is a client for the storage of the index (e.g. DynamoDB or Bigtable).
type Client interface {
ReadClient
WriteClient
Stop()
}
// ReadBatchResult represents the results of a QueryPages.
type ReadBatchResult interface {
Iterator() ReadBatchIterator
}
// ReadBatchIterator is an iterator over a ReadBatch.
type ReadBatchIterator interface {
Next() bool
RangeValue() []byte
Value() []byte
}
// WriteBatch represents a batch of writes.
type WriteBatch interface {
Add(tableName, hashValue string, rangeValue []byte, value []byte)
Delete(tableName, hashValue string, rangeValue []byte)
}
// Query describes a query for entries
type Query struct {
TableName string
HashValue string
// One of RangeValuePrefix or RangeValueStart might be set:
// - If RangeValuePrefix is not nil, must read all keys with that prefix.
// - If RangeValueStart is not nil, must read all keys from there onwards.
// - If neither is set, must read all keys for that row.
// RangeValueStart should only be used for querying Chunk IDs.
// If this is going to change then please take care of func isChunksQuery in pkg/chunk/storage/caching_index_client.go which relies on it.
RangeValuePrefix []byte
RangeValueStart []byte
// Filters for querying
ValueEqual []byte
// If the result of this lookup is immutable or not (for caching).
Immutable bool
}
// Entry describes an entry in the chunk index
type Entry struct {
TableName string
HashValue string
// For writes, RangeValue will always be set.
RangeValue []byte
// New for v6 schema, label value is not written as part of the range key.
Value []byte
}
func QueryKey(q Query) string {
ret := q.TableName + sep + q.HashValue
if len(q.RangeValuePrefix) != 0 {
ret += sep + string(q.RangeValuePrefix)
}
if len(q.RangeValueStart) != 0 {
ret += sep + string(q.RangeValueStart)
}
if len(q.ValueEqual) != 0 {
ret += sep + string(q.ValueEqual)
}
return ret
}