diff --git a/core/rawdb/table.go b/core/rawdb/table.go index fc99ff0866..d481fbd3ec 100644 --- a/core/rawdb/table.go +++ b/core/rawdb/table.go @@ -188,6 +188,12 @@ func (t *table) Compact(start []byte, limit []byte) error { return t.db.Compact(start, limit) } +// Sync ensures that all pending writes are flushed to disk, guaranteeing +// data durability up to the point. +func (t *table) Sync() error { + return t.db.Sync() +} + // NewBatch creates a write-only database that buffers changes to its host db // until a final write is called, each operation prefixing all keys with the // pre-configured string. diff --git a/ethdb/database.go b/ethdb/database.go index 39a565f6ac..f277acb550 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -57,6 +57,13 @@ type KeyValueStater interface { Stat() (string, error) } +// KeyValueSyncer wraps the Sync method of a backing data store. +type KeyValueSyncer interface { + // Sync ensures that all pending writes are flushed to disk, guaranteeing + // data durability up to the point. + Sync() error +} + // Compacter wraps the Compact method of a backing data store. type Compacter interface { // Compact flattens the underlying data store for the given key range. In essence, @@ -75,6 +82,7 @@ type KeyValueStore interface { KeyValueReader KeyValueWriter KeyValueStater + KeyValueSyncer KeyValueRangeDeleter Batcher Iteratee diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index ef02e91822..f29a0f064d 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -324,6 +324,12 @@ func (db *Database) Path() string { return db.fn } +// Sync flushes all pending writes in the write-ahead-log to disk, ensuring +// data durability up to that point. +func (db *Database) Sync() error { + return nil +} + // meter periodically retrieves internal leveldb counters and reports them to // the metrics subsystem. func (db *Database) meter(refresh time.Duration, namespace string) { diff --git a/ethdb/memorydb/memorydb.go b/ethdb/memorydb/memorydb.go index a797275e92..c8196f7137 100644 --- a/ethdb/memorydb/memorydb.go +++ b/ethdb/memorydb/memorydb.go @@ -199,6 +199,12 @@ func (db *Database) Compact(start []byte, limit []byte) error { return nil } +// Sync ensures that all pending writes are flushed to disk, guaranteeing +// data durability up to the point. +func (db *Database) Sync() error { + return nil +} + // Len returns the number of entries currently present in the memory database. // // Note, this method is only used for testing (i.e. not public in general) and diff --git a/ethdb/pebble/pebble.go b/ethdb/pebble/pebble.go index 969e67af5a..da6d68f673 100644 --- a/ethdb/pebble/pebble.go +++ b/ethdb/pebble/pebble.go @@ -414,6 +414,14 @@ func (d *Database) Path() string { return d.fn } +// Sync flushes all pending writes in the write-ahead-log to disk, ensuring +// data durability up to that point. +func (d *Database) Sync() error { + b := d.db.NewBatch() + b.LogData(nil, nil) + return d.db.Apply(b, pebble.Sync) +} + // meter periodically retrieves internal pebble counters and reports them to // the metrics subsystem. func (d *Database) meter(refresh time.Duration, namespace string) { diff --git a/ethdb/remotedb/remotedb.go b/ethdb/remotedb/remotedb.go index 9de0bdc0d5..13b19facea 100644 --- a/ethdb/remotedb/remotedb.go +++ b/ethdb/remotedb/remotedb.go @@ -138,6 +138,10 @@ func (db *Database) Compact(start []byte, limit []byte) error { return nil } +func (db *Database) Sync() error { + return nil +} + func (db *Database) Close() error { db.remote.Close() return nil diff --git a/trie/trie_test.go b/trie/trie_test.go index 54d1b083d8..0a297b317d 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -830,6 +830,7 @@ func (s *spongeDb) NewBatch() ethdb.Batch { return &spongeBat func (s *spongeDb) NewBatchWithSize(size int) ethdb.Batch { return &spongeBatch{s} } func (s *spongeDb) Stat() (string, error) { panic("implement me") } func (s *spongeDb) Compact(start []byte, limit []byte) error { panic("implement me") } +func (s *spongeDb) Sync() error { return nil } func (s *spongeDb) Close() error { return nil } func (s *spongeDb) Put(key []byte, value []byte) error { var (