|
| 1 | +#!/usr/bin/env bash |
| 2 | +bash -n "$0" | exit 1 |
| 3 | + |
| 4 | +# This test demonstrates a case where ufid_hash would hold an open |
| 5 | +# DB handle to an outdated btree file, after schema change, hence prevent |
| 6 | +# the file from being deleted. |
| 7 | +# |
| 8 | +# 1. send flush |
| 9 | +# 2. write to table |
| 10 | +# 3. bounce a replicant |
| 11 | +# 3.1. replicant will start matching from the LSN in step 1 |
| 12 | +# 3.2. replicant will run recovery to apply transaction from step 2 |
| 13 | +# 3.3. ufid-hash will need to open a DB handle on the btree file |
| 14 | +# 4. truncate table, this creates new btree file |
| 15 | +# 5. delfiles now will create "deleted" file on this replicant; |
| 16 | +# alternatively, if we upgrade master to this replicant and then run delfiles, |
| 17 | +# we'll get "DB_FILEOPEN: Rename or remove while file is open" |
| 18 | + |
| 19 | +source ${TESTSROOTDIR}/tools/cluster_utils.sh |
| 20 | + |
| 21 | +[ -z "${CLUSTER}" ] && { echo "Test requires a cluster"; exit 0; } |
| 22 | + |
| 23 | +dbnm=$1 |
| 24 | + |
| 25 | +replicant=`cdb2sql --tabs ${CDB2_OPTIONS} $dbnm default "select comdb2_host()"` |
| 26 | +master=`cdb2sql --tabs ${CDB2_OPTIONS} $dbnm default "select host from comdb2_cluster where is_master='Y'"` |
| 27 | + |
| 28 | +cdb2sql ${CDB2_OPTIONS} $dbnm default "CREATE TABLE t1 (i integer, b blob)" |
| 29 | +sleep 2 # wait for the checkpoint thread to do its 1st checkpoint |
| 30 | +cdb2sql $dbnm --host $master "EXEC PROCEDURE sys.cmd.send('bdb checkpoint')" |
| 31 | +sleep 2 # wait for the async checkpoint to finish |
| 32 | + |
| 33 | +cdb2sql ${CDB2_OPTIONS} $dbnm default "TRUNCATE TABLE t1" |
| 34 | +cdb2sql $dbnm --host $master "EXEC PROCEDURE sys.cmd.send('bdb checkpoint')" |
| 35 | +sleep 2 # wait for the async checkpoint to finish |
| 36 | + |
| 37 | +cdb2sql ${CDB2_OPTIONS} $dbnm default "INSERT INTO t1 VALUES(1, x'CDB2BABE')" |
| 38 | +sleep 2 |
| 39 | + |
| 40 | +echo "Restarting node $replicant ..." |
| 41 | +kill_restart_node $replicant 10 1 |
| 42 | +cdb2sql $dbnm --host $replicant "SELECT 1" |
| 43 | +if [ $? -ne 0 ]; then |
| 44 | + echo 'db not up?' >&2 |
| 45 | + exit 1 |
| 46 | +fi |
| 47 | + |
| 48 | +echo 'Before truncate ...' |
| 49 | +cdb2sql $dbnm --host $replicant "EXEC PROCEDURE sys.cmd.send('bdb cachestatall')" | grep -A1 blobs0 |
| 50 | +cdb2sql $dbnm --host $master "TRUNCATE TABLE t1" |
| 51 | +echo 'After truncate ...' |
| 52 | +cdb2sql $dbnm --host $replicant "EXEC PROCEDURE sys.cmd.send('bdb cachestatall')" | grep -A1 blobs0 |
| 53 | + |
| 54 | +echo "Waiting for $replicant to become new master" |
| 55 | +while true; do |
| 56 | + is_replicant_new_master=`cdb2sql --tabs $dbnm --host $replicant "SELECT comdb2_host() = (select host from comdb2_cluster where is_master='Y')"` |
| 57 | + if [ "$is_replicant_new_master" = "1" ]; then |
| 58 | + master=$replicant |
| 59 | + break |
| 60 | + fi |
| 61 | + |
| 62 | + master=`cdb2sql --tabs ${CDB2_OPTIONS} $dbnm default "select host from comdb2_cluster where is_master='Y'"` |
| 63 | + cdb2sql $dbnm --host $master "EXEC PROCEDURE sys.cmd.send('upgrade $replicant')" |
| 64 | + sleep 5 |
| 65 | + master=`cdb2sql --tabs ${CDB2_OPTIONS} $dbnm default "select host from comdb2_cluster where is_master='Y'"` |
| 66 | + echo "Master swung to $master" |
| 67 | + |
| 68 | + while true; do |
| 69 | + cdb2sql $dbnm --host $replicant "SELECT 1" >/dev/null |
| 70 | + if [ $? -eq 0 ]; then |
| 71 | + break; |
| 72 | + fi |
| 73 | + sleep 1 |
| 74 | + done |
| 75 | +done |
| 76 | + |
| 77 | +cdb2sql -tabs $dbnm --host $master "EXEC PROCEDURE sys.cmd.send('delfiles t1')" | grep 'DB_FILEOPEN: Rename or remove while file is open' |
| 78 | +if [ $? -eq 0 ]; then |
| 79 | + echo "DB handles leaked" >&2 |
| 80 | + exit 1 |
| 81 | +fi |
| 82 | + |
| 83 | +echo "Success!" |
| 84 | +exit 0 |
0 commit comments