Skip to content
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

Add atomic truncate test #4738

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions berkdb/env/env_recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ extern int __txn_commit_map_get(DB_ENV *, u_int64_t, DB_LSN*);
#include <bdbglue.h>
extern int gbl_is_physical_replicant;
int gbl_apprec_gen;
int gbl_debug_sleep_during_truncate = 0;

#else

Expand Down Expand Up @@ -1367,6 +1368,9 @@ __db_apprec(dbenv, max_lsn, trunclsn, update, flags)

log_recovery_progress(1, -1);
dbenv->recovery_pass = DB_TXN_BACKWARD_ROLL;
if (trunclsn && gbl_debug_sleep_during_truncate) {
sleep(5);
}

/*
* Pass #2.
Expand Down
1 change: 1 addition & 0 deletions db/db_tunables.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ extern int gbl_debug_sleep_coordinator_before_commit;
extern int gbl_debug_sleep_on_set_read_only;
extern int gbl_debug_wait_on_verify_off;
extern int gbl_debug_disttxn_trace;
extern int gbl_debug_sleep_during_truncate;
extern int gbl_sparse_lockerid_map;
extern int gbl_spstrictassignments;
extern int gbl_early;
Expand Down
3 changes: 3 additions & 0 deletions db/db_tunables.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ REGISTER_TUNABLE("debug_sleep_coordinator_before_commit", "Coordinator sleeps be
REGISTER_TUNABLE("debug_coordinator_dispatch_failure", "Fake failed dispatch in coordinator. (Default: off)",
TUNABLE_BOOLEAN, &gbl_debug_coordinator_dispatch_failure, EXPERIMENTAL | INTERNAL, NULL, NULL, NULL,
NULL);
REGISTER_TUNABLE("debug_sleep_during_truncate", "Sleeps during the backward pass of a truncate. (Default: off)",
TUNABLE_BOOLEAN, &gbl_debug_sleep_during_truncate, EXPERIMENTAL | INTERNAL, NULL, NULL, NULL,
NULL);
REGISTER_TUNABLE("debug_sleep_on_set_read_only", "Sleep before setting to readonly. (Default: off)", TUNABLE_BOOLEAN,
&gbl_debug_sleep_on_set_read_only, EXPERIMENTAL | INTERNAL, NULL, NULL, NULL, NULL);
REGISTER_TUNABLE("debug_wait_on_verify_off", "Wait for particpant when verify is disabled. (Default: off)",
Expand Down
8 changes: 8 additions & 0 deletions tests/atomic_truncate.test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ifeq ($(TESTSROOTDIR),)
include ../testcase.mk
else
include $(TESTSROOTDIR)/testcase.mk
endif
ifeq ($(TEST_TIMEOUT),)
export TEST_TIMEOUT=5m
endif
1 change: 1 addition & 0 deletions tests/atomic_truncate.test/lrl.options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debug_sleep_truncate on
48 changes: 48 additions & 0 deletions tests/atomic_truncate.test/runit
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
bash -n "$0" | exit 1

TIER="default"

query_replicant_in_loop() {
set +e

local prev_count=-1
while true;
do
local count
count=$(cdb2sql -tabs ${CDB2_OPTIONS} "${DBNAME}" "${TIER}" "select count(*) from t")
if (( $? ));
then
exit 0
elif (( prev_count != -1 && count != prev_count ));
then
echo "count mismatch count: "${count}". prev_count: "${prev_count}"."
exit 1
fi
prev_count=$count
done
}

main() {
set -e

local master
master=$(cdb2sql ${CDB2_OPTIONS} -tabs "${DBNAME}" "${TIER}" "select host from comdb2_cluster where is_master='Y'")
readonly master

local trunc_lsn
trunc_lsn=$(cdb2sql ${CDB2_OPTIONS} --host "${master}" "${DBNAME}" 'exec procedure sys.cmd.send("bdb cluster")' \
| grep MASTER | sed 's/.*lsn //g ; s/ .*//g')
readonly trunc_lsn

cdb2sql ${CDB2_OPTIONS} "${DBNAME}" "${TIER}" "create table t(i int)"
for ((i=0; i<1000; ++i ));
do
cdb2sql ${CDB2_OPTIONS} "${DBNAME}" "${TIER}" "insert into t values("${i}")" &> /dev/null
done

cdb2sql ${CDB2_OPTIONS} --host "${master}" "${DBNAME}" "exec procedure sys.cmd.truncate_log(\"{"${trunc_lsn}"}\");" &
query_replicant_in_loop
}

main