Refactor Restore()

This commit refactors out the complexity of downloading ordered WAL
files in parallel to a type called `WALDownloader`. This makes it
easier to test the restore separately from the download.
This commit is contained in:
Ben Johnson
2022-01-04 14:47:11 -07:00
parent 531e19ed6f
commit 3f0ec9fa9f
130 changed files with 2943 additions and 1254 deletions

8
testdata/Makefile vendored Normal file
View File

@@ -0,0 +1,8 @@
.PHONY: default
default:
make -C find-latest-generation/ok
make -C generation-time-bounds/ok
make -C generation-time-bounds/snapshots-only
make -C replica-client-time-bounds/ok
make -C snapshot-time-bounds/ok
make -C wal-time-bounds/ok

View File

@@ -0,0 +1,7 @@
.PHONY: default
default:
TZ=UTC touch -t 200001010000 generations/0000000000000000/snapshots/00000000.snapshot.lz4
TZ=UTC touch -t 200001020000 generations/0000000000000000/snapshots/00000001.snapshot.lz4
TZ=UTC touch -t 200001010000 generations/0000000000000001/snapshots/00000000.snapshot.lz4
TZ=UTC touch -t 200001030000 generations/0000000000000001/snapshots/00000001.snapshot.lz4
TZ=UTC touch -t 200001010000 generations/0000000000000002/snapshots/00000000.snapshot.lz4

View File

@@ -0,0 +1,8 @@
.PHONY: default
default:
TZ=UTC touch -t 200001010000 generations/0000000000000000/snapshots/00000000.snapshot.lz4
TZ=UTC touch -t 200001020000 generations/0000000000000000/snapshots/00000001.snapshot.lz4
TZ=UTC touch -t 200001010000 generations/0000000000000000/wal/00000000/00000000.wal.lz4
TZ=UTC touch -t 200001020000 generations/0000000000000000/wal/00000000/00000001.wal.lz4
TZ=UTC touch -t 200001030000 generations/0000000000000000/wal/00000001/00000000.wal.lz4

View File

@@ -0,0 +1,5 @@
.PHONY: default
default:
TZ=UTC touch -t 200001010000 generations/0000000000000000/snapshots/00000000.snapshot.lz4
TZ=UTC touch -t 200001020000 generations/0000000000000000/snapshots/00000001.snapshot.lz4

View File

@@ -0,0 +1,6 @@
.PHONY: default
default:
TZ=UTC touch -t 200001020000 generations/0000000000000000/snapshots/00000000.snapshot.lz4
TZ=UTC touch -t 200001010000 generations/0000000000000001/snapshots/00000000.snapshot.lz4
TZ=UTC touch -t 200001030000 generations/0000000000000001/snapshots/00000001.snapshot.lz4
TZ=UTC touch -t 200001010000 generations/0000000000000002/snapshots/00000000.snapshot.lz4

View File

@@ -0,0 +1,6 @@
.PHONY: default
default:
TZ=UTC touch -t 200001020000 generations/0000000000000000/snapshots/00000000.snapshot.lz4
TZ=UTC touch -t 200001010000 generations/0000000000000001/snapshots/00000000.snapshot.lz4
TZ=UTC touch -t 200001030000 generations/0000000000000001/snapshots/00000001.snapshot.lz4
TZ=UTC touch -t 200001010000 generations/0000000000000002/snapshots/00000000.snapshot.lz4

Binary file not shown.

36
testdata/restore/bad-permissions/README vendored Normal file
View File

@@ -0,0 +1,36 @@
To reproduce this testdata, run sqlite3 and execute:
PRAGMA journal_mode = WAL;
CREATE TABLE t (x);
INSERT INTO t (x) VALUES (1);
INSERT INTO t (x) VALUES (2);
sl3 split -o generations/0000000000000000/wal/00000000 db-wal
cp db generations/0000000000000000/snapshots/00000000.snapshot
lz4 -c --rm generations/0000000000000000/snapshots/00000000.snapshot
Then execute:
PRAGMA wal_checkpoint(TRUNCATE);
INSERT INTO t (x) VALUES (3);
sl3 split -o generations/0000000000000000/wal/00000001 db-wal
Then execute:
PRAGMA wal_checkpoint(TRUNCATE);
INSERT INTO t (x) VALUES (4);
INSERT INTO t (x) VALUES (5);
sl3 split -o generations/0000000000000000/wal/00000002 db-wal
Finally, obtain the final snapshot:
PRAGMA wal_checkpoint(TRUNCATE);
cp db 00000002.db
rm db*

BIN
testdata/restore/ok/00000002.db vendored Normal file

Binary file not shown.

36
testdata/restore/ok/README vendored Normal file
View File

@@ -0,0 +1,36 @@
To reproduce this testdata, run sqlite3 and execute:
PRAGMA journal_mode = WAL;
CREATE TABLE t (x);
INSERT INTO t (x) VALUES (1);
INSERT INTO t (x) VALUES (2);
sl3 split -o generations/0000000000000000/wal/00000000 db-wal
cp db generations/0000000000000000/snapshots/00000000.snapshot
lz4 -c --rm generations/0000000000000000/snapshots/00000000.snapshot
Then execute:
PRAGMA wal_checkpoint(TRUNCATE);
INSERT INTO t (x) VALUES (3);
sl3 split -o generations/0000000000000000/wal/00000001 db-wal
Then execute:
PRAGMA wal_checkpoint(TRUNCATE);
INSERT INTO t (x) VALUES (4);
INSERT INTO t (x) VALUES (5);
sl3 split -o generations/0000000000000000/wal/00000002 db-wal
Finally, obtain the final snapshot:
PRAGMA wal_checkpoint(TRUNCATE);
cp db 00000002.db
rm db*

Binary file not shown.

View File

@@ -0,0 +1,6 @@
.PHONY: default
default:
TZ=UTC touch -t 200001010000 generations/0000000000000000/snapshots/00000000.snapshot.lz4
TZ=UTC touch -t 200001020000 generations/0000000000000000/snapshots/00000001.snapshot.lz4
TZ=UTC touch -t 200001030000 generations/0000000000000000/snapshots/00000002.snapshot.lz4

BIN
testdata/wal-downloader/ok/00000000.wal vendored Normal file

Binary file not shown.

BIN
testdata/wal-downloader/ok/00000001.wal vendored Normal file

Binary file not shown.

BIN
testdata/wal-downloader/ok/00000002.wal vendored Normal file

Binary file not shown.

40
testdata/wal-downloader/ok/README vendored Normal file
View File

@@ -0,0 +1,40 @@
To reproduce this testdata, run sqlite3 and execute:
PRAGMA journal_mode = WAL;
CREATE TABLE t (x);
INSERT INTO t (x) VALUES (1);
INSERT INTO t (x) VALUES (2);
And copy & split the WAL into segments:
sl3 split -o generations/0000000000000000/wal/00000000 db-wal
cp db-wal 00000000.wal
Then execute:
PRAGMA wal_checkpoint(TRUNCATE);
INSERT INTO t (x) VALUES (3);
And split again:
sl3 split -o generations/0000000000000000/wal/00000001 db-wal
cp db-wal 00000001.wal
Then execute:
PRAGMA wal_checkpoint(TRUNCATE);
INSERT INTO t (x) VALUES (4);
INSERT INTO t (x) VALUES (5);
And split again:
sl3 split -o generations/0000000000000000/wal/00000002 db-wal
cp db-wal 00000002.wal
Finally, remove the original database files:
rm db*

BIN
testdata/wal-downloader/one/00000000.wal vendored Normal file

Binary file not shown.

17
testdata/wal-downloader/one/README vendored Normal file
View File

@@ -0,0 +1,17 @@
To reproduce this testdata, run sqlite3 and execute:
PRAGMA journal_mode = WAL;
CREATE TABLE t (x);
INSERT INTO t (x) VALUES (1);
INSERT INTO t (x) VALUES (2);
And copy & split the WAL into segments:
sl3 split -o generations/0000000000000000/wal/00000000 db-wal
cp db-wal 00000000.wal
Finally, remove the original database files:
rm db*

Some files were not shown because too many files have changed in this diff Show More