-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot.go
39 lines (35 loc) · 1 KB
/
snapshot.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
package leveldb
// Snapshot is a read-only view of the database at a moment in time. A Snapshot can be used by multiple go routines,
// but access across Close() and other operations must be externally synchronized.
type Snapshot struct {
db *Database
multi *multiSegment
}
func (s *Snapshot) Get(key []byte) ([]byte, error) {
if s.multi == nil {
return nil, SnapshotClosed
}
value, err := s.multi.Get(key)
if err != nil {
return nil, err
}
if value != nil && len(value) == 0 {
return nil, KeyNotFound
}
return value, nil
}
func (s *Snapshot) Lookup(lower []byte, upper []byte) (LookupIterator, error) {
if s.multi == nil {
return nil, SnapshotClosed
}
itr, err := s.multi.Lookup(lower, upper)
if err != nil {
return nil, err
}
return &dbLookup{LookupIterator: itr, db: s.db}, nil
}
// Close frees any resources used by the Snapshot. This is optional and instead simply setting the Snapshot reference
// to nil will eventually free the resources.
func (s *Snapshot) Close() {
s.multi = nil
}