mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core/rawdb: remove TruncateTailBlocks
Put the condition into TruncateTail instead.
This commit is contained in:
parent
7b51129b0d
commit
3e032ccd7a
8 changed files with 19 additions and 86 deletions
|
|
@ -48,7 +48,7 @@ var chainFreezerTableConfigs = map[string]freezerTableConfig{
|
||||||
|
|
||||||
type freezerTableConfig struct {
|
type freezerTableConfig struct {
|
||||||
noSnappy bool // disables item compression
|
noSnappy bool // disables item compression
|
||||||
prunable bool // true for tables that can be truncated by TruncateTailBlocks
|
prunable bool // true for tables that can be pruned by TruncateTail
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -65,11 +65,11 @@ const (
|
||||||
|
|
||||||
// stateFreezerTableConfigs configures whether compression is disabled for the state freezer.
|
// stateFreezerTableConfigs configures whether compression is disabled for the state freezer.
|
||||||
var stateFreezerTableConfigs = map[string]freezerTableConfig{
|
var stateFreezerTableConfigs = map[string]freezerTableConfig{
|
||||||
stateHistoryMeta: {noSnappy: true, prunable: false},
|
stateHistoryMeta: {noSnappy: true, prunable: true},
|
||||||
stateHistoryAccountIndex: {noSnappy: false, prunable: false},
|
stateHistoryAccountIndex: {noSnappy: false, prunable: true},
|
||||||
stateHistoryStorageIndex: {noSnappy: false, prunable: false},
|
stateHistoryStorageIndex: {noSnappy: false, prunable: true},
|
||||||
stateHistoryAccountData: {noSnappy: false, prunable: false},
|
stateHistoryAccountData: {noSnappy: false, prunable: true},
|
||||||
stateHistoryStorageData: {noSnappy: false, prunable: false},
|
stateHistoryStorageData: {noSnappy: false, prunable: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
// The list of identifiers of ancient stores.
|
// The list of identifiers of ancient stores.
|
||||||
|
|
|
||||||
|
|
@ -126,11 +126,6 @@ func (db *nofreezedb) TruncateTail(items uint64) (uint64, error) {
|
||||||
return 0, errNotSupported
|
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.
|
// Sync returns an error as we don't have a backing chain freezer.
|
||||||
func (db *nofreezedb) Sync() error {
|
func (db *nofreezedb) Sync() error {
|
||||||
return errNotSupported
|
return errNotSupported
|
||||||
|
|
|
||||||
|
|
@ -301,32 +301,9 @@ func (f *Freezer) TruncateHead(items uint64) (uint64, error) {
|
||||||
return oitems, nil
|
return oitems, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TruncateTailBlocks discards all data below the provided threshold block number.
|
// TruncateTail discards all data below the provided threshold number
|
||||||
// This is intended to be used with the chain freezer. Unlike TruncateTail, it
|
// Note this will only truncate 'prunable' tables. Block headers and canonical
|
||||||
// only truncates blocks and receipts, leaving the header table where it is.
|
// hashes cannot be truncated at this time.
|
||||||
func (f *Freezer) TruncateTailBlocks(tailBlock uint64) (uint64, error) {
|
|
||||||
if f.readonly {
|
|
||||||
return 0, errReadOnly
|
|
||||||
}
|
|
||||||
f.writeLock.Lock()
|
|
||||||
defer f.writeLock.Unlock()
|
|
||||||
|
|
||||||
old := f.tail.Load()
|
|
||||||
if old >= tailBlock {
|
|
||||||
return old, nil
|
|
||||||
}
|
|
||||||
for _, table := range f.tables {
|
|
||||||
if table.config.prunable {
|
|
||||||
if err := table.truncateTail(tailBlock); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.tail.Store(tailBlock)
|
|
||||||
return old, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TruncateTail discards all data below the provided threshold number.
|
|
||||||
func (f *Freezer) TruncateTail(tail uint64) (uint64, error) {
|
func (f *Freezer) TruncateTail(tail uint64) (uint64, error) {
|
||||||
if f.readonly {
|
if f.readonly {
|
||||||
return 0, errReadOnly
|
return 0, errReadOnly
|
||||||
|
|
@ -339,10 +316,12 @@ func (f *Freezer) TruncateTail(tail uint64) (uint64, error) {
|
||||||
return old, nil
|
return old, nil
|
||||||
}
|
}
|
||||||
for _, table := range f.tables {
|
for _, table := range f.tables {
|
||||||
|
if table.config.prunable {
|
||||||
if err := table.truncateTail(tail); err != nil {
|
if err := table.truncateTail(tail); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
f.tail.Store(tail)
|
f.tail.Store(tail)
|
||||||
return old, nil
|
return old, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -370,33 +370,13 @@ func (f *MemoryFreezer) TruncateHead(items uint64) (uint64, error) {
|
||||||
return old, nil
|
return old, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TruncateTail discards any recent data below the provided threshold number.
|
// TruncateTail discards all data below the provided threshold number.
|
||||||
|
// Note this will only truncate 'prunable' tables. Block headers and canonical
|
||||||
|
// hashes cannot be truncated at this time.
|
||||||
func (f *MemoryFreezer) TruncateTail(tail uint64) (uint64, error) {
|
func (f *MemoryFreezer) TruncateTail(tail uint64) (uint64, error) {
|
||||||
f.lock.Lock()
|
f.lock.Lock()
|
||||||
defer f.lock.Unlock()
|
defer f.lock.Unlock()
|
||||||
|
|
||||||
if f.readonly {
|
|
||||||
return 0, errReadOnly
|
|
||||||
}
|
|
||||||
old := f.tail
|
|
||||||
if old >= tail {
|
|
||||||
return old, nil
|
|
||||||
}
|
|
||||||
for _, table := range f.tables {
|
|
||||||
if err := table.truncateTail(tail); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.tail = tail
|
|
||||||
return old, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TruncateTailBlocks discards all data below the provided block.
|
|
||||||
// Only truncates blocks and receipts.
|
|
||||||
func (f *MemoryFreezer) TruncateTailBlocks(tail uint64) (uint64, error) {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
if f.readonly {
|
if f.readonly {
|
||||||
return 0, errReadOnly
|
return 0, errReadOnly
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -194,15 +194,6 @@ func (f *resettableFreezer) TruncateTail(tail uint64) (uint64, error) {
|
||||||
return f.freezer.TruncateTail(tail)
|
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.
|
// Sync flushes all data tables to disk.
|
||||||
func (f *resettableFreezer) Sync() error {
|
func (f *resettableFreezer) Sync() error {
|
||||||
f.lock.RLock()
|
f.lock.RLock()
|
||||||
|
|
|
||||||
|
|
@ -107,12 +107,6 @@ func (t *table) TruncateTail(items uint64) (uint64, error) {
|
||||||
return t.db.TruncateTail(items)
|
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
|
// Sync is a noop passthrough that just forwards the request to the underlying
|
||||||
// database.
|
// database.
|
||||||
func (t *table) Sync() error {
|
func (t *table) Sync() error {
|
||||||
|
|
|
||||||
|
|
@ -128,13 +128,11 @@ type AncientWriter interface {
|
||||||
// is item_n(start from 0). The deleted items may not be removed from the ancient store
|
// 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
|
// immediately, but only when the accumulated deleted data reach the threshold then
|
||||||
// will be removed all together.
|
// will be removed all together.
|
||||||
|
//
|
||||||
|
// Note this will only truncate 'prunable' tables. Block headers and canonical
|
||||||
|
// hashes cannot be truncated at this time.
|
||||||
TruncateTail(n uint64) (uint64, error)
|
TruncateTail(n uint64) (uint64, error)
|
||||||
|
|
||||||
// TruncateTailBlocks discards all blocks and receipts below the given number from the
|
|
||||||
// ancient store. Headers are left as-is. This is intended to be used with the chain
|
|
||||||
// freezer specifically.
|
|
||||||
TruncateTailBlocks(tailBlock uint64) (uint64, error)
|
|
||||||
|
|
||||||
// Sync flushes all in-memory ancient store data to disk.
|
// Sync flushes all in-memory ancient store data to disk.
|
||||||
Sync() error
|
Sync() error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,10 +110,6 @@ func (db *Database) TruncateTail(n uint64) (uint64, error) {
|
||||||
panic("not supported")
|
panic("not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Database) TruncateTailBlocks(n uint64) (uint64, error) {
|
|
||||||
panic("not supported")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *Database) Sync() error {
|
func (db *Database) Sync() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue