@@ -44,24 +44,29 @@ func InitDatabaseFromFreezer(db ethdb.Database) {
44
44
logged = start .Add (- 7 * time .Second ) // Unindex during import is fast, don't double log
45
45
hash common.Hash
46
46
)
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 {
53
55
log .Crit ("Failed to init database from freezer" , "err" , err )
54
- } else {
55
- hash = common .BytesToHash (h )
56
56
}
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 ()
62
67
}
63
- batch .Reset ()
64
68
}
69
+ i += uint64 (len (data ))
65
70
// If we've spent too much time already, notify the user of what we're doing
66
71
if time .Since (logged ) > 8 * time .Second {
67
72
log .Info ("Initializing database from freezer" , "total" , frozen , "number" , i , "hash" , hash , "elapsed" , common .PrettyDuration (time .Since (start )))
0 commit comments