Skip to content

chore: Remove TODO comment and improve FindDbsInPath documentation #1055

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions v2/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ func (sql *SqliteDb) ImportSnapshotFromTable(version int64, traverseOrder Traver
}

func (sql *SqliteDb) ImportMostRecentSnapshot(targetVersion int64, traverseOrder TraverseOrderType, loadLeaves bool) (*Node, int64, error) {
// First check if we need to find the database paths
if sql.opts.Path == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return nil, 0, fmt.Errorf("database path is empty")
}

read, err := sql.getReadConn()
if err != nil {
return nil, 0, err
Expand Down Expand Up @@ -414,6 +419,8 @@ func (sql *SqliteDb) ImportMostRecentSnapshot(targetVersion int64, traverseOrder
return root, version, err
}

// FindDbsInPath finds all database directories in the given path that contain a changelog.sqlite file.
// This function is used by various commands to locate IAVL databases.
func FindDbsInPath(path string) ([]string, error) {
var paths []string
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
Expand All @@ -431,9 +438,6 @@ func FindDbsInPath(path string) ([]string, error) {
return paths, nil
}

// TODO
// merge these two functions

func (snap *sqliteSnapshot) writeStep(node *Node) error {
snap.ordinal++
// Pre-order, NLR traversal
Expand Down
15 changes: 15 additions & 0 deletions v2/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,18 @@ func Test_ConcurrentIndexRead(t *testing.T) {
err = conn.Exec("CREATE INDEX foo_idx ON foo (id)")
require.NoError(t, err)
}

func TestImportMostRecentSnapshotEmptyPath(t *testing.T) {
// Create a db with empty path
sql, err := NewSqliteDb(NewNodePool(), SqliteDbOptions{Path: ""})
require.NoError(t, err)

// Attempt to import snapshot from an empty path
root, version, err := sql.ImportMostRecentSnapshot(1, PreOrder, false)

// Verify that we get the expected error about no prior snapshot found
require.Error(t, err)
require.Nil(t, root)
require.Equal(t, int64(0), version)
require.Contains(t, err.Error(), "no prior snapshot found")
}