-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
118 lines (96 loc) · 2.61 KB
/
interface.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
package kvdb
import (
"io"
"github.com/ethereum/go-ethereum/ethdb"
)
// IdealBatchSize defines the size of the data batches should ideally add in one
// write.
const IdealBatchSize = 100 * 1024
// Batch is a write-only database that commits changes to its host database
// when Write is called. A batch cannot be used concurrently.
type Batch interface {
Writer
// ValueSize retrieves the amount of data queued up for writing.
ValueSize() int
// Write flushes any accumulated data to disk.
Write() error
// Reset resets the batch for reuse.
Reset()
// Replay replays the batch contents.
Replay(w Writer) error
}
// Iterator iterates over a database's key/value pairs in ascending key order.
type Iterator interface {
ethdb.Iterator
}
// Writer wraps the Put method of a backing data store.
type Writer interface {
ethdb.KeyValueWriter
}
// Reader wraps the Has and get method of a backing data store.
type Reader interface {
ethdb.KeyValueReader
}
// Batcher wraps the NewBatch method of a backing data store.
type Batcher interface {
// NewBatch creates a write-only database that buffers changes to its host db
// until a final write is called.
NewBatch() Batch
}
// Iteratee wraps the NewIterator methods of a backing data store.
type Iteratee interface {
// NewIterator creates a binary-alphabetical iterator over a subset
// of database content with a particular key prefix, starting at a particular
// initial key (or after, if it does not exist).
NewIterator(prefix []byte, start []byte) Iterator
}
// Store contains all the methods required to allow handling different
// key-value data stores backing the high level database.
type Store interface {
Reader
Writer
Batcher
Iteratee
ethdb.Stater
ethdb.Compacter
io.Closer
}
// ReadonlyStore contains only reading methods of Store.
type ReadonlyStore interface {
Reader
Iteratee
ethdb.Stater
}
// Droper is able to delete the DB.
type Droper interface {
Drop()
}
// DropableStore is Droper + Store
type DropableStore interface {
Store
Droper
}
// FlushableKVStore contains all the method for flushable databases,
// i.e. databases which write changes on disk only on flush.
type FlushableKVStore interface {
DropableStore
NotFlushedPairs() int
NotFlushedSizeEst() int
Flush() error
DropNotFlushed()
}
// DBProducer represents real db producer.
type DBProducer interface {
// OpenDB or create db with name.
OpenDB(name string) (DropableStore, error)
}
type IterableDBProducer interface {
DBProducer
// Names of existing databases.
Names() []string
}
type FlushableDBProducer interface {
DBProducer
NotFlushedSizeEst() int
Flush(id []byte) error
}