Skip to content

Commit ac2cb4d

Browse files
committed
Disable 2pc for distributed sc for now
Signed-off-by: mohitkhullar <mkhullar1@bloomberg.net>
1 parent 2585bb8 commit ac2cb4d

6 files changed

Lines changed: 174 additions & 1 deletion

File tree

db/fdb_fend.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6324,6 +6324,9 @@ static int _running_dist_ddl(struct schema_change_type *sc, char **errmsg, uint3
63246324

63256325
*errmsg = "";
63266326

6327+
/* Fix this, for now disable 2pc if its a DDL */
6328+
clnt->use_2pc = 0;
6329+
63276330
pushes = (fdb_push_connector_t**)alloca(nshards * sizeof(fdb_push_connector_t*));
63286331
bzero(pushes, nshards * sizeof(fdb_push_connector_t*));
63296332

db/sqlinterfaces.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ extern int gbl_alternate_normalize;
150150
extern int gbl_typessql;
151151
extern int gbl_modsnap_asof;
152152
extern int gbl_use_modsnap_for_snapshot;
153+
extern int gbl_2pc;
153154

154155
/* Once and for all:
155156
@@ -4208,6 +4209,9 @@ static int execute_sql_query(struct sqlthdstate *thd, struct sqlclntstate *clnt)
42084209
if (rc)
42094210
return rc;
42104211

4212+
if (gbl_2pc && !clnt->use_2pc && !in_client_trans(clnt))
4213+
clnt->use_2pc = gbl_2pc;
4214+
42114215
/* is this a snapshot? special processing */
42124216
rc = get_high_availability(clnt);
42134217
if (rc) {
@@ -5383,7 +5387,6 @@ void reset_clnt(struct sqlclntstate *clnt, int initial)
53835387
clnt->num_retry = 0;
53845388
clnt->early_retry = 0;
53855389

5386-
extern int gbl_2pc;
53875390
clnt->use_2pc = gbl_2pc;
53885391
clnt->is_coordinator = 0;
53895392
clnt->is_participant = 0;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export SECONDARY_DB_PREFIX=s1
2+
export TERTIARY_DB_PREFIX=s2
3+
export QUATERNARY_DB_PREFIX=s3
4+
5+
ifeq ($(TESTSROOTDIR),)
6+
include ../testcase.mk
7+
else
8+
include $(TESTSROOTDIR)/testcase.mk
9+
endif
10+
ifeq ($(TEST_TIMEOUT),)
11+
export TEST_TIMEOUT=2m
12+
endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test 2PC transactional multi table create & drop.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foreign_db_resolve_local 1
2+
foreign_db_push_remote_writes 1
3+
enable_2pc
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/usr/bin/env bash
2+
bash -n "$0" | exit 1
3+
set -x
4+
# Remote cursor moves testcase for comdb2
5+
################################################################################
6+
7+
8+
# we rely on the following global variables to be set
9+
echo "main db vars"
10+
vars="TESTCASE DBNAME DBDIR TESTSROOTDIR TESTDIR CDB2_OPTIONS CDB2_CONFIG SECONDARY_DBNAME SECONDARY_DBDIR SECONDARY_CDB2_CONFIG SECONDARY_CDB2_OPTIONS TERTIARY_DBNAME TERTIARY_DBDIR TERTIARY_CDB2_CONFIG TERTIARY_CDB2_OPTIONS QUATERNARY_DBNAME QUATERNARY_DBDIR QUATERNARY_CDB2_CONFIG QUATERNARY_CDB2_OPTIONS"
11+
for required in $vars; do
12+
q=${!required}
13+
echo "$required=$q"
14+
if [[ -z "$q" ]]; then
15+
echo "$required not set" >&2
16+
exit 1
17+
fi
18+
done
19+
20+
shards=""
21+
SHARDS_LIST="$DBNAME $SECONDARY_DBNAME $TERTIARY_DBNAME $QUATERNARY_DBNAME"
22+
numshards=4
23+
24+
S0_SQLT="cdb2sql --tabs ${CDB2_OPTIONS} ${DBNAME} default"
25+
S0_SQL="cdb2sql ${CDB2_OPTIONS} ${DBNAME} default"
26+
S1_SQLT="cdb2sql --tabs ${SECONDARY_CDB2_OPTIONS} ${SECONDARY_DBNAME} default"
27+
S1_SQL="cdb2sql ${SECONDARY_CDB2_OPTIONS} ${SECONDARY_DBNAME} default"
28+
S2_SQLT="cdb2sql --tabs ${TERTIARY_CDB2_OPTIONS} ${TERTIARY_DBNAME} default"
29+
S2_SQL="cdb2sql ${TERTIARY_CDB2_OPTIONS} ${TERTIARY_DBNAME} default"
30+
S3_SQLT="cdb2sql --tabs ${QUATERNARY_CDB2_OPTIONS} ${QUATERNARY_DBNAME} default"
31+
S3_SQL="cdb2sql ${QUATERNARY_CDB2_OPTIONS} ${QUATERNARY_DBNAME} default"
32+
33+
OUT=log.txt
34+
35+
export stopfile=./stopfile.txt
36+
37+
rm ${OUT}
38+
39+
function fail_exit()
40+
{
41+
echo "Failed $@" | tee ${DBNAME}.fail_exit # runtestcase script looks for this file
42+
touch $stopfile
43+
}
44+
45+
function setup_testcase {
46+
$S0_SQL "DROP TABLE IF EXISTS t"
47+
}
48+
49+
function verify_table {
50+
tbl=$1
51+
$S0_SQLT "SELECT * from ${tbl}"
52+
if (( $? != 0 )); then
53+
fail_exit "verify_table failed. Could not select from ${tbl} on ${DBNAME}"
54+
fi
55+
$S1_SQLT "SELECT * from ${tbl}"
56+
if (( $? != 0 )); then
57+
fail_exit "verify_table failed. Could not select from ${tbl} on ${SECONDARY_DBNAME}"
58+
fi
59+
$S2_SQLT "SELECT * from ${tbl}"
60+
if (( $? != 0 )); then
61+
fail_exit "verify_table failed. Could not select from ${tbl} on ${TERNARY_DBNAME}"
62+
fi
63+
$S3_SQLT "SELECT * from ${tbl}"
64+
if (( $? != 0 )); then
65+
fail_exit "verify_table failed. Could not select from ${tbl} on ${QUATERNARY_DBNAME}"
66+
fi
67+
}
68+
function verify_llmeta {
69+
expected=$1
70+
result=$($S0_SQLT "EXEC PROCEDURE sys.cmd.send('llmeta list')" | grep "gen_shard")
71+
entry=`echo $result | cut -d ' ' -f 3 | cut -d '=' -f 2`
72+
if [ "$entry" != "$expected" ]; then
73+
fail_exit "verify_llmeta failed on $DBNAME. Expected $expected but got $entry"
74+
fi
75+
result=$($S1_SQLT "EXEC PROCEDURE sys.cmd.send('llmeta list')" | grep "gen_shard")
76+
entry=`echo $result | cut -d ' ' -f 3 | cut -d '=' -f 2`
77+
if [ "$entry" != "$expected" ]; then
78+
fail_exit "verify_llmeta failed on ${SECONDARY_DBNAME}. Expected $expected but got $entry"
79+
fi
80+
result=$($S2_SQLT "EXEC PROCEDURE sys.cmd.send('llmeta list')" | grep "gen_shard")
81+
entry=`echo $result | cut -d ' ' -f 3 | cut -d '=' -f 2`
82+
if [ "$entry" != "$expected" ]; then
83+
fail_exit "verify_llmeta failed on ${TERNARY_DBNAME}. Expected $expected but got $entry"
84+
fi
85+
result=$($S3_SQLT "EXEC PROCEDURE sys.cmd.send('llmeta list')" | grep "gen_shard")
86+
entry=`echo $result | cut -d ' ' -f 3 | cut -d '=' -f 2`
87+
if [ "$entry" != "$expected" ]; then
88+
fail_exit "verify_llmeta failed on ${QUATERNARY_DBNAME}. Expected $expected but got $entry"
89+
fi
90+
}
91+
92+
function test_creation_nonkey {
93+
$S0_SQL "create table t(a int , b int) partitioned by columns(a) on (${shards})"
94+
if (( $? == 0 )); then
95+
fail_exit "test_creation succeeded. Should have failed creating a sharded table with a non-key sharding key"
96+
fi
97+
}
98+
99+
function test_deletion {
100+
$S0_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
101+
if (( $? != 0 )); then
102+
fail_exit "test_creation failed. Could not create table"
103+
fi
104+
verify_table "t"
105+
$S0_SQL "drop table t"
106+
verify_llmeta ''
107+
}
108+
109+
function test_creation {
110+
$S0_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
111+
if (( $? != 0 )); then
112+
fail_exit "test_creation failed. Could not create table"
113+
fi
114+
verify_table "t"
115+
expected="\"{\"t\":\"{\\\"TABLENAME\\\":\\\"t\\\",\\\"NUMDBS\\\":4,\\\"DBNAMES\\\":[\\\"${DBNAME}\\\",\\\"${SECONDARY_DBNAME}\\\",\\\"${TERTIARY_DBNAME}\\\",\\\"${QUATERNARY_DBNAME}\\\"],\\\"NUMCOLS\\\":1,\\\"COLUMNS\\\":[\\\"a\\\"],\\\"SHARDNAMES\\\":[\\\"\$1_t\\\",\\\"\$2_t\\\",\\\"\$3_t\\\",\\\"\$4_t\\\"]}\"}\""
116+
verify_llmeta $expected
117+
}
118+
119+
function run_test {
120+
testcase="testing creation"
121+
setup_testcase
122+
test_creation
123+
124+
testcase="testing deletion"
125+
setup_testcase
126+
test_deletion
127+
128+
testcase="testing creation with non-key sharding key"
129+
setup_testcase
130+
test_creation_nonkey
131+
}
132+
133+
rm $stopfile >/dev/null 2>&1
134+
135+
136+
for shard in $SHARDS_LIST; do
137+
shards+=" ${shard},"
138+
done
139+
140+
# remove the last ','
141+
shards=`echo $shards | sed 's/.$//'`
142+
echo $shards
143+
144+
run_test
145+
146+
if [[ -f $stopfile ]]; then
147+
echo "Testcase failed"
148+
exit -1
149+
fi
150+
151+
echo "Success"

0 commit comments

Comments
 (0)