mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +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.
|
// memoryTable is used to store a list of sequential items in memory.
|
||||||
type memoryTable struct {
|
type memoryTable struct {
|
||||||
name string // Table name
|
|
||||||
items uint64 // Number of stored items in the table, including the deleted ones
|
items uint64 // Number of stored items in the table, including the deleted ones
|
||||||
offset uint64 // Number of deleted items from the table
|
offset uint64 // Number of deleted items from the table
|
||||||
data [][]byte // List of rlp-encoded items, sort in order
|
data [][]byte // List of rlp-encoded items, sort in order
|
||||||
size uint64 // Total memory size occupied by the table
|
size uint64 // Total memory size occupied by the table
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
|
|
||||||
|
name string
|
||||||
|
config freezerTableConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMemoryTable initializes the memory table.
|
// newMemoryTable initializes the memory table.
|
||||||
func newMemoryTable(name string) *memoryTable {
|
func newMemoryTable(name string, config freezerTableConfig) *memoryTable {
|
||||||
return &memoryTable{name: name}
|
return &memoryTable{name: name, config: config}
|
||||||
}
|
}
|
||||||
|
|
||||||
// has returns an indicator whether the specified data exists.
|
// has returns an indicator whether the specified data exists.
|
||||||
|
|
@ -220,8 +222,8 @@ type MemoryFreezer struct {
|
||||||
// NewMemoryFreezer initializes an in-memory freezer instance.
|
// NewMemoryFreezer initializes an in-memory freezer instance.
|
||||||
func NewMemoryFreezer(readonly bool, tableName map[string]freezerTableConfig) *MemoryFreezer {
|
func NewMemoryFreezer(readonly bool, tableName map[string]freezerTableConfig) *MemoryFreezer {
|
||||||
tables := make(map[string]*memoryTable)
|
tables := make(map[string]*memoryTable)
|
||||||
for name := range tableName {
|
for name, cfg := range tableName {
|
||||||
tables[name] = newMemoryTable(name)
|
tables[name] = newMemoryTable(name, cfg)
|
||||||
}
|
}
|
||||||
return &MemoryFreezer{
|
return &MemoryFreezer{
|
||||||
writeBatch: newMemoryBatch(),
|
writeBatch: newMemoryBatch(),
|
||||||
|
|
@ -389,7 +391,7 @@ func (f *MemoryFreezer) TruncateTail(tail uint64) (uint64, error) {
|
||||||
return old, nil
|
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.
|
// Only truncates blocks and receipts.
|
||||||
func (f *MemoryFreezer) TruncateTailBlocks(tail uint64) (uint64, error) {
|
func (f *MemoryFreezer) TruncateTailBlocks(tail uint64) (uint64, error) {
|
||||||
f.lock.Lock()
|
f.lock.Lock()
|
||||||
|
|
@ -402,8 +404,8 @@ func (f *MemoryFreezer) TruncateTailBlocks(tail uint64) (uint64, error) {
|
||||||
if old >= tail {
|
if old >= tail {
|
||||||
return old, nil
|
return old, nil
|
||||||
}
|
}
|
||||||
for kind, table := range f.tables {
|
for _, table := range f.tables {
|
||||||
if kind == ChainFreezerBodiesTable || kind == ChainFreezerReceiptTable {
|
if table.config.prunable {
|
||||||
if err := table.truncateTail(tail); err != nil {
|
if err := table.truncateTail(tail); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
@ -436,8 +438,8 @@ func (f *MemoryFreezer) Reset() error {
|
||||||
defer f.lock.Unlock()
|
defer f.lock.Unlock()
|
||||||
|
|
||||||
tables := make(map[string]*memoryTable)
|
tables := make(map[string]*memoryTable)
|
||||||
for name := range f.tables {
|
for name, table := range f.tables {
|
||||||
tables[name] = newMemoryTable(name)
|
tables[name] = newMemoryTable(name, table.config)
|
||||||
}
|
}
|
||||||
f.tables = tables
|
f.tables = tables
|
||||||
f.items, f.tail = 0, 0
|
f.items, f.tail = 0, 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue