Skip to content

Commit

Permalink
[R4R]fix: tools broken because of writting metadata when open a ready…
Browse files Browse the repository at this point in the history
…only db (#1013)

* freezer batch compatible offline prunblock command

adjust pruneblock local var

* not write metadata to db when open db with readyonly
  • Loading branch information
joeylichang authored Jul 25, 2022
1 parent d93211b commit 9d59a14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions core/rawdb/accessors_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func ReadOffSetOfCurrentAncientFreezer(db ethdb.KeyValueReader) uint64 {
// WriteOffSetOfCurrentAncientFreezer write prune block start
func WriteOffSetOfCurrentAncientFreezer(db ethdb.KeyValueWriter, offset uint64) {
if err := db.Put(offSetOfCurrentAncientFreezer, new(big.Int).SetUint64(offset).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store the current offset of ancient", "err", err)
}
}

Expand All @@ -209,7 +209,7 @@ func ReadOffSetOfLastAncientFreezer(db ethdb.KeyValueReader) uint64 {
// WriteOffSetOfLastAncientFreezer wirte before prune block start
func WriteOffSetOfLastAncientFreezer(db ethdb.KeyValueWriter, offset uint64) {
if err := db.Put(offSetOfLastAncientFreezer, new(big.Int).SetUint64(offset).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store the old offset of ancient", "err", err)
}
}

Expand All @@ -225,7 +225,7 @@ func ReadFrozenOfAncientFreezer(db ethdb.KeyValueReader) uint64 {
// WriteFrozenOfAncientFreezer write freezer block number
func WriteFrozenOfAncientFreezer(db ethdb.KeyValueWriter, frozen uint64) {
if err := db.Put(frozenOfAncientDBKey, new(big.Int).SetUint64(frozen).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store the ancient frozen number", "err", err)
}
}

Expand All @@ -241,7 +241,7 @@ func ReadSafePointBlockNumber(db ethdb.KeyValueReader) uint64 {
// WriteSafePointBlockNumber write the number of block that roothash save to disk
func WriteSafePointBlockNumber(db ethdb.KeyValueWriter, number uint64) {
if err := db.Put(LastSafePointBlockKey, new(big.Int).SetUint64(number).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store safe point of block number", "err", err)
}
}

Expand All @@ -257,6 +257,6 @@ func ReadAncientType(db ethdb.KeyValueReader) uint64 {
// WriteAncientType write freezer type
func WriteAncientType(db ethdb.KeyValueWriter, flag uint64) {
if err := db.Put(pruneAncientKey, new(big.Int).SetUint64(flag).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store prune ancient type", "err", err)
}
}
8 changes: 6 additions & 2 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace st
}

go frdb.freeze()
WriteAncientType(db, PruneFreezerType)
if !readonly {
WriteAncientType(db, PruneFreezerType)
}
return &freezerdb{
KeyValueStore: db,
AncientStore: frdb,
Expand Down Expand Up @@ -296,7 +298,9 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace st
}
}
// no prune ancinet start success
WriteAncientType(db, EntireFreezerType)
if !readonly {
WriteAncientType(db, EntireFreezerType)
}
// Freezer is consistent with the key-value database, permit combining the two
if !disableFreeze && !frdb.readonly {
frdb.wg.Add(1)
Expand Down

0 comments on commit 9d59a14

Please sign in to comment.