-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.go
149 lines (124 loc) · 3.23 KB
/
types.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package types
type Entry struct {
Key []byte
Value []byte
NextKey []byte
Height int64
LastHeight int64
SerialNum int64
}
type EntryX struct {
Entry *Entry
Pos int64
DeactivedSNList []int64
}
type KeyAndPos struct {
Key []byte
Pos int64
SerialNum int64
}
type OperationOnEntry int32
const (
OpNone OperationOnEntry = iota
OpDelete
OpInsertOrChange
ShardCount = 8
IndexChanCount = 10
)
func LimitRange(b byte) byte {
return (b % 128) + 64 // limit the range to avoid conflicting with start&end Guard
}
func GetShardID(bz []byte) int {
if len(bz) != 8 {
return 0
}
return int(bz[7]) / (256 / ShardCount)
}
func GetIndexChanID(b byte) int {
if b < 64 {
return 0 // for the x-standy-queue
} else if b >= 128+64 {
return 9 // for the standy-queue
} else {
return 1 + (int(b)-64)/16
}
}
type HotEntry struct {
EntryPtr *Entry
Operation OperationOnEntry
IsModified bool
IsTouchedByNext bool
}
type IteratorUI64 interface {
Domain() (start []byte, end []byte)
Valid() bool
Next()
Key() []byte
Value() int64
Close()
}
type IndexTree interface {
Init(repFn func([]byte)) error
SetDuringInit(b bool)
ActiveCount() int
BeginWrite(height int64)
EndWrite()
Iterator(start, end []byte) IteratorUI64
ReverseIterator(start, end []byte) IteratorUI64
Get(k []byte) (int64, bool)
GetAtHeight(k []byte, height uint64) (int64, bool)
Set(k []byte, v int64)
Delete(k []byte)
Close()
}
type EntryHandler func(pos int64, entry *Entry, deactivedSNList []int64)
type DataTree interface {
DeactiviateEntry(sn int64) int
AppendEntry(entry *Entry) int64
AppendEntryRawBytes(entryBz []byte, sn int64) int64
ReadEntry(pos int64) *Entry
ReadEntryBytesForProof(pos int64) []byte
GetActiveBit(sn int64) bool
EvictTwig(twigID int64)
GetActiveEntriesInTwig(twigID int64) chan []byte
ScanEntries(oldestActiveTwigID int64, outChan chan EntryX)
ScanEntriesLite(oldestActiveTwigID int64, outChan chan KeyAndPos)
TwigCanBePruned(twigID int64) bool
PruneTwigs(startID, endID int64) []byte
GetFileSizes() (int64, int64)
EndBlock() [32]byte
WaitForFlushing()
DeactivedSNListSize() int
PrintTree()
GetProofBytesAndCheck(sn int64, entryBz []byte) ([]byte, error)
SaveMemToDisk()
Close()
}
type MetaDB interface {
Commit()
ReloadFromKVDB()
PrintInfo()
SetCurrHeight(h int64)
GetCurrHeight() int64
SetTwigMtFileSize(shardID int, size int64)
GetTwigMtFileSize(shardID int) int64
SetEntryFileSize(shardID int, size int64)
GetEntryFileSize(shardID int) int64
GetTwigHeight(shardID int, twigID int64) int64
DeleteTwigHeight(shardID int, twigID int64)
SetLastPrunedTwig(shardID int, twigID int64)
GetLastPrunedTwig(shardID int) int64
SetEdgeNodes(shardID int, bz []byte)
GetEdgeNodes(shardID int) []byte
// MaxSerialNum is the maximum serial num among all the entries
GetMaxSerialNum(shardID int) int64
IncrMaxSerialNum(shardID int) // It should call setTwigHeight(twigID int64, height int64)
GetYoungestTwigID(shardID int) int64
SetRootHash(shardID int, h [32]byte)
GetRootHash(shardID int) [32]byte
// the ID of the oldest active twig, increased by ReapOldestActiveTwig
GetOldestActiveTwigID(shardID int) int64
IncrOldestActiveTwigID(shardID int)
Init()
Close()
}