Skip to content

Commit 944718b

Browse files
authored
ethdb: remove snapshot (#30189)
1 parent df3f0a8 commit 944718b

File tree

9 files changed

+0
-270
lines changed

9 files changed

+0
-270
lines changed

core/rawdb/table.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,6 @@ func (t *table) NewBatchWithSize(size int) ethdb.Batch {
200200
return &tableBatch{t.db.NewBatchWithSize(size), t.prefix}
201201
}
202202

203-
// NewSnapshot creates a database snapshot based on the current state.
204-
// The created snapshot will not be affected by all following mutations
205-
// happened on the database.
206-
func (t *table) NewSnapshot() (ethdb.Snapshot, error) {
207-
return t.db.NewSnapshot()
208-
}
209-
210203
// tableBatch is a wrapper around a database batch that prefixes each key access
211204
// with a pre-configured string.
212205
type tableBatch struct {

ethdb/database.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ type KeyValueStore interface {
6464
Batcher
6565
Iteratee
6666
Compacter
67-
Snapshotter
6867
io.Closer
6968
}
7069

@@ -199,6 +198,5 @@ type Database interface {
199198
Iteratee
200199
Stater
201200
Compacter
202-
Snapshotter
203201
io.Closer
204202
}

ethdb/dbtest/testsuite.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -318,69 +318,6 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
318318
}
319319
})
320320

321-
t.Run("Snapshot", func(t *testing.T) {
322-
db := New()
323-
defer db.Close()
324-
325-
initial := map[string]string{
326-
"k1": "v1", "k2": "v2", "k3": "", "k4": "",
327-
}
328-
for k, v := range initial {
329-
db.Put([]byte(k), []byte(v))
330-
}
331-
snapshot, err := db.NewSnapshot()
332-
if err != nil {
333-
t.Fatal(err)
334-
}
335-
for k, v := range initial {
336-
got, err := snapshot.Get([]byte(k))
337-
if err != nil {
338-
t.Fatal(err)
339-
}
340-
if !bytes.Equal(got, []byte(v)) {
341-
t.Fatalf("Unexpected value want: %v, got %v", v, got)
342-
}
343-
}
344-
345-
// Flush more modifications into the database, ensure the snapshot
346-
// isn't affected.
347-
var (
348-
update = map[string]string{"k1": "v1-b", "k3": "v3-b"}
349-
insert = map[string]string{"k5": "v5-b"}
350-
delete = map[string]string{"k2": ""}
351-
)
352-
for k, v := range update {
353-
db.Put([]byte(k), []byte(v))
354-
}
355-
for k, v := range insert {
356-
db.Put([]byte(k), []byte(v))
357-
}
358-
for k := range delete {
359-
db.Delete([]byte(k))
360-
}
361-
for k, v := range initial {
362-
got, err := snapshot.Get([]byte(k))
363-
if err != nil {
364-
t.Fatal(err)
365-
}
366-
if !bytes.Equal(got, []byte(v)) {
367-
t.Fatalf("Unexpected value want: %v, got %v", v, got)
368-
}
369-
}
370-
for k := range insert {
371-
got, err := snapshot.Get([]byte(k))
372-
if err == nil || len(got) != 0 {
373-
t.Fatal("Unexpected value")
374-
}
375-
}
376-
for k := range delete {
377-
got, err := snapshot.Get([]byte(k))
378-
if err != nil || len(got) == 0 {
379-
t.Fatal("Unexpected deletion")
380-
}
381-
}
382-
})
383-
384321
t.Run("OperationsAfterClose", func(t *testing.T) {
385322
db := New()
386323
db.Put([]byte("key"), []byte("value"))

ethdb/leveldb/leveldb.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,6 @@ func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
230230
return db.db.NewIterator(bytesPrefixRange(prefix, start), nil)
231231
}
232232

233-
// NewSnapshot creates a database snapshot based on the current state.
234-
// The created snapshot will not be affected by all following mutations
235-
// happened on the database.
236-
// Note don't forget to release the snapshot once it's used up, otherwise
237-
// the stale data will never be cleaned up by the underlying compactor.
238-
func (db *Database) NewSnapshot() (ethdb.Snapshot, error) {
239-
snap, err := db.db.GetSnapshot()
240-
if err != nil {
241-
return nil, err
242-
}
243-
return &snapshot{db: snap}, nil
244-
}
245-
246233
// Stat returns the statistic data of the database.
247234
func (db *Database) Stat() (string, error) {
248235
var stats leveldb.DBStats
@@ -498,26 +485,3 @@ func bytesPrefixRange(prefix, start []byte) *util.Range {
498485
r.Start = append(r.Start, start...)
499486
return r
500487
}
501-
502-
// snapshot wraps a leveldb snapshot for implementing the Snapshot interface.
503-
type snapshot struct {
504-
db *leveldb.Snapshot
505-
}
506-
507-
// Has retrieves if a key is present in the snapshot backing by a key-value
508-
// data store.
509-
func (snap *snapshot) Has(key []byte) (bool, error) {
510-
return snap.db.Has(key, nil)
511-
}
512-
513-
// Get retrieves the given key if it's present in the snapshot backing by
514-
// key-value data store.
515-
func (snap *snapshot) Get(key []byte) ([]byte, error) {
516-
return snap.db.Get(key, nil)
517-
}
518-
519-
// Release releases associated resources. Release should always succeed and can
520-
// be called multiple times without causing error.
521-
func (snap *snapshot) Release() {
522-
snap.db.Release()
523-
}

ethdb/memorydb/memorydb.go

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ var (
3535
// errMemorydbNotFound is returned if a key is requested that is not found in
3636
// the provided memory database.
3737
errMemorydbNotFound = errors.New("not found")
38-
39-
// errSnapshotReleased is returned if callers want to retrieve data from a
40-
// released snapshot.
41-
errSnapshotReleased = errors.New("snapshot released")
4238
)
4339

4440
// Database is an ephemeral key-value store. Apart from basic data storage
@@ -175,13 +171,6 @@ func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
175171
}
176172
}
177173

