Skip to content

Commit

Permalink
core/rawdb: comment, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Nov 15, 2021
1 parent 16286fa commit 05812de
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions core/rawdb/freezer.go
Expand Up @@ -596,7 +596,10 @@ func (f *freezer) TransformTable(kind string, fn TransformerFn) error {
batch := newTable.newBatch()

var i uint64
// Number of the file in which the first up-to-date receipt appers
var filenum uint32
// Iterate through entries and transform them
// until reaching first non-legacy one.
for i = 0; i < numAncients; i++ {
blob, err := table.Retrieve(i)
if err != nil {
Expand All @@ -612,6 +615,8 @@ func (f *freezer) TransformTable(kind string, fn TransformerFn) error {
} else {
// Reached the first up-to-date entry.
// Remember in which file the switch happens.
// TODO: what if it coincidentally starts in a new file?
// we won't need to copy-over that file
entry, err := table.getIndices(i, 0)
if err != nil {
return err
Expand Down Expand Up @@ -645,15 +650,22 @@ func (f *freezer) TransformTable(kind string, fn TransformerFn) error {
}
log.Info("Finished copying leftovers", "i", i)

if err := batch.commit(); err != nil {
return err
}
log.Info("Committed write batch", "newHeadId", newTable.headId, "headbytes", newTable.headBytes, "items", newTable.items)

// 3. need to copy rest of old index and repair the filenum in the entries
if i < numAncients {
idx, err := table.readEntry(i)
if err != nil {
return err
}

lastFilenum := atomic.LoadUint32(&newTable.headId)
diff := int32(lastFilenum) - int32(idx.filenum)
lastFilenum := newTable.headId
// idx.filenum is always >=1
diff := int32(lastFilenum) - int32(idx.filenum-1)
log.Info("Starting duplication", "i", i, "oldFn", idx.filenum, "offset", idx.offset, "newHeadId", lastFilenum)
for ; i < numAncients; i++ {
idx, err := table.readEntry(i)
if err != nil {
Expand All @@ -666,14 +678,12 @@ func (f *freezer) TransformTable(kind string, fn TransformerFn) error {
log.Info("Duplicated rest of index in new table", "i", i)
}

if err := batch.commit(); err != nil {
return err
}

if err := newTable.Close(); err != nil {
return err
}

// Delete old table index & files up to cross-over point

// Move new table files to ancients dir
files, err := ioutil.ReadDir(migrationPath)
if err != nil {
Expand Down

0 comments on commit 05812de

Please sign in to comment.