-
Notifications
You must be signed in to change notification settings - Fork 239
fix: allow reading v1.16 snapshots #861
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d6daada
fix: allow reading v1.16 snapshots
marco6 27f1650
Addressing review from Copilot
marco6 3fbcafa
Add tests for snapshot loading
marco6 1f6b815
Fix minor bug found in local testing
marco6 defcfc3
Add snapshot testsuite generation step
marco6 491102f
Limit snapshot generation to supported platforms
marco6 430e802
CI is amazing
marco6 69358e8
Handle empty tests
marco6 75312ef
Adding some more trace and logging.
marco6 a41a764
Tune down large datasets
marco6 fb26507
Addressing review
marco6 0b3dd36
End of day coding is hard
marco6 36153db
addressing review
marco6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #!/bin/sh | ||
|
|
||
| ROW_COUNT=1000 | ||
| WAL_AUTOCHECKPOINT=0 | ||
| MAIN_ONLY=0 | ||
| usage() { | ||
| cat <<USAGE | ||
| Usage: generate-snapshot.sh [--main-only] [--wal-limit <num>] [--row-count <num>] <output-dir> | ||
|
|
||
| Options: | ||
| --main-only Generate a main database only snapshot (no WAL) | ||
| --wal-limit <num> Maximum amount of WAL pages to keep (default: 0 - unbounded) | ||
| --row-count <num> Number of rows to generate (default: 1000) | ||
| -h, --help Show this help message | ||
|
|
||
| USAGE | ||
| exit 0 | ||
| } | ||
|
|
||
| # Parse arguments | ||
marco6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| while [ $# -gt 0 ]; do | ||
| case "$1" in | ||
| --main-only) | ||
| MAIN_ONLY=1 | ||
| shift 1 | ||
| ;; | ||
| --wal-limit) | ||
| if [ -z "$2" ]; then | ||
| echo "Error: --wal-limit requires a value" >&2 | ||
| usage | ||
| fi | ||
| WAL_AUTOCHECKPOINT="$2" | ||
| shift 2 | ||
| ;; | ||
| --row-count) | ||
| if [ -z "$2" ]; then | ||
| echo "Error: --row-count requires a value" >&2 | ||
| usage | ||
| fi | ||
| ROW_COUNT="$2" | ||
| shift 2 | ||
| ;; | ||
| -h|--help) | ||
| usage | ||
| ;; | ||
| *) | ||
| if [ -n "$2" ]; then | ||
| echo "Error: unknown option '$1'" >&2 | ||
| usage | ||
| fi | ||
| OUTPUT_DIR="$1" | ||
| shift 1 | ||
marco6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [ -z "$OUTPUT_DIR" ]; then | ||
| echo "Error: Missing output directory" >&2 | ||
| usage | ||
| fi | ||
|
|
||
| # Cleanup | ||
| trap 'rm -f temp temp-wal temp-shm' EXIT | ||
|
|
||
| SQLITE3_CHECKPOINT_ON_CLOSE="" | ||
| if [ "$MAIN_ONLY" -eq 0 ]; then | ||
| SQLITE3_CHECKPOINT_ON_CLOSE=".dbconfig no_ckpt_on_close on" | ||
| fi | ||
|
|
||
| # First generate a sqlite3 database | ||
| cat <<EOF | sqlite3 temp > /dev/null 2>&1 | ||
| PRAGMA journal_mode=WAL; | ||
| PRAGMA wal_autocheckpoint=$WAL_AUTOCHECKPOINT; | ||
| $SQLITE3_CHECKPOINT_ON_CLOSE | ||
|
|
||
| CREATE TABLE test(id INTEGER PRIMARY KEY, value TEXT NOT NULL); | ||
| WITH sequence AS ( | ||
marco6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SELECT 1 AS id | ||
|
|
||
| UNION ALL | ||
|
|
||
| SELECT id + 1 | ||
| FROM sequence | ||
| WHERE id < $ROW_COUNT | ||
| ) | ||
| INSERT OR REPLACE INTO test | ||
| SELECT id, hex(randomblob(16)) | ||
| FROM sequence; | ||
|
|
||
| EOF | ||
|
|
||
|
|
||
| # Now generate a dqlite snapshot from the sqlite3 database | ||
| cat <<EOF | dqlite-utils > /dev/null 2>&1 | ||
| .snapshot | ||
| .add-server "1" | ||
| ATTACH DATABASE "temp" AS test; | ||
| .finish "$OUTPUT_DIR" | ||
| EOF | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.