Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sapshots: remove modtime protection #8573

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 16 additions & 41 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ func (sn *HeaderSegment) reopenIdx(dir string) (err error) {
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, fileName)
}
if sn.idxHeaderHash.ModTime().Before(sn.seg.ModTime()) {
// Index has been created before the segment file, needs to be ignored (and rebuilt) as inconsistent
sn.idxHeaderHash.Close()
sn.idxHeaderHash = nil
}

return nil
}

Expand Down Expand Up @@ -182,11 +178,6 @@ func (sn *BodySegment) reopenIdx(dir string) (err error) {
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, fileName)
}
if sn.idxBodyNumber.ModTime().Before(sn.seg.ModTime()) {
// Index has been created before the segment file, needs to be ignored (and rebuilt) as inconsistent
sn.idxBodyNumber.Close()
sn.idxBodyNumber = nil
}
return nil
}

Expand Down Expand Up @@ -229,24 +220,27 @@ func (sn *TxnSegment) reopenIdx(dir string) (err error) {
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, fileName)
}
if sn.IdxTxnHash.ModTime().Before(sn.Seg.ModTime()) {
log.Trace("[snapshots] skip index because it modify time is ahead before .seg file", "name", sn.IdxTxnHash.FileName())
// Index has been created before the segment file, needs to be ignored (and rebuilt) as inconsistent
sn.IdxTxnHash.Close()
sn.IdxTxnHash = nil
}

/*
// Historically we had several times when:
// - erigon downloaded new version of .seg file
// - or didn't finish download and start indexing
// this was a "quick-fix protection" against this cases
// but now we have other protections for this cases
// let's try to remove this one - because it's not compatible with "copy datadir" and "restore datadir from backup" scenarios
if sn.IdxTxnHash.ModTime().Before(sn.Seg.ModTime()) {
log.Trace("[snapshots] skip index because it modify time is ahead before .seg file", "name", sn.IdxTxnHash.FileName())
//Index has been created before the segment file, needs to be ignored (and rebuilt) as inconsistent
sn.IdxTxnHash.Close()
sn.IdxTxnHash = nil
}
*/

fileName = snaptype.IdxFileName(sn.ranges.from, sn.ranges.to, snaptype.Transactions2Block.String())
sn.IdxTxnHash2BlockNum, err = recsplit.OpenIndex(path.Join(dir, fileName))
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, fileName)
}
if sn.IdxTxnHash2BlockNum.ModTime().Before(sn.Seg.ModTime()) {
log.Trace("[snapshots] skip index because it modify time is ahead before .seg file", "name", sn.IdxTxnHash2BlockNum.FileName())
// Index has been created before the segment file, needs to be ignored (and rebuilt) as inconsistent
sn.IdxTxnHash2BlockNum.Close()
sn.IdxTxnHash2BlockNum = nil
}
return nil
}

Expand Down Expand Up @@ -1547,10 +1541,6 @@ func dumpBlocksRange(ctx context.Context, blockFrom, blockTo uint64, tmpDir, sna
}

func hasIdxFile(sn snaptype.FileInfo, logger log.Logger) bool {
stat, err := os.Stat(sn.Path)
if err != nil {
return false
}
dir, _ := filepath.Split(sn.Path)
fName := snaptype.IdxFileName(sn.From, sn.To, sn.T.String())
var result = true
Expand All @@ -1560,34 +1550,19 @@ func hasIdxFile(sn snaptype.FileInfo, logger log.Logger) bool {
if err != nil {
return false
}
// If index was created before the segment file, it needs to be ignored (and rebuilt)
if idx.ModTime().Before(stat.ModTime()) {
logger.Warn("Index file has timestamp before segment file, will be recreated", "segfile", sn.Path, "segtime", stat.ModTime(), "idxfile", fName, "idxtime", idx.ModTime())
result = false
}
idx.Close()
case snaptype.Transactions:
idx, err := recsplit.OpenIndex(path.Join(dir, fName))
if err != nil {
return false
}
// If index was created before the segment file, it needs to be ignored (and rebuilt)
if idx.ModTime().Before(stat.ModTime()) {
log.Warn("Index file has timestamp before segment file, will be recreated", "segfile", sn.Path, "segtime", stat.ModTime(), "idxfile", fName, "idxtime", idx.ModTime())
result = false
}
idx.Close()

fName = snaptype.IdxFileName(sn.From, sn.To, snaptype.Transactions2Block.String())
idx, err = recsplit.OpenIndex(path.Join(dir, fName))
if err != nil {
return false
}
// If index was created before the segment file, it needs to be ignored (and rebuilt)
if idx.ModTime().Before(stat.ModTime()) {
logger.Warn("Index file has timestamp before segment file, will be recreated", "segfile", sn.Path, "segtime", stat.ModTime(), "idxfile", fName, "idxtime", idx.ModTime())
result = false
}
idx.Close()
}
return result
Expand Down
10 changes: 0 additions & 10 deletions turbo/snapshotsync/freezeblocks/bor_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ func (sn *BorEventSegment) reopenIdx(dir string) (err error) {
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, fileName)
}
if sn.IdxBorTxnHash.ModTime().Before(sn.seg.ModTime()) {
// Index has been created before the segment file, needs to be ignored (and rebuilt) as inconsistent
sn.IdxBorTxnHash.Close()
sn.IdxBorTxnHash = nil
}
return nil
}

Expand Down Expand Up @@ -154,11 +149,6 @@ func (sn *BorSpanSegment) reopenIdx(dir string) (err error) {
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, fileName)
}
if sn.idx.ModTime().Before(sn.seg.ModTime()) {
// Index has been created before the segment file, needs to be ignored (and rebuilt) as inconsistent
sn.idx.Close()
sn.idx = nil
}
return nil
}

Expand Down
5 changes: 0 additions & 5 deletions turbo/snapshotsync/freezeblocks/caplin_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ func (sn *BeaconBlockSegment) reopenIdx(dir string) (err error) {
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, fileName)
}
if sn.idxSlot.ModTime().Before(sn.seg.ModTime()) {
// Index has been created before the segment file, needs to be ignored (and rebuilt) as inconsistent
sn.idxSlot.Close()
sn.idxSlot = nil
}
return nil
}

Expand Down
Loading