-
Notifications
You must be signed in to change notification settings - Fork 266
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
feat: allow saving version 0 #1002
Changes from all commits
b7bfb3a
35f6e94
81b4a52
507b04b
f37eaef
f1d176e
cfce4c6
ec511e4
fbd5df5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
cmd/legacydump/legacydump | ||
vendor | ||
.glide | ||
*.swp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,12 @@ test-short: | |
@go test ./... $(LDFLAGS) -v --race --short | ||
.PHONY: test-short | ||
|
||
test: | ||
cmd/legacydump/legacydump: | ||
cd cmd/legacydump && go build -o legacydump main.go | ||
|
||
test: cmd/legacydump/legacydump | ||
@echo "--> Running go test" | ||
@go test ./... $(LDFLAGS) -v | ||
@go test ./... $(LDFLAGS) | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Removing --short flag will significantly impact test execution time The codebase contains several time-intensive tests that are specifically skipped in short mode:
Removing the --short flag will cause these tests to run, substantially increasing the CI pipeline duration. Consider keeping a separate make target for comprehensive testing (current 🔗 Analysis chainVerify test execution time impact. The removal of the Let's check the test execution time impact: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Compare test execution time with and without --short flag
echo "Running tests with --short flag..."
time go test ./... --short >/dev/null
echo -e "\nRunning tests without --short flag..."
time go test ./... >/dev/null
Length of output: 433 Script: #!/bin/bash
# Let's check for test files and analyze their content for long-running tests
# Look for test files with potential time-consuming operations
# Search for test files containing sleep, timeout, or other time-related patterns
echo "=== Test files with potential long-running operations ==="
rg -l --type go "time\.(Sleep|After|Tick)|context\.WithTimeout" ".*_test\.go$"
echo -e "\n=== Test files with skip conditions based on short flag ==="
rg -l --type go "testing\.Short\(\)" ".*_test\.go$"
echo -e "\n=== Detailed context of tests using Short() flag ==="
rg -B2 -A2 --type go "testing\.Short\(\)" ".*_test\.go$"
Length of output: 733 Script: #!/bin/bash
# Let's try a different approach to find test files
echo "=== Finding Go test files ==="
fd "_test\.go$"
echo -e "\n=== Checking Makefile history for test-related changes ==="
git log -p -- Makefile | grep -A 5 -B 5 "go test"
Length of output: 3363 Script: #!/bin/bash
# Let's analyze the test files for time-consuming operations and short flag usage
echo "=== Checking test files for time-consuming operations ==="
rg -C3 "time\.(Sleep|After|Tick)|context\.WithTimeout" basic_test.go batch_test.go tree_test.go mutable_tree_test.go
echo -e "\n=== Checking test files for testing.Short() usage ==="
rg -C3 "testing\.Short\(\)" basic_test.go batch_test.go tree_test.go mutable_tree_test.go
echo -e "\n=== Checking for large test data or iterations ==="
rg -C3 "for.+range|for.+:=.+;.+;" basic_test.go batch_test.go tree_test.go mutable_tree_test.go | rg "1000|10000"
Length of output: 2610 |
||
.PHONY: test | ||
|
||
format: | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,6 +40,7 @@ type MutableTree struct { | |||||||||||||||
unsavedFastNodeRemovals *sync.Map // map[string]interface{} FastNodes that have not yet been removed from disk | ||||||||||||||||
ndb *nodeDB | ||||||||||||||||
skipFastStorageUpgrade bool // If true, the tree will work like no fast storage and always not upgrade fast storage | ||||||||||||||||
initialVersionSet bool | ||||||||||||||||
|
||||||||||||||||
mtx sync.Mutex | ||||||||||||||||
} | ||||||||||||||||
|
@@ -62,6 +63,7 @@ func NewMutableTree(db corestore.KVStoreWithBatch, cacheSize int, skipFastStorag | |||||||||||||||
unsavedFastNodeRemovals: &sync.Map{}, | ||||||||||||||||
ndb: ndb, | ||||||||||||||||
skipFastStorageUpgrade: skipFastStorageUpgrade, | ||||||||||||||||
initialVersionSet: opts.initialVersionSet, | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
@@ -73,7 +75,8 @@ func (tree *MutableTree) IsEmpty() bool { | |||||||||||||||
|
||||||||||||||||
// GetLatestVersion returns the latest version of the tree. | ||||||||||||||||
func (tree *MutableTree) GetLatestVersion() (int64, error) { | ||||||||||||||||
return tree.ndb.getLatestVersion() | ||||||||||||||||
_, v, err := tree.ndb.getLatestVersion() | ||||||||||||||||
return v, err | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// VersionExists returns whether or not a version exists. | ||||||||||||||||
|
@@ -90,10 +93,13 @@ func (tree *MutableTree) VersionExists(version int64) bool { | |||||||||||||||
if err != nil { | ||||||||||||||||
return false | ||||||||||||||||
} | ||||||||||||||||
latestVersion, err := tree.ndb.getLatestVersion() | ||||||||||||||||
found, latestVersion, err := tree.ndb.getLatestVersion() | ||||||||||||||||
if err != nil { | ||||||||||||||||
return false | ||||||||||||||||
} | ||||||||||||||||
if !found { | ||||||||||||||||
return false | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return firstVersion <= version && version <= latestVersion | ||||||||||||||||
} | ||||||||||||||||
|
@@ -104,7 +110,7 @@ func (tree *MutableTree) AvailableVersions() []int { | |||||||||||||||
if err != nil { | ||||||||||||||||
return nil | ||||||||||||||||
} | ||||||||||||||||
latestVersion, err := tree.ndb.getLatestVersion() | ||||||||||||||||
_, latestVersion, err := tree.ndb.getLatestVersion() | ||||||||||||||||
if err != nil { | ||||||||||||||||
return nil | ||||||||||||||||
} | ||||||||||||||||
|
@@ -146,7 +152,7 @@ func (tree *MutableTree) WorkingHash() []byte { | |||||||||||||||
|
||||||||||||||||
func (tree *MutableTree) WorkingVersion() int64 { | ||||||||||||||||
version := tree.version + 1 | ||||||||||||||||
if version == 1 && tree.ndb.opts.InitialVersion > 0 { | ||||||||||||||||
if version == 1 && tree.initialVersionSet { | ||||||||||||||||
version = int64(tree.ndb.opts.InitialVersion) | ||||||||||||||||
} | ||||||||||||||||
return version | ||||||||||||||||
|
@@ -449,21 +455,16 @@ func (tree *MutableTree) LoadVersion(targetVersion int64) (int64, error) { | |||||||||||||||
tree.ndb.opts.InitialVersion, firstVersion) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
latestVersion, err := tree.ndb.getLatestVersion() | ||||||||||||||||
ok, latestVersion, err := tree.ndb.getLatestVersion() | ||||||||||||||||
if err != nil { | ||||||||||||||||
return 0, err | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if firstVersion > 0 && firstVersion < int64(tree.ndb.opts.InitialVersion) { | ||||||||||||||||
return latestVersion, fmt.Errorf("initial version set to %v, but found earlier version %v", | ||||||||||||||||
tree.ndb.opts.InitialVersion, firstVersion) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if latestVersion < targetVersion { | ||||||||||||||||
return latestVersion, fmt.Errorf("wanted to load target %d but only found up to %d", targetVersion, latestVersion) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if firstVersion == 0 { | ||||||||||||||||
if !ok { | ||||||||||||||||
if targetVersion <= 0 { | ||||||||||||||||
if !tree.skipFastStorageUpgrade { | ||||||||||||||||
tree.mtx.Lock() | ||||||||||||||||
|
@@ -604,7 +605,7 @@ func (tree *MutableTree) enableFastStorageAndCommit() error { | |||||||||||||||
return err | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
latestVersion, err := tree.ndb.getLatestVersion() | ||||||||||||||||
_, latestVersion, err := tree.ndb.getLatestVersion() | ||||||||||||||||
if err != nil { | ||||||||||||||||
return err | ||||||||||||||||
} | ||||||||||||||||
|
@@ -707,6 +708,7 @@ func (tree *MutableTree) UnsetCommitting() { | |||||||||||||||
// the tree. Returns the hash and new version number. | ||||||||||||||||
func (tree *MutableTree) SaveVersion() ([]byte, int64, error) { | ||||||||||||||||
version := tree.WorkingVersion() | ||||||||||||||||
tree.initialVersionSet = false | ||||||||||||||||
|
||||||||||||||||
if tree.VersionExists(version) { | ||||||||||||||||
// If the version already exists, return an error as we're attempting to overwrite. | ||||||||||||||||
|
@@ -871,6 +873,7 @@ func (tree *MutableTree) saveFastNodeRemovals() error { | |||||||||||||||
// and is otherwise ignored. | ||||||||||||||||
func (tree *MutableTree) SetInitialVersion(version uint64) { | ||||||||||||||||
tree.ndb.opts.InitialVersion = version | ||||||||||||||||
tree.initialVersionSet = true | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding mutex protection for thread safety The Apply this diff to add mutex protection: func (tree *MutableTree) SetInitialVersion(version uint64) {
+ tree.mtx.Lock()
+ defer tree.mtx.Unlock()
tree.ndb.opts.InitialVersion = version
tree.initialVersionSet = true
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// DeleteVersionsTo removes versions upto the given version from the MutableTree. | ||||||||||||||||
|
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.
🛠️ Refactor suggestion
Improve the binary build step
The current approach of changing directories to build the binary has several issues:
Additionally, consider adding a cleanup step in a
post
block to ensure the binary is removed after tests: