forked from wal-g/wal-g
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add partial restore for Greenplum (wal-g#1489)
* Add partial restore for Greenplum * fix interface * fix style * naive try * always restore aoseg tables * little optimization: skip aoseg table for skipped database * always set skipRedundatTars to true * rebasing master * add test for aovisimap * fixes * remove embedding impl And move FilterFilesToUnwrap function to RestoreDesc struct * move RestoreDescMaker into private field
- Loading branch information
Showing
12 changed files
with
362 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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 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 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
2 changes: 2 additions & 0 deletions
2
docker/gp_tests/scripts/configs/partial_database_restore_test_config.json
This file contains 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,2 @@ | ||
"WALE_S3_PREFIX": "s3://gppartialdatabasebucket", | ||
"WALG_DELTA_MAX_STEPS": "2" |
3 changes: 3 additions & 0 deletions
3
docker/gp_tests/scripts/configs/partial_table_restore_test_config.json
This file contains 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,3 @@ | ||
"WALE_S3_PREFIX": "s3://gppartialtablebucket", | ||
"WALG_DELTA_MAX_STEPS": "2", | ||
"WALG_LOG_LEVEL": "DEVEL" |
78 changes: 78 additions & 0 deletions
78
docker/gp_tests/scripts/tests/partial_database_restore_test.sh
This file contains 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,78 @@ | ||
#!/bin/bash | ||
set -e -x | ||
|
||
CONFIG_FILE="/tmp/configs/partial_database_restore_test_config.json" | ||
COMMON_CONFIG="/tmp/configs/common_config.json" | ||
TMP_CONFIG="/tmp/configs/tmp_config.json" | ||
cat ${CONFIG_FILE} > ${TMP_CONFIG} | ||
echo "," >> ${TMP_CONFIG} | ||
cat ${COMMON_CONFIG} >> ${TMP_CONFIG} | ||
/tmp/pg_scripts/wrap_config_file.sh ${TMP_CONFIG} | ||
source /tmp/tests/test_functions/util.sh | ||
|
||
wal-g --config=${TMP_CONFIG} delete everything FORCE --confirm | ||
|
||
bootstrap_gp_cluster | ||
sleep 3 | ||
enable_pitr_extension | ||
setup_wal_archiving | ||
|
||
# insert_data | ||
psql -p 6000 -c "DROP DATABASE IF EXISTS to_restore" | ||
psql -p 6000 -c "CREATE DATABASE to_restore" | ||
psql -p 6000 -d to_restore -c "CREATE TABLE heap AS SELECT a FROM generate_series(1,2) AS a;" | ||
psql -p 6000 -d to_restore -c "CREATE TABLE ao(a int, b int) WITH (appendoptimized = true) DISTRIBUTED BY (a);" | ||
psql -p 6000 -d to_restore -c "CREATE TABLE co(a int, b int) WITH (appendoptimized = true, orientation = column) DISTRIBUTED BY (a);" | ||
psql -p 6000 -d to_restore -c "INSERT INTO ao select i, i FROM generate_series(1,2)i;" | ||
psql -p 6000 -d to_restore -c "INSERT INTO co select i, i FROM generate_series(1,2)i;" | ||
|
||
psql -p 6000 -c "DROP DATABASE IF EXISTS to_skip" | ||
psql -p 6000 -c "CREATE DATABASE to_skip" | ||
psql -p 6000 -d to_skip -c "CREATE TABLE heap AS SELECT a FROM generate_series(1,2) AS a;" | ||
psql -p 6000 -d to_skip -c "CREATE TABLE ao(a int, b int) WITH (appendoptimized = true) DISTRIBUTED BY (a);" | ||
psql -p 6000 -d to_skip -c "CREATE TABLE co(a int, b int) WITH (appendoptimized = true, orientation = column) DISTRIBUTED BY (a);" | ||
psql -p 6000 -d to_skip -c "INSERT INTO ao select i, i FROM generate_series(1,2)i;" | ||
psql -p 6000 -d to_skip -c "INSERT INTO co select i, i FROM generate_series(1,2)i;" | ||
|
||
run_backup_logged ${TMP_CONFIG} ${PGDATA} | ||
|
||
psql -p 6000 -d to_restore -c "INSERT INTO heap select i FROM generate_series(3,4)i;" | ||
psql -p 6000 -d to_restore -c "INSERT INTO ao select i, i FROM generate_series(3,4)i;" | ||
psql -p 6000 -d to_restore -c "INSERT INTO co select i, i FROM generate_series(3,4)i;" | ||
|
||
psql -p 6000 -d to_skip -c "INSERT INTO heap select i FROM generate_series(3,4)i;" | ||
psql -p 6000 -d to_skip -c "INSERT INTO ao select i, i FROM generate_series(3,4)i;" | ||
psql -p 6000 -d to_skip -c "INSERT INTO co select i, i FROM generate_series(3,4)i;" | ||
|
||
stop_and_delete_cluster_dir | ||
|
||
wal-g --config=${TMP_CONFIG} backup-fetch ${PGDATA} LATEST --in-place --restore-only=to_restore | ||
|
||
start_cluster | ||
|
||
if [ "$(psql -p 6000 -t -c "select a from heap order by a;" -d to_restore -A)" != "$(printf '1\n2')" ]; then | ||
echo "Error: Heap table in to_restore database must be restored after partial fetch" | ||
exit 1 | ||
elif [ "$(psql -p 6000 -t -c "select a, b from ao order by a, b;" -d to_restore -A)" != "$(printf '1|1\n2|2')" ]; then | ||
echo "Error: Append optimized table in to_restore database must be restored after partial fetch" | ||
exit 1 | ||
elif [ "$(psql -p 6000 -t -c "select a, b from co order by a, b;" -d to_restore -A)" != "$(printf '1|1\n2|2')" ]; then | ||
echo "Error: Column oriented table in to_restore database must be restored after partial fetch" | ||
exit 1 | ||
fi | ||
|
||
if ! psql -p 6000 -t -c "select a from heap order by a;" -d to_skip -A 2>&1 | grep -q "is not a valid data directory"; then | ||
echo "Error: to_skip database directory must be emtpy after partial fetch" | ||
echo "$(psql -p 6000 -t -c "select a from heap order by a;" -d to_skip -A)" | ||
exit 1 | ||
elif ! psql -p 6000 -t -c "select a, b from ao order by a, b;" -d to_skip -A 2>&1 | grep "is not a valid data directory"; then | ||
echo "Error: to_skip database directory must be emtpy after partial fetch" | ||
echo "$(psql -p 6000 -t -c "select a, b from ao order by a, b;" -d to_skip -A)" | ||
exit 1 | ||
elif ! psql -p 6000 -t -c "select a, b from co order by a, b;" -d to_skip -A 2>&1 | grep "is not a valid data directory"; then | ||
echo "Error: to_skip database directory must be emtpy after partial fetch" | ||
echo "$(psql -p 6000 -t -c "select a, b from co order by a, b;" -d to_skip -A)" | ||
exit 1 | ||
fi | ||
|
||
cleanup |
100 changes: 100 additions & 0 deletions
100
docker/gp_tests/scripts/tests/partial_table_restore_test.sh
This file contains 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,100 @@ | ||
#!/bin/bash | ||
set -e -x | ||
|
||
CONFIG_FILE="/tmp/configs/partial_table_restore_test_config.json" | ||
COMMON_CONFIG="/tmp/configs/common_config.json" | ||
TMP_CONFIG="/tmp/configs/tmp_config.json" | ||
cat ${CONFIG_FILE} > ${TMP_CONFIG} | ||
echo "," >> ${TMP_CONFIG} | ||
cat ${COMMON_CONFIG} >> ${TMP_CONFIG} | ||
/tmp/pg_scripts/wrap_config_file.sh ${TMP_CONFIG} | ||
source /tmp/tests/test_functions/util.sh | ||
|
||
wal-g --config=${TMP_CONFIG} delete everything FORCE --confirm | ||
|
||
bootstrap_gp_cluster | ||
sleep 3 | ||
enable_pitr_extension | ||
setup_wal_archiving | ||
|
||
# insert_data | ||
n=10000 | ||
it=10 | ||
expected_count=$(($n + $it * 5)) | ||
|
||
psql -p 6000 -c "DROP DATABASE IF EXISTS db" | ||
psql -p 6000 -c "CREATE DATABASE db" | ||
psql -p 6000 -d db -c "CREATE TABLE heap_to_restore AS SELECT a FROM generate_series(1,$n) AS a;" | ||
psql -p 6000 -d db -c "CREATE TABLE heap_to_skip AS SELECT a FROM generate_series(1,$n) AS a;" | ||
psql -p 6000 -d db -c "CREATE TABLE ao_to_restore(a int, b int) WITH (appendoptimized = true) DISTRIBUTED BY (a);" | ||
psql -p 6000 -d db -c "CREATE TABLE ao_to_skip(a int, b int) WITH (appendoptimized = true) DISTRIBUTED BY (a);" | ||
psql -p 6000 -d db -c "CREATE TABLE co_to_restore(a int, b int) WITH (appendoptimized = true, orientation = column) DISTRIBUTED BY (a);" | ||
psql -p 6000 -d db -c "CREATE TABLE co_to_skip(a int, b int) WITH (appendoptimized = true, orientation = column) DISTRIBUTED BY (a);" | ||
psql -p 6000 -d db -c "INSERT INTO ao_to_restore SELECT i, i FROM generate_series(1,$n)i;" | ||
psql -p 6000 -d db -c "INSERT INTO ao_to_skip SELECT i, i FROM generate_series(1,$n)i;" | ||
psql -p 6000 -d db -c "INSERT INTO co_to_restore SELECT i, i FROM generate_series(1,$n)i;" | ||
psql -p 6000 -d db -c "INSERT INTO co_to_skip SELECT i, i FROM generate_series(1,$n)i;" | ||
|
||
# check aovisimap | ||
insert_10_delete_5() { | ||
start_val=$1 | ||
stop_val=$(($start_val + 9)) | ||
stop_val_d=$(($start_val + 4)) | ||
psql -p 6000 -d db -c "INSERT INTO ao_to_restore SELECT i, i FROM generate_series($start_val,$stop_val)i;" | ||
psql -p 6000 -d db -c "INSERT INTO ao_to_skip SELECT i, i FROM generate_series($start_val,$stop_val)i;" | ||
psql -p 6000 -d db -c "INSERT INTO co_to_restore SELECT i, i FROM generate_series($start_val,$stop_val)i;" | ||
psql -p 6000 -d db -c "INSERT INTO co_to_skip SELECT i, i FROM generate_series($start_val,$stop_val)i;" | ||
|
||
psql -p 6000 -d db -c "DELETE FROM ao_to_restore WHERE a >= $start_val and a <= $stop_val_d;" | ||
psql -p 6000 -d db -c "DELETE FROM ao_to_skip WHERE a >= $start_val and a <= $stop_val_d;" | ||
psql -p 6000 -d db -c "DELETE FROM co_to_restore WHERE a >= $start_val and a <= $stop_val_d;" | ||
psql -p 6000 -d db -c "DELETE FROM co_to_skip WHERE a >= $start_val and a <= $stop_val_d;" | ||
} | ||
|
||
for i in $(seq 1 $it); | ||
do | ||
insert_10_delete_5 $(($n + 1 + 10*($i-1))) | ||
done | ||
|
||
run_backup_logged ${TMP_CONFIG} ${PGDATA} | ||
stop_and_delete_cluster_dir | ||
|
||
wal-g --config=${TMP_CONFIG} backup-fetch LATEST --in-place --restore-only=db/heap_to_restore,db/ao_to_restore,db/co_to_restore | ||
|
||
start_cluster | ||
|
||
if [ "$(psql -p 6000 -t -c "SELECT count(*) FROM heap_to_restore;" -d db -A)" != $n ]; then | ||
echo "Error: Heap table in db database must be restored after partial fetch" | ||
exit 1 | ||
elif [ "$(psql -p 6000 -t -c "SELECT count(*) FROM ao_to_restore;" -d db -A)" != $expected_count ]; then | ||
echo "Error: Append optimized table in db database must be restored after partial fetch" | ||
exit 1 | ||
elif [ "$(psql -p 6000 -t -c "SELECT count(*) FROM co_to_restore;" -d db -A)" != $expected_count ]; then | ||
echo "Error: Column oriented table in db database must be restored after partial fetch" | ||
exit 1 | ||
fi | ||
|
||
EXPECTED_HEAP_ERROR_MSG="could not open file" | ||
EXPECTED_AO_ERROR_MSG="append-Only storage read could not open segment file" | ||
|
||
set +e | ||
heap_output=$(psql -p 6000 -t -c "SELECT count(*) FROM heap_to_skip;" -d db -A 2>&1) | ||
ao_output=$(psql -p 6000 -t -c "SELECT count(*) FROM ao_to_skip;" -d db -A 2>&1) | ||
aocs_output=$(psql -p 6000 -t -c "SELECT count(*) FROM co_to_skip;" -d db -A 2>&1) | ||
set -e | ||
|
||
if ! echo $heap_output | grep -q "$EXPECTED_HEAP_ERROR_MSG"; then | ||
echo "Error: to_skip database directory must be emtpy after partial fetch" | ||
echo $heap_output | ||
exit 1 | ||
elif ! echo $ao_output | grep -q "$EXPECTED_AO_ERROR_MSG"; then | ||
echo "Error: to_skip database directory must be emtpy after partial fetch" | ||
echo $ao_output | ||
exit 1 | ||
elif ! echo $aocs_output | grep -q "$EXPECTED_AO_ERROR_MSG"; then | ||
echo "Error: to_skip database directory must be emtpy after partial fetch" | ||
echo $aocs_output | ||
exit 1 | ||
fi | ||
|
||
cleanup |
This file contains 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 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.