178-
// NewSnapshot creates a database snapshot based on the current state.
179-
// The created snapshot will not be affected by all following mutations
180-
// happened on the database.
181-
func (db *Database) NewSnapshot() (ethdb.Snapshot, error) {
182-
return newSnapshot(db), nil
183-
}
184-
185174
// Stat returns the statistic data of the database.
186175
func (db *Database) Stat() (string, error) {
187176
return "", nil
@@ -332,59 +321,3 @@ func (it *iterator) Value() []byte {
332321
func (it *iterator) Release() {
333322
it.index, it.keys, it.values = -1, nil, nil
334323
}
335-
336-
// snapshot wraps a batch of key-value entries deep copied from the in-memory
337-
// database for implementing the Snapshot interface.
338-
type snapshot struct {
339-
db map[string][]byte
340-
lock sync.RWMutex
341-
}
342-
343-
// newSnapshot initializes the snapshot with the given database instance.
344-
func newSnapshot(db *Database) *snapshot {
345-
db.lock.RLock()
346-
defer db.lock.RUnlock()
347-
348-
copied := make(map[string][]byte, len(db.db))
349-
for key, val := range db.db {
350-
copied[key] = common.CopyBytes(val)
351-
}
352-
return &snapshot{db: copied}
353-
}
354-
355-
// Has retrieves if a key is present in the snapshot backing by a key-value
356-
// data store.
357-
func (snap *snapshot) Has(key []byte) (bool, error) {
358-
snap.lock.RLock()
359-
defer snap.lock.RUnlock()
360-
361-
if snap.db == nil {
362-
return false, errSnapshotReleased
363-
}
364-
_, ok := snap.db[string(key)]
365-
return ok, nil
366-
}
367-
368-
// Get retrieves the given key if it's present in the snapshot backing by
369-
// key-value data store.
370-
func (snap *snapshot) Get(key []byte) ([]byte, error) {
371-
snap.lock.RLock()
372-
defer snap.lock.RUnlock()
373-
374-
if snap.db == nil {
375-
return nil, errSnapshotReleased
376-
}
377-
if entry, ok := snap.db[string(key)]; ok {
378-
return common.CopyBytes(entry), nil
379-
}
380-
return nil, errMemorydbNotFound
381-
}
382-
383-
// Release releases associated resources. Release should always succeed and can
384-
// be called multiple times without causing error.
385-
func (snap *snapshot) Release() {
386-
snap.lock.Lock()
387-
defer snap.lock.Unlock()
388-
389-
snap.db = nil
390-
}

ethdb/pebble/pebble.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -351,55 +351,6 @@ func (d *Database) NewBatchWithSize(size int) ethdb.Batch {
351351
}
352352
}
353353

354-
// snapshot wraps a pebble snapshot for implementing the Snapshot interface.
355-
type snapshot struct {
356-
db *pebble.Snapshot
357-
}
358-
359-
// NewSnapshot creates a database snapshot based on the current state.
360-
// The created snapshot will not be affected by all following mutations
361-
// happened on the database.
362-
// Note don't forget to release the snapshot once it's used up, otherwise
363-
// the stale data will never be cleaned up by the underlying compactor.
364-
func (d *Database) NewSnapshot() (ethdb.Snapshot, error) {
365-
snap := d.db.NewSnapshot()
366-
return &snapshot{db: snap}, nil
367-
}
368-
369-
// Has retrieves if a key is present in the snapshot backing by a key-value
370-
// data store.
371-
func (snap *snapshot) Has(key []byte) (bool, error) {
372-
_, closer, err := snap.db.Get(key)
373-
if err != nil {
374-
if err != pebble.ErrNotFound {
375-
return false, err
376-
} else {
377-
return false, nil
378-
}
379-
}
380-
closer.Close()
381-
return true, nil
382-
}
383-
384-
// Get retrieves the given key if it's present in the snapshot backing by
385-
// key-value data store.
386-
func (snap *snapshot) Get(key []byte) ([]byte, error) {
387-
dat, closer, err := snap.db.Get(key)
388-
if err != nil {
389-
return nil, err
390-
}
391-
ret := make([]byte, len(dat))
392-
copy(ret, dat)
393-
closer.Close()
394-
return ret, nil
395-
}
396-
397-
// Release releases associated resources. Release should always succeed and can
398-
// be called multiple times without causing error.
399-
func (snap *snapshot) Release() {
400-
snap.db.Close()
401-
}
402-
403354
// upperBound returns the upper bound for the given prefix
404355
func upperBound(prefix []byte) (limit []byte) {
405356
for i := len(prefix) - 1; i >= 0; i-- {

ethdb/remotedb/remotedb.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ func (db *Database) Compact(start []byte, limit []byte) error {
138138
return nil
139139
}
140140

141-
func (db *Database) NewSnapshot() (ethdb.Snapshot, error) {
142-
panic("not supported")
143-
}
144-
145141
func (db *Database) Close() error {
146142
db.remote.Close()
147143
return nil

ethdb/snapshot.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

trie/trie_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,6 @@ func (s *spongeDb) Get(key []byte) ([]byte, error) { return nil, error
819819
func (s *spongeDb) Delete(key []byte) error { panic("implement me") }
820820
func (s *spongeDb) NewBatch() ethdb.Batch { return &spongeBatch{s} }
821821
func (s *spongeDb) NewBatchWithSize(size int) ethdb.Batch { return &spongeBatch{s} }
822-
func (s *spongeDb) NewSnapshot() (ethdb.Snapshot, error) { panic("implement me") }
823822
func (s *spongeDb) Stat() (string, error) { panic("implement me") }
824823
func (s *spongeDb) Compact(start []byte, limit []byte) error { panic("implement me") }
825824
func (s *spongeDb) Close() error { return nil }

0 commit comments

Comments
 (0)