mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
core/rawdb: track table config in memory freezer
This commit is contained in:
parent
53d6c25c6b
commit
cf79ace3c1
1 changed files with 12 additions and 10 deletions
|
|
@ -30,17 +30,19 @@ import (
|
|||
|
||||
// memoryTable is used to store a list of sequential items in memory.
|
||||
type memoryTable struct {
|
||||
name string // Table name
|
||||
items uint64 // Number of stored items in the table, including the deleted ones
|
||||
offset uint64 // Number of deleted items from the table
|
||||
data [][]byte // List of rlp-encoded items, sort in order
|
||||
size uint64 // Total memory size occupied by the table
|
||||
lock sync.RWMutex
|
||||
|
||||
name string
|
||||
config freezerTableConfig
|
||||
}
|
||||
|
||||
// newMemoryTable initializes the memory table.
|
||||
func newMemoryTable(name string) *memoryTable {
|
||||
return &memoryTable{name: name}
|
||||
func newMemoryTable(name string, config freezerTableConfig) *memoryTable {
|
||||
return &memoryTable{name: name, config: config}
|
||||
}
|
||||
|
||||
// has returns an indicator whether the specified data exists.
|
||||
|
|
@ -220,8 +222,8 @@ type MemoryFreezer struct {
|
|||
// NewMemoryFreezer initializes an in-memory freezer instance.
|
||||
func NewMemoryFreezer(readonly bool, tableName map[string]freezerTableConfig) *MemoryFreezer {
|
||||
tables := make(map[string]*memoryTable)
|
||||
for name := range tableName {
|
||||
tables[name] = newMemoryTable(name)
|
||||
for name, cfg := range tableName {
|
||||
tables[name] = newMemoryTable(name, cfg)
|
||||
}
|
||||
return &MemoryFreezer{
|
||||
writeBatch: newMemoryBatch(),
|
||||
|
|
@ -389,7 +391,7 @@ func (f *MemoryFreezer) TruncateTail(tail uint64) (uint64, error) {
|
|||
return old, nil
|
||||
}
|
||||
|
||||
// TruncateTailBlocks discards any recent data below the provided threshold number.
|
||||
// TruncateTailBlocks discards all data below the provided block.
|
||||
// Only truncates blocks and receipts.
|
||||
func (f *MemoryFreezer) TruncateTailBlocks(tail uint64) (uint64, error) {
|
||||
f.lock.Lock()
|
||||
|
|
@ -402,8 +404,8 @@ func (f *MemoryFreezer) TruncateTailBlocks(tail uint64) (uint64, error) {
|
|||
if old >= tail {
|
||||
return old, nil
|
||||
}
|
||||
for kind, table := range f.tables {
|
||||
if kind == ChainFreezerBodiesTable || kind == ChainFreezerReceiptTable {
|
||||
for _, table := range f.tables {
|
||||
if table.config.prunable {
|
||||
if err := table.truncateTail(tail); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
@ -436,8 +438,8 @@ func (f *MemoryFreezer) Reset() error {
|
|||
defer f.lock.Unlock()
|
||||
|
||||
tables := make(map[string]*memoryTable)
|
||||
for name := range f.tables {
|
||||
tables[name] = newMemoryTable(name)
|
||||
for name, table := range f.tables {
|
||||
tables[name] = newMemoryTable(name, table.config)
|
||||
}
|
||||
f.tables = tables
|
||||
f.items, f.tail = 0, 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue