core/rawdb, ethdb, trie: implement db.Sync

This commit is contained in:
Gary Rong 2025-04-23 10:37:09 +08:00
parent 7fe474b24c
commit 1665dfecba
7 changed files with 39 additions and 0 deletions

View file

@ -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.

View file

@ -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

View file

@ -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) {

View file

@ -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

View file

@ -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) {

View file

@ -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

View file

@ -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 (