ethdb: refactor Database interface (#30693)

pull/30696/head
Marius van der Wijden 4 weeks ago committed by GitHub
parent 7180d26530
commit 236147bf70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      core/rawdb/accessors_indexes_test.go
  2. 7
      core/rawdb/freezer.go
  3. 6
      core/rawdb/freezer_memory.go
  4. 8
      core/rawdb/freezer_resettable.go
  5. 25
      ethdb/database.go

@ -35,17 +35,17 @@ var newTestHasher = blocktest.NewHasher
func TestLookupStorage(t *testing.T) {
tests := []struct {
name string
writeTxLookupEntriesByBlock func(ethdb.Writer, *types.Block)
writeTxLookupEntriesByBlock func(ethdb.KeyValueWriter, *types.Block)
}{
{
"DatabaseV6",
func(db ethdb.Writer, block *types.Block) {
func(db ethdb.KeyValueWriter, block *types.Block) {
WriteTxLookupEntriesByBlock(db, block)
},
},
{
"DatabaseV4-V5",
func(db ethdb.Writer, block *types.Block) {
func(db ethdb.KeyValueWriter, block *types.Block) {
for _, tx := range block.Transactions() {
db.Put(txLookupKey(tx.Hash()), block.Hash().Bytes())
}
@ -53,7 +53,7 @@ func TestLookupStorage(t *testing.T) {
},
{
"DatabaseV3",
func(db ethdb.Writer, block *types.Block) {
func(db ethdb.KeyValueWriter, block *types.Block) {
for index, tx := range block.Transactions() {
entry := LegacyTxLookupEntry{
BlockHash: block.Hash(),

@ -58,6 +58,7 @@ const freezerTableSize = 2 * 1000 * 1000 * 1000
// - The append-only nature ensures that disk writes are minimized.
// - The in-order data ensures that disk reads are always optimized.
type Freezer struct {
datadir string
frozen atomic.Uint64 // Number of items already frozen
tail atomic.Uint64 // Number of the first stored item in the freezer
@ -109,6 +110,7 @@ func NewFreezer(datadir string, namespace string, readonly bool, maxTableSize ui
}
// Open all the supported data tables
freezer := &Freezer{
datadir: datadir,
readonly: readonly,
tables: make(map[string]*freezerTable),
instanceLock: lock,
@ -172,6 +174,11 @@ func (f *Freezer) Close() error {
return nil
}
// AncientDatadir returns the path of the ancient store.
func (f *Freezer) AncientDatadir() (string, error) {
return f.datadir, nil
}
// HasAncient returns an indicator whether the specified ancient data exists
// in the freezer.
func (f *Freezer) HasAncient(kind string, number uint64) (bool, error) {

@ -419,3 +419,9 @@ func (f *MemoryFreezer) Reset() error {
f.items, f.tail = 0, 0
return nil
}
// AncientDatadir returns the path of the ancient store.
// Since the memory freezer is ephemeral, an empty string is returned.
func (f *MemoryFreezer) AncientDatadir() (string, error) {
return "", nil
}

@ -202,6 +202,14 @@ func (f *resettableFreezer) Sync() error {
return f.freezer.Sync()
}
// AncientDatadir returns the path of the ancient store.
func (f *resettableFreezer) AncientDatadir() (string, error) {
f.lock.RLock()
defer f.lock.RUnlock()
return f.freezer.AncientDatadir()
}
// cleanup removes the directory located in the specified path
// has the name with deletion marker suffix.
func cleanup(path string) error {

@ -162,26 +162,12 @@ type Reader interface {
AncientReader
}
// Writer contains the methods required to write data to both key-value as well as
// immutable ancient data.
type Writer interface {
KeyValueWriter
KeyValueRangeDeleter
AncientWriter
}
// Stater contains the methods required to retrieve states from both key-value as well as
// immutable ancient data.
type Stater interface {
KeyValueStater
AncientStater
}
// AncientStore contains all the methods required to allow handling different
// ancient data stores backing immutable data store.
type AncientStore interface {
AncientReader
AncientWriter
AncientStater
io.Closer
}
@ -196,11 +182,6 @@ type ResettableAncientStore interface {
// Database contains all the methods required by the high level database to not
// only access the key-value data store but also the ancient chain store.
type Database interface {
Reader
Writer
Batcher
Iteratee
Stater
Compacter
io.Closer
KeyValueStore
AncientStore
}

Loading…
Cancel
Save