-
Notifications
You must be signed in to change notification settings - Fork 237
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
Problem: memiavl snapshot rewriting is not triggered #1034
Problem: memiavl snapshot rewriting is not triggered #1034
Conversation
Solution: - add configs to trigger the snapshot rewriting.
Signed-off-by: yihuang <huang@crypto.com>
Codecov Report
@@ Coverage Diff @@
## main #1034 +/- ##
===========================================
+ Coverage 22.43% 46.55% +24.11%
===========================================
Files 50 82 +32
Lines 3013 7091 +4078
===========================================
+ Hits 676 3301 +2625
- Misses 2272 3443 +1171
- Partials 65 347 +282
|
@@ -372,18 +404,26 @@ | |||
return nil | |||
} | |||
|
|||
// rewriteIfApplicable execute the snapshot rewrite strategy according to current height | |||
func (db *DB) rewriteIfApplicable(height int64) { | |||
if height%int64(db.snapshotInterval) != 0 { |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
for key := range rs.stores { | ||
store := rs.stores[key] | ||
if store.GetStoreType() == types.StoreTypeIAVL { | ||
rs.stores[key], err = rs.loadCommitStoreFromParams(rs.db, key, rs.storesParams[key]) | ||
if err != nil { | ||
panic(fmt.Errorf("inconsistent store map, store %s not found", key.Name())) | ||
} | ||
} | ||
} |
Check failure
Code scanning / gosec
the value in the range statement should be _ unless copying a map: want: for key := range m
for key := range rs.stores { | ||
store := rs.stores[key] | ||
if store.GetStoreType() == types.StoreTypeIAVL { | ||
rs.stores[key], err = rs.loadCommitStoreFromParams(rs.db, key, rs.storesParams[key]) | ||
if err != nil { | ||
panic(fmt.Errorf("inconsistent store map, store %s not found", key.Name())) | ||
} | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map
if initialVersion > 1 { | ||
return int64(index) + int64(initialVersion) - 1 | ||
} | ||
return int64(index) |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
// walVersion converts wal index to version, reverse of walIndex | ||
func walVersion(index uint64, initialVersion uint32) int64 { | ||
if initialVersion > 1 { | ||
return int64(index) + int64(initialVersion) - 1 |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
// walVersion converts wal index to version, reverse of walIndex | ||
func walVersion(index uint64, initialVersion uint32) int64 { | ||
if initialVersion > 1 { | ||
return int64(index) + int64(initialVersion) - 1 |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
12c2522
to
46b7a07
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems async wal writing goroutine quit unexpectedly when file already closed
where did you see that error? |
I was trying ibc test
|
|
||
// truncate WAL until the earliest remaining snapshot | ||
earliestVersion, err := firstSnapshotVersion(db.dir) | ||
if err := db.wal.TruncateFront(uint64(earliestVersion + 1)); err != nil { |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := mtree.CatchupWAL(wal, int64(opts.TargetVersion)); err != nil { | ||
return nil, err | ||
if opts.TargetVersion == 0 || int64(opts.TargetVersion) > mtree.Version() { |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
return nil, fmt.Errorf("failed to load current version: %w", err) | ||
} | ||
|
||
if int64(opts.TargetVersion) < version { |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
is it when quitting the node? it seems don't reproduce here. |
if err := mtree.CatchupWAL(wal, int64(opts.TargetVersion)); err != nil { | ||
return nil, err | ||
if opts.TargetVersion == 0 || int64(opts.TargetVersion) > mtree.Version() { | ||
if err := mtree.CatchupWAL(wal, int64(opts.TargetVersion)); err != nil { |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
go func() { | ||
defer db.pruneSnapshotLock.Unlock() | ||
|
||
currentName, err := os.Readlink(currentPath(db.dir)) | ||
if err != nil { | ||
db.logger.Error("failed to read current snapshot name", "err", err) | ||
return | ||
} | ||
|
||
entries, err := os.ReadDir(db.dir) | ||
if err != nil { | ||
db.logger.Error("failed to read db dir", "err", err) | ||
return | ||
} | ||
|
||
counter := db.snapshotKeepRecent | ||
for i := len(entries) - 1; i >= 0; i-- { | ||
name := entries[i].Name() | ||
if !strings.HasPrefix(name, SnapshotPrefix) { | ||
continue | ||
} | ||
|
||
if name >= currentName { | ||
// ignore any newer snapshot directories, there could be ongoning snapshot rewrite. | ||
continue | ||
} | ||
|
||
if counter > 0 { | ||
counter-- | ||
continue | ||
} | ||
|
||
db.logger.Info("prune snapshot", "name", name) | ||
if err := os.RemoveAll(filepath.Join(db.dir, name)); err != nil { | ||
db.logger.Error("failed to prune snapshot", "err", err) | ||
} | ||
} | ||
|
||
// truncate WAL until the earliest remaining snapshot | ||
earliestVersion, err := firstSnapshotVersion(db.dir) | ||
if err != nil { | ||
db.logger.Error("failed to find first snapshot", "err", err) | ||
} | ||
|
||
if err := db.wal.TruncateFront(uint64(earliestVersion + 1)); err != nil { | ||
db.logger.Error("failed to truncate wal", "err", err, "version", earliestVersion+1) | ||
} | ||
}() |
Check notice
Code scanning / CodeQL
Spawning a Go routine
Strange that I only see once in e2e, maybe I can add some unit test later |
Solution:
👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻
PR Checklist:
make
)make test
)go fmt
)golangci-lint run
)go list -json -m all | nancy sleuth
)Thank you for your code, it's appreciated! :)