@@ -1341,7 +1341,7 @@ function verify_revconn_fix
13411341{
13421342 logFile=$TESTDIR /logs/${REPL_DBNAME_PREFIX} _${firstNode} .log
13431343 x=$( egrep " Reverse connected" $logFile | wc -l)
1344- if [[ " $x " -gt 80 ]]; then
1344+ if [[ " $x " -gt 90 ]]; then
13451345 cleanFailExit " Reverse connection loop in $logFile "
13461346 fi
13471347}
@@ -1396,6 +1396,135 @@ function match_overlap
13961396 return 0
13971397}
13981398
1399+ function physrep_truncate
1400+ {
1401+ local mnode=` getmaster`
1402+ local startlsn=$( $CDB2SQL_EXE $CDB2_OPTIONS --tabs $DBNAME --host $mnode " select lsn from comdb2_transaction_logs(NULL, NULL, 4) limit 1" )
1403+ echo " Create table"
1404+ $CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default " create table cktruncate(a int, b cstring(32))"
1405+ $CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default " insert into cktruncate select *, 'good' from generate_series(1, 1000)"
1406+
1407+ # Block until all standalones have these records
1408+ for node in $CLUSTER ; do
1409+ name=" ${REPL_DBNAME_PREFIX} _${node} "
1410+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" )
1411+ while [[ " $x " -ne " 1000" ]]; do
1412+ sleep 1
1413+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" )
1414+ done
1415+ echo " Db $name on node $node has caught up"
1416+ done
1417+
1418+ # Block until clustered physrep has these records
1419+ name=" ${REPL_CLUS_DBNAME} "
1420+ for node in $CLUSTER ; do
1421+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" )
1422+ while [[ " $x " -ne " 1000" ]]; do
1423+ sleep 1
1424+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" 2> /dev/null)
1425+ done
1426+ echo " Db $name on node $node has caught up"
1427+ done
1428+
1429+ echo " Retrieve 'good' LSN"
1430+ local goodlsn=$( $CDB2SQL_EXE $CDB2_OPTIONS --tabs $DBNAME --host $mnode " select lsn from comdb2_transaction_logs(NULL, NULL, 4) limit 1" )
1431+
1432+ echo " Insert 'bad' data"
1433+ $CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default " insert into cktruncate select *, 'bad' from generate_series(1, 1000)"
1434+
1435+ # Block until all standalones have these records
1436+ for node in $CLUSTER ; do
1437+ name=" ${REPL_DBNAME_PREFIX} _${node} "
1438+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate where b = 'bad'" 2> /dev/null)
1439+ while [[ " $x " -ne " 1000" ]]; do
1440+ sleep 1
1441+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate where b = 'bad'" 2> /dev/null)
1442+ done
1443+ echo " Db $name on node $node has caught up"
1444+ done
1445+
1446+ # Block until clustered physrep has these records
1447+ # name=${REPL_CLUS_DBNAME}
1448+ name=" ${REPL_CLUS_DBNAME} "
1449+ for node in $CLUSTER ; do
1450+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate where b = 'bad'" 2> /dev/null)
1451+ while [[ " $x " -ne " 1000" ]]; do
1452+ sleep 1
1453+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate where b = 'bad'" 2> /dev/null)
1454+ done
1455+ echo " Db $name on node $node has caught up"
1456+ done
1457+
1458+ echo " Truncate to good LSN $goodlsn "
1459+ $CDB2SQL_EXE $CDB2_OPTIONS $DBNAME --host $mnode " exec procedure sys.cmd.truncate_log(\" $goodlsn \" )"
1460+ r=$?
1461+ while [[ " $r " -ne " 0" ]]; do
1462+ echo " Truncate returned a bad rcode $r , retrying"
1463+ sleep 1
1464+ $CDB2SQL_EXE $CDB2_OPTIONS $DBNAME --host $mnode " exec procedure sys.cmd.truncate_log(\" $goodlsn \" )"
1465+ r=$?
1466+ done
1467+
1468+ sleep 5
1469+ echo " Verify that truncate succeeded - there should be 1000 records"
1470+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" 2> /dev/null)
1471+ while [[ " $x " -ne " 1000" ]]; do
1472+ sleep 1
1473+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" 2> /dev/null)
1474+ done
1475+
1476+ echo " Block until standalone physreps have truncated"
1477+ # Block until all standalones have truncated
1478+ for node in $CLUSTER ; do
1479+ name=" ${REPL_DBNAME_PREFIX} _${node} "
1480+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" 2> /dev/null)
1481+ while [[ " $x " -ne " 1000" ]]; do
1482+ sleep 1
1483+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" 2> /dev/null)
1484+ done
1485+ echo " Db $name on node $node has caught up"
1486+ done
1487+
1488+ # Block until clustered physrep has truncated
1489+ echo " Block until clustered physrep has truncated"
1490+ name=" ${REPL_CLUS_DBNAME} "
1491+ for node in $CLUSTER ; do
1492+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" 2> /dev/null)
1493+ while [[ " $x " -ne " 1000" ]]; do
1494+ sleep 1
1495+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from cktruncate" 2> /dev/null)
1496+ done
1497+ echo " Db $name on node $node has caught up"
1498+ done
1499+
1500+ echo " Drop table"
1501+ $CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default " drop table cktruncate"
1502+
1503+ echo " Block until standalone physreps have dropped table"
1504+ # Block until all standalones have truncated
1505+ for node in $CLUSTER ; do
1506+ name=" ${REPL_DBNAME_PREFIX} _${node} "
1507+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from comdb2_tables where tablename = 'cktruncate'" 2> /dev/null)
1508+ while [[ " $x " -ne " 0" ]]; do
1509+ sleep 1
1510+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from comdb2_tables where tablename = 'cktruncate'" 2> /dev/null)
1511+ done
1512+ echo " Db $name on node $node has caught up"
1513+ done
1514+
1515+ # Block until clustered physrep has truncated
1516+ echo " Block until clustered physrep has truncated"
1517+ name=" ${REPL_CLUS_DBNAME} "
1518+ for node in $CLUSTER ; do
1519+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from comdb2_tables where tablename = 'cktruncate'" 2> /dev/null)
1520+ while [[ " $x " -ne " 0" ]]; do
1521+ sleep 1
1522+ x=$( $CDB2SQL_EXE --tabs ${CDB2_OPTIONS} --host $node $name " select count(*) from comdb2_tables where tablename = 'cktruncate'" 2> /dev/null)
1523+ done
1524+ echo " Db $name on node $node has caught up"
1525+ done
1526+ }
1527+
13991528# Verify that we are showing generation in comdb2-transaction-logs
14001529function verify_generation
14011530{
@@ -1852,6 +1981,11 @@ function run_tests
18521981 verify_revconn_fix
18531982 testcase_finish $testcase
18541983
1984+ testcase=" physrep_truncate"
1985+ testcase_preamble $testcase
1986+ physrep_truncate
1987+ testcase_finish $testcase
1988+
18551989 testcase=" multimeta"
18561990 testcase_preamble $testcase
18571991 multimetadb
0 commit comments