-
Notifications
You must be signed in to change notification settings - Fork 534
tools: update catchpointdump 'database' and 'database check' commands to handle staging tables and KVs #4802
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
Changes from 2 commits
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 |
|---|---|---|
|
|
@@ -127,11 +127,11 @@ var fileCmd = &cobra.Command{ | |
| defer outFile.Close() | ||
| } | ||
|
|
||
| err = printAccountsDatabase("./ledger.tracker.sqlite", fileHeader, outFile, excludedFields.GetSlice()) | ||
| err = printAccountsDatabase("./ledger.tracker.sqlite", true, fileHeader, outFile, excludedFields.GetSlice()) | ||
| if err != nil { | ||
| reportErrorf("Unable to print account database : %v", err) | ||
| } | ||
| err = printKeyValueStore("./ledger.tracker.sqlite", outFile) | ||
| err = printKeyValueStore("./ledger.tracker.sqlite", true, fileHeader, outFile) | ||
| if err != nil { | ||
| reportErrorf("Unable to print key value store : %v", err) | ||
| } | ||
|
|
@@ -246,7 +246,7 @@ func printDumpingCatchpointProgressLine(progress int, barLength int, dld int64) | |
| fmt.Printf(escapeCursorUp + escapeDeleteLine + outString + "\n") | ||
| } | ||
|
|
||
| func printAccountsDatabase(databaseName string, fileHeader ledger.CatchpointFileHeader, outFile *os.File, excludeFields []string) error { | ||
| func printAccountsDatabase(databaseName string, stagingTables bool, fileHeader ledger.CatchpointFileHeader, outFile *os.File, excludeFields []string) error { | ||
| lastProgressUpdate := time.Now() | ||
| progress := uint64(0) | ||
| defer printDumpingCatchpointProgressLine(0, 0, 0) | ||
|
|
@@ -322,6 +322,9 @@ func printAccountsDatabase(databaseName string, fileHeader ledger.CatchpointFile | |
| if fileHeader.Version == 0 { | ||
| var totals ledgercore.AccountTotals | ||
| id := "" | ||
| if stagingTables { | ||
| id = "catchpointStaging" | ||
| } | ||
| row := tx.QueryRow("SELECT online, onlinerewardunits, offline, offlinerewardunits, notparticipating, notparticipatingrewardunits, rewardslevel FROM accounttotals WHERE id=?", id) | ||
| err = row.Scan(&totals.Online.Money.Raw, &totals.Online.RewardUnits, | ||
| &totals.Offline.Money.Raw, &totals.Offline.RewardUnits, | ||
|
|
@@ -339,7 +342,7 @@ func printAccountsDatabase(databaseName string, fileHeader ledger.CatchpointFile | |
|
|
||
| balancesTable := "accountbase" | ||
| resourcesTable := "resources" | ||
| if fileHeader.Version != 0 { | ||
| if stagingTables { | ||
| balancesTable = "catchpointbalances" | ||
| resourcesTable = "catchpointresources" | ||
| } | ||
|
|
@@ -365,60 +368,21 @@ func printAccountsDatabase(databaseName string, fileHeader ledger.CatchpointFile | |
| return nil | ||
| } | ||
|
|
||
| if fileHeader.Version < ledger.CatchpointFileVersionV6 { | ||
| var rows *sql.Rows | ||
| rows, err = tx.Query(fmt.Sprintf("SELECT address, data FROM %s order by address", balancesTable)) | ||
| acctCount := 0 | ||
| acctCb := func(addr basics.Address, data basics.AccountData) { | ||
| err = printer(addr, data, progress) | ||
| if err != nil { | ||
| return | ||
| } | ||
| defer rows.Close() | ||
|
|
||
| for rows.Next() { | ||
| var addrbuf []byte | ||
| var buf []byte | ||
| err = rows.Scan(&addrbuf, &buf) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
algorandskiy marked this conversation as resolved.
|
||
|
|
||
| var addr basics.Address | ||
| if len(addrbuf) != len(addr) { | ||
| err = fmt.Errorf("account DB address length mismatch: %d != %d", len(addrbuf), len(addr)) | ||
| return | ||
| } | ||
| copy(addr[:], addrbuf) | ||
|
|
||
| var data basics.AccountData | ||
| err = protocol.Decode(buf, &data) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| err = printer(addr, data, progress) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| progress++ | ||
| } | ||
| err = rows.Err() | ||
| } else { | ||
| acctCount := 0 | ||
| acctCb := func(addr basics.Address, data basics.AccountData) { | ||
| err = printer(addr, data, progress) | ||
| if err != nil { | ||
| return | ||
| } | ||
| progress++ | ||
| acctCount++ | ||
| } | ||
| _, err = ledger.LoadAllFullAccounts(context.Background(), tx, balancesTable, resourcesTable, acctCb) | ||
| if err != nil { | ||
| return | ||
| } | ||
| if acctCount != int(rowsCount) { | ||
| return fmt.Errorf("expected %d accounts but got only %d", rowsCount, acctCount) | ||
| } | ||
| progress++ | ||
| acctCount++ | ||
| } | ||
| _, err = ledger.LoadAllFullAccounts(context.Background(), tx, balancesTable, resourcesTable, acctCb) | ||
| if err != nil { | ||
| return | ||
| } | ||
| if acctCount != int(rowsCount) { | ||
| return fmt.Errorf("expected %d accounts but got only %d", rowsCount, acctCount) | ||
| } | ||
|
|
||
| // increase the deadline warning to disable the warning message. | ||
|
|
@@ -439,7 +403,7 @@ func printKeyValue(writer *bufio.Writer, key, value []byte) { | |
| fmt.Fprintf(writer, "%s : %v\n", pretty, base64.StdEncoding.EncodeToString(value)) | ||
| } | ||
|
|
||
| func printKeyValueStore(databaseName string, outFile *os.File) error { | ||
| func printKeyValueStore(databaseName string, stagingTables bool, fileHeader ledger.CatchpointFileHeader, outFile *os.File) error { | ||
|
Contributor
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. Did you just add
Contributor
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. I confirm
Contributor
Author
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. Yes, just removed it, it was left over from before I added the stagingTables arg. |
||
| fmt.Printf("\n") | ||
| printDumpingCatchpointProgressLine(0, 50, 0) | ||
| lastProgressUpdate := time.Now() | ||
|
|
@@ -454,15 +418,20 @@ func printKeyValueStore(databaseName string, outFile *os.File) error { | |
| return err | ||
| } | ||
|
|
||
| kvTable := "kvstore" | ||
| if stagingTables { | ||
| kvTable = "catchpointkvstore" | ||
| } | ||
|
|
||
| return dbAccessor.Atomic(func(ctx context.Context, tx *sql.Tx) error { | ||
| var rowsCount int64 | ||
| err := tx.QueryRow("SELECT count(*) from catchpointkvstore").Scan(&rowsCount) | ||
| err := tx.QueryRow(fmt.Sprintf("SELECT count(*) from %s", kvTable)).Scan(&rowsCount) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // ordered to make dumps more "diffable" | ||
| rows, err := tx.Query("SELECT key, value FROM catchpointkvstore order by key") | ||
| rows, err := tx.Query(fmt.Sprintf("SELECT key, value FROM %s order by key", kvTable)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
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.
Does printing the root even when
err != nilmake sense?Also, doesn't String() get called implicitly by
%s?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.
Updated