-
Notifications
You must be signed in to change notification settings - Fork 198
/
interface.go
118 lines (110 loc) · 4.39 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 storage
import (
"github.com/ElrondNetwork/elrond-go/data"
"github.com/ElrondNetwork/elrond-go/epochStart"
)
// Persister provides storage of data services in a database like construct
type Persister interface {
// Put add the value to the (key, val) persistence medium
Put(key, val []byte) error
// Get gets the value associated to the key
Get(key []byte) ([]byte, error)
// Has returns true if the given key is present in the persistence medium
Has(key []byte) error
// Init initializes the persistence medium and prepares it for usage
Init() error
// Close closes the files/resources associated to the persistence medium
Close() error
// Remove removes the data associated to the given key
Remove(key []byte) error
// Destroy removes the persistence medium stored data
Destroy() error
// DestroyClosed removes the already closed persistence medium stored data
DestroyClosed() error
// IsInterfaceNil returns true if there is no value under the interface
IsInterfaceNil() bool
}
// Batcher allows to batch the data first then write the batch to the persister in one go
type Batcher interface {
// Put inserts one entry - key, value pair - into the batch
Put(key []byte, val []byte) error
// Delete deletes the batch
Delete(key []byte) error
// Reset clears the contents of the batch
Reset()
// IsInterfaceNil returns true if there is no value under the interface
IsInterfaceNil() bool
}
// Cacher provides caching services
type Cacher interface {
// Clear is used to completely clear the cache.
Clear()
// Put adds a value to the cache. Returns true if an eviction occurred.
Put(key []byte, value interface{}) (evicted bool)
// Get looks up a key's value from the cache.
Get(key []byte) (value interface{}, ok bool)
// Has checks if a key is in the cache, without updating the
// recent-ness or deleting it for being stale.
Has(key []byte) bool
// Peek returns the key value (or undefined if not found) without updating
// the "recently used"-ness of the key.
Peek(key []byte) (value interface{}, ok bool)
// HasOrAdd checks if a key is in the cache without updating the
// recent-ness or deleting it for being stale, and if not adds the value.
// Returns whether found and whether an eviction occurred.
HasOrAdd(key []byte, value interface{}) (ok, evicted bool)
// Remove removes the provided key from the cache.
Remove(key []byte)
// RemoveOldest removes the oldest item from the cache.
RemoveOldest()
// Keys returns a slice of the keys in the cache, from oldest to newest.
Keys() [][]byte
// Len returns the number of items in the cache.
Len() int
// MaxSize returns the maximum number of items which can be stored in the cache.
MaxSize() int
// RegisterHandler registers a new handler to be called when a new data is added
RegisterHandler(func(key []byte))
// IsInterfaceNil returns true if there is no value under the interface
IsInterfaceNil() bool
}
// BloomFilter provides services for filtering database requests
type BloomFilter interface {
//Add adds the value to the bloom filter
Add([]byte)
// MayContain checks if the value is in in the set. If it returns 'false',
//the item is definitely not in the DB
MayContain([]byte) bool
//Clear sets all the bits from the filter to 0
Clear()
// IsInterfaceNil returns true if there is no value under the interface
IsInterfaceNil() bool
}
// Storer provides storage services in a two layered storage construct, where the first layer is
// represented by a cache and second layer by a persitent storage (DB-like)
type Storer interface {
Put(key, data []byte) error
Get(key []byte) ([]byte, error)
GetFromEpoch(key []byte, epoch uint32) ([]byte, error)
Has(key []byte) error
HasInEpoch(key []byte, epoch uint32) error
SearchFirst(key []byte) ([]byte, error)
Remove(key []byte) error
ClearCache()
DestroyUnit() error
IsInterfaceNil() bool
Close() error
}
// EpochStartNotifier defines which actions should be done for handling new epoch's events
type EpochStartNotifier interface {
RegisterHandler(handler epochStart.EpochStartHandler)
UnregisterHandler(handler epochStart.EpochStartHandler)
NotifyAll(hdr data.HeaderHandler)
IsInterfaceNil() bool
}
// PathManagerHandler defines which actions should be done for generating paths for databases directories
type PathManagerHandler interface {
PathForEpoch(shardId string, epoch uint32, identifier string) string
PathForStatic(shardId string, identifier string) string
IsInterfaceNil() bool
}