mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
core/rawdb: add truncateHeadBlocks to interface
This commit is contained in:
parent
4c23e7473d
commit
7824a0c56f
7 changed files with 62 additions and 8 deletions
|
|
@ -126,6 +126,11 @@ func (db *nofreezedb) TruncateTail(items uint64) (uint64, error) {
|
|||
return 0, errNotSupported
|
||||
}
|
||||
|
||||
// TruncateTailBlock returns an error as we don't have a backing chain freezer.
|
||||
func (db *nofreezedb) TruncateTailBlocks(items uint64) (uint64, error) {
|
||||
return 0, errNotSupported
|
||||
}
|
||||
|
||||
// Sync returns an error as we don't have a backing chain freezer.
|
||||
func (db *nofreezedb) Sync() error {
|
||||
return errNotSupported
|
||||
|
|
|
|||
|
|
@ -301,9 +301,9 @@ func (f *Freezer) TruncateHead(items uint64) (uint64, error) {
|
|||
return oitems, nil
|
||||
}
|
||||
|
||||
// TruncateTailNoHeads discards any recent data below the provided threshold number.
|
||||
// Does not truncate the header and hash table
|
||||
func (f *Freezer) TruncateTailNoHeads(tail uint64) (uint64, error) {
|
||||
// TruncateTailBlocks discards any recent data below the provided threshold number.
|
||||
// Only truncates blocks and receipts.
|
||||
func (f *Freezer) TruncateTailBlocks(tail uint64) (uint64, error) {
|
||||
if f.readonly {
|
||||
return 0, errReadOnly
|
||||
}
|
||||
|
|
@ -315,11 +315,10 @@ func (f *Freezer) TruncateTailNoHeads(tail uint64) (uint64, error) {
|
|||
return old, nil
|
||||
}
|
||||
for kind, table := range f.tables {
|
||||
if kind == ChainFreezerHeaderTable || kind == ChainFreezerHashTable {
|
||||
continue
|
||||
}
|
||||
if err := table.truncateTail(tail); err != nil {
|
||||
return 0, err
|
||||
if kind == ChainFreezerBodiesTable || kind == ChainFreezerReceiptTable {
|
||||
if err := table.truncateTail(tail); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
f.tail.Store(tail)
|
||||
|
|
|
|||
|
|
@ -389,6 +389,30 @@ func (f *MemoryFreezer) TruncateTail(tail uint64) (uint64, error) {
|
|||
return old, nil
|
||||
}
|
||||
|
||||
// TruncateTailBlocks discards any recent data below the provided threshold number.
|
||||
// Only truncates blocks and receipts.
|
||||
func (f *MemoryFreezer) TruncateTailBlocks(tail uint64) (uint64, error) {
|
||||
f.lock.Lock()
|
||||
defer f.lock.Unlock()
|
||||
|
||||
if f.readonly {
|
||||
return 0, errReadOnly
|
||||
}
|
||||
old := f.tail
|
||||
if old >= tail {
|
||||
return old, nil
|
||||
}
|
||||
for kind, table := range f.tables {
|
||||
if kind == ChainFreezerBodiesTable || kind == ChainFreezerReceiptTable {
|
||||
if err := table.truncateTail(tail); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
f.tail = tail
|
||||
return old, nil
|
||||
}
|
||||
|
||||
// Sync flushes all data tables to disk.
|
||||
func (f *MemoryFreezer) Sync() error {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -194,6 +194,15 @@ func (f *resettableFreezer) TruncateTail(tail uint64) (uint64, error) {
|
|||
return f.freezer.TruncateTail(tail)
|
||||
}
|
||||
|
||||
// TruncateTailBlocks discards any recent data below the provided threshold number.
|
||||
// It returns the previous value
|
||||
func (f *resettableFreezer) TruncateTailBlocks(tail uint64) (uint64, error) {
|
||||
f.lock.RLock()
|
||||
defer f.lock.RUnlock()
|
||||
|
||||
return f.freezer.TruncateTailBlocks(tail)
|
||||
}
|
||||
|
||||
// Sync flushes all data tables to disk.
|
||||
func (f *resettableFreezer) Sync() error {
|
||||
f.lock.RLock()
|
||||
|
|
|
|||
|
|
@ -107,6 +107,12 @@ func (t *table) TruncateTail(items uint64) (uint64, error) {
|
|||
return t.db.TruncateTail(items)
|
||||
}
|
||||
|
||||
// TruncateTailBlocks is a noop passthrough that just forwards the request to the underlying
|
||||
// database.
|
||||
func (t *table) TruncateTailBlocks(items uint64) (uint64, error) {
|
||||
return t.db.TruncateTailBlocks(items)
|
||||
}
|
||||
|
||||
// Sync is a noop passthrough that just forwards the request to the underlying
|
||||
// database.
|
||||
func (t *table) Sync() error {
|
||||
|
|
|
|||
|
|
@ -130,6 +130,13 @@ type AncientWriter interface {
|
|||
// will be removed all together.
|
||||
TruncateTail(n uint64) (uint64, error)
|
||||
|
||||
// TruncateTailBlocks discards the first n ancient data from the ancient store. The already
|
||||
// deleted items are ignored. After the truncation, the earliest item can be accessed
|
||||
// is item_n(start from 0). The deleted items may not be removed from the ancient store
|
||||
// immediately, but only when the accumulated deleted data reach the threshold then
|
||||
// will be removed all together. Only deletes bodies and receipts.
|
||||
TruncateTailBlocks(n uint64) (uint64, error)
|
||||
|
||||
// Sync flushes all in-memory ancient store data to disk.
|
||||
Sync() error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,10 @@ func (db *Database) TruncateTail(n uint64) (uint64, error) {
|
|||
panic("not supported")
|
||||
}
|
||||
|
||||
func (db *Database) TruncateTailBlocks(n uint64) (uint64, error) {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (db *Database) Sync() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue