core/rawdb: untie freezer and ancient chain data (#24684)

Previously freezer has only been used for storing ancient chain data, while obviously it can be used more. This PR unties the chain data and freezer, keep the minimal freezer structure and move all other logic (like incrementally freezing block data) into a separate structure called ChainFreezer.

This PR also extends the database interface by adding a new ancient store function AncientDatadir which can return the root directory of ancient store. The ancient root directory can be used when we want to open some other ancient-stores (e.g. reverse diff freezer).
This commit is contained in:
rjl493456442
2022-05-06 13:28:42 +02:00
committed by GitHub
parent cef1a86df2
commit 1941c5e6c9
9 changed files with 401 additions and 310 deletions
+25 -11
View File
@@ -37,8 +37,8 @@ type KeyValueWriter interface {
Delete(key []byte) error
}
// Stater wraps the Stat method of a backing data store.
type Stater interface {
// KeyValueStater wraps the Stat method of a backing data store.
type KeyValueStater interface {
// Stat returns a particular internal stat of the database.
Stat(property string) (string, error)
}
@@ -60,16 +60,16 @@ type Compacter interface {
type KeyValueStore interface {
KeyValueReader
KeyValueWriter
KeyValueStater
Batcher
Iteratee
Stater
Compacter
Snapshotter
io.Closer
}
// AncientReader contains the methods required to read from immutable ancient data.
type AncientReader interface {
// AncientReaderOp contains the methods required to read from immutable ancient data.
type AncientReaderOp interface {
// HasAncient returns an indicator whether the specified data exists in the
// ancient store.
HasAncient(kind string, number uint64) (bool, error)
@@ -95,13 +95,13 @@ type AncientReader interface {
AncientSize(kind string) (uint64, error)
}
// AncientBatchReader is the interface for 'batched' or 'atomic' reading.
type AncientBatchReader interface {
AncientReader
// AncientReader is the extended ancient reader interface including 'batched' or 'atomic' reading.
type AncientReader interface {
AncientReaderOp
// ReadAncients runs the given read operation while ensuring that no writes take place
// on the underlying freezer.
ReadAncients(fn func(AncientReader) error) (err error)
ReadAncients(fn func(AncientReaderOp) error) (err error)
}
// AncientWriter contains the methods required to write to immutable ancient data.
@@ -140,11 +140,17 @@ type AncientWriteOp interface {
AppendRaw(kind string, number uint64, item []byte) error
}
// AncientStater wraps the Stat method of a backing data store.
type AncientStater interface {
// AncientDatadir returns the root directory path of the ancient store.
AncientDatadir() (string, error)
}
// Reader contains the methods required to read data from both key-value as well as
// immutable ancient data.
type Reader interface {
KeyValueReader
AncientBatchReader
AncientReader
}
// Writer contains the methods required to write data to both key-value as well as
@@ -154,11 +160,19 @@ type Writer interface {
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 chain data store.
type AncientStore interface {
AncientBatchReader
AncientReader
AncientWriter
AncientStater
io.Closer
}