mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
core/rawdb: implement tail truncation change in memory freezer
This commit is contained in:
parent
d9eea18517
commit
07511b5359
2 changed files with 29 additions and 1 deletions
|
|
@ -260,6 +260,24 @@ func basicWrite(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to write ancient data %v", err)
|
t.Fatalf("Failed to write ancient data %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write should work after truncating from tail but over the head
|
||||||
|
db.TruncateTail(200)
|
||||||
|
_, err = db.ModifyAncients(func(op ethdb.AncientWriteOp) error {
|
||||||
|
offset := uint64(200)
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
if err := op.AppendRaw("a", offset+uint64(i), dataA[i]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := op.AppendRaw("b", offset+uint64(i), dataB[i]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to write ancient data %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func nonMutable(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {
|
func nonMutable(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ func (t *memoryTable) truncateTail(items uint64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if t.items < items {
|
if t.items < items {
|
||||||
return errors.New("truncation above head")
|
return t.reset(items)
|
||||||
}
|
}
|
||||||
for i := uint64(0); i < items-t.offset; i++ {
|
for i := uint64(0); i < items-t.offset; i++ {
|
||||||
if t.size > uint64(len(t.data[i])) {
|
if t.size > uint64(len(t.data[i])) {
|
||||||
|
|
@ -127,6 +127,16 @@ func (t *memoryTable) truncateTail(items uint64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reset clears the entire table and sets both the head and tail to the given
|
||||||
|
// value. It assumes the caller holds the lock and that tail > t.items.
|
||||||
|
func (t *memoryTable) reset(offset uint64) error {
|
||||||
|
t.size = 0
|
||||||
|
t.data = nil
|
||||||
|
t.items = offset
|
||||||
|
t.offset = offset
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// commit merges the given item batch into table. It's presumed that the
|
// commit merges the given item batch into table. It's presumed that the
|
||||||
// batch is ordered and continuous with table.
|
// batch is ordered and continuous with table.
|
||||||
func (t *memoryTable) commit(batch [][]byte) error {
|
func (t *memoryTable) commit(batch [][]byte) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue