-
Notifications
You must be signed in to change notification settings - Fork 524
Add kvstore to catchpoints #4455
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 all commits
0c24574
0963cb3
256158e
fef9cb6
448a911
74f2617
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
| "bufio" | ||
| "context" | ||
| "database/sql" | ||
| "encoding/base64" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
|
|
@@ -34,6 +35,7 @@ import ( | |
| "github.com/algorand/go-algorand/config" | ||
| "github.com/algorand/go-algorand/data/basics" | ||
| "github.com/algorand/go-algorand/data/bookkeeping" | ||
| "github.com/algorand/go-algorand/data/transactions/logic" | ||
| "github.com/algorand/go-algorand/ledger" | ||
| "github.com/algorand/go-algorand/ledger/ledgercore" | ||
| "github.com/algorand/go-algorand/logging" | ||
|
|
@@ -128,6 +130,10 @@ var fileCmd = &cobra.Command{ | |
| if err != nil { | ||
| reportErrorf("Unable to print account database : %v", err) | ||
| } | ||
| err = printKeyValueStore("./ledger.tracker.sqlite", outFile) | ||
| if err != nil { | ||
| reportErrorf("Unable to print key value store : %v", err) | ||
| } | ||
| } | ||
| }, | ||
| } | ||
|
|
@@ -176,7 +182,7 @@ func loadCatchpointIntoDatabase(ctx context.Context, catchupAccessor ledger.Catc | |
| return fileHeader, err | ||
| } | ||
| } | ||
| err = catchupAccessor.ProgressStagingBalances(ctx, header.Name, balancesBlockBytes, &downloadProgress) | ||
| err = catchupAccessor.ProcessStagingBalances(ctx, header.Name, balancesBlockBytes, &downloadProgress) | ||
| if err != nil { | ||
| return fileHeader, err | ||
| } | ||
|
|
@@ -380,7 +386,64 @@ func printAccountsDatabase(databaseName string, fileHeader ledger.CatchpointFile | |
| } | ||
|
|
||
| // increase the deadline warning to disable the warning message. | ||
| db.ResetTransactionWarnDeadline(ctx, tx, time.Now().Add(5*time.Second)) | ||
| _, _ = db.ResetTransactionWarnDeadline(ctx, tx, time.Now().Add(5*time.Second)) | ||
tzaffi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return err | ||
| }) | ||
| } | ||
|
|
||
| func printKeyValue(writer *bufio.Writer, key, value []byte) { | ||
| var pretty string | ||
| ai, rest, err := logic.SplitBoxKey(string(key)) | ||
| if err == nil { | ||
| pretty = fmt.Sprintf("box(%d, %s)", ai, base64.StdEncoding.EncodeToString([]byte(rest))) | ||
| } else { | ||
| pretty = base64.StdEncoding.EncodeToString(key) | ||
| } | ||
|
|
||
| fmt.Fprintf(writer, "%s : %v\n", pretty, base64.StdEncoding.EncodeToString(value)) | ||
| } | ||
|
|
||
| func printKeyValueStore(databaseName string, outFile *os.File) error { | ||
| fmt.Printf("\n") | ||
| printDumpingCatchpointProgressLine(0, 50, 0) | ||
| lastProgressUpdate := time.Now() | ||
| progress := uint64(0) | ||
| defer printDumpingCatchpointProgressLine(0, 0, 0) | ||
|
|
||
| fileWriter := bufio.NewWriterSize(outFile, 1024*1024) | ||
| defer fileWriter.Flush() | ||
|
|
||
| dbAccessor, err := db.MakeAccessor(databaseName, true, false) | ||
| if err != nil || dbAccessor.Handle == nil { | ||
| return err | ||
| } | ||
|
|
||
| return dbAccessor.Atomic(func(ctx context.Context, tx *sql.Tx) error { | ||
| var rowsCount int64 | ||
| err := tx.QueryRow("SELECT count(*) from catchpointkvstore").Scan(&rowsCount) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| rows, err := tx.Query("SELECT key, value FROM catchpointkvstore") | ||
|
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. this need to be ordered. The result should be the same across all nodes
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. Is this only so that the catchpoint dump utility prints in the same order? I want to check my understanding that the catchpoint files don't actually need to be identical (down to the level of ordering) for any other reason. All that matters for their use that they produce the same merkle trie, which is order independent. (I think.) I'll certainly make the change, but I want to be sure I know what's going on.
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. Oh! This is actually in the catchpoint dump utility! So certainly we're talking about the same reason. So now, just to be extra safe, can you confirm that the similar SELECT, in |
||
| if err != nil { | ||
| return err | ||
| } | ||
| defer rows.Close() | ||
| for rows.Next() { | ||
| progress++ | ||
| var key []byte | ||
| var value []byte | ||
| err := rows.Scan(&key, &value) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| printKeyValue(fileWriter, key, value) | ||
| if time.Since(lastProgressUpdate) > 50*time.Millisecond { | ||
| lastProgressUpdate = time.Now() | ||
| printDumpingCatchpointProgressLine(int(float64(progress)*50.0/float64(rowsCount)), 50, int64(progress)) | ||
| } | ||
| } | ||
| return nil | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.