Skip to content

Commit b0bffc5

Browse files
holimanjagdeep sidhu
authored and
jagdeep sidhu
committed
core/rawdb: use AncientRange when initializing leveldb from freezer (ethereum#23612)
* core/rawdb: utilize AncientRange when initiating from freezer * core/rawdb: remove debug sanity check
1 parent 529327e commit b0bffc5

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

core/rawdb/chain_iterator.go

+19-14
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,29 @@ func InitDatabaseFromFreezer(db ethdb.Database) {
4444
logged = start.Add(-7 * time.Second) // Unindex during import is fast, don't double log
4545
hash common.Hash
4646
)
47-
for i := uint64(0); i < frozen; i++ {
48-
// Since the freezer has all data in sequential order on a file,
49-
// it would be 'neat' to read more data in one go, and let the
50-
// freezerdb return N items (e.g up to 1000 items per go)
51-
// That would require an API change in Ancients though
52-
if h, err := db.Ancient(freezerHashTable, i); err != nil {
47+
for i := uint64(0); i < frozen; {
48+
// We read 100K hashes at a time, for a total of 3.2M
49+
count := uint64(100_000)
50+
if i+count > frozen {
51+
count = frozen - i
52+
}
53+
data, err := db.AncientRange(freezerHashTable, i, count, 32*count)
54+
if err != nil {
5355
log.Crit("Failed to init database from freezer", "err", err)
54-
} else {
55-
hash = common.BytesToHash(h)
5656
}
57-
WriteHeaderNumber(batch, hash, i)
58-
// If enough data was accumulated in memory or we're at the last block, dump to disk
59-
if batch.ValueSize() > ethdb.IdealBatchSize {
60-
if err := batch.Write(); err != nil {
61-
log.Crit("Failed to write data to db", "err", err)
57+
for j, h := range data {
58+
number := i + uint64(j)
59+
hash = common.BytesToHash(h)
60+
WriteHeaderNumber(batch, hash, number)
61+
// If enough data was accumulated in memory or we're at the last block, dump to disk
62+
if batch.ValueSize() > ethdb.IdealBatchSize {
63+
if err := batch.Write(); err != nil {
64+
log.Crit("Failed to write data to db", "err", err)
65+
}
66+
batch.Reset()
6267
}
63-
batch.Reset()
6468
}
69+
i += uint64(len(data))
6570
// If we've spent too much time already, notify the user of what we're doing
6671
if time.Since(logged) > 8*time.Second {
6772
log.Info("Initializing database from freezer", "total", frozen, "number", i, "hash", hash, "elapsed", common.PrettyDuration(time.Since(start)))

0 commit comments

Comments
 (0)