Skip to content

Commit 46ee730

Browse files
committed
Implement partition database discovery via comdb2db.cfg
Signed-off-by: Salil Chandra <schandra107@bloomberg.net>
1 parent 369509a commit 46ee730

File tree

8 files changed

+208
-46
lines changed

8 files changed

+208
-46
lines changed

cdb2api/cdb2api.c

Lines changed: 138 additions & 31 deletions
Large diffs are not rendered by default.

tests/partitiondb.test/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export SECONDARY_DB_PREFIX=s1
2+
3+
ifeq ($(TESTSROOTDIR),)
4+
include ../testcase.mk
5+
else
6+
include $(TESTSROOTDIR)/testcase.mk
7+
endif
8+
ifeq ($(TEST_TIMEOUT),)
9+
export TEST_TIMEOUT=2m
10+
endif

tests/partitiondb.test/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test that a partition database name gets mapped onto a shard via the api.

tests/partitiondb.test/lrl.options

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
foreign_db_resolve_local 1
2+
foreign_db_push_remote_writes 1

tests/partitiondb.test/runit

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
bash -n "$0" | exit 1
3+
set -x
4+
5+
SHARDS_LIST="$DBNAME $SECONDARY_DBNAME"
6+
7+
echo "shard partitiondb:$SHARDS_LIST" >> $DBDIR/comdb2db.cfg
8+
9+
P_SQL="cdb2sql --tabs ${CDB2_OPTIONS} partitiondb default"
10+
11+
shard=$($P_SQL "select comdb2_dbname()")
12+
if [[ $shard != $DBNAME && $shard != $SECONDARY_DBNAME ]]; then
13+
echo "Got dbname $shard but expected one in ($DBNAME, $SECONDARY_DBNAME)"
14+
exit 1
15+
fi;
16+
17+
echo "Success"

tests/remotecreate.test/runit

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ shards=""
2121
SHARDS_LIST="$DBNAME $SECONDARY_DBNAME $TERTIARY_DBNAME $QUATERNARY_DBNAME"
2222
numshards=4
2323

24+
echo "shard partitiondb:$SHARDS_LIST" >> $DBDIR/comdb2db.cfg
25+
26+
P_SQLT="cdb2sql --tabs ${CDB2_OPTIONS} partitiondb default"
27+
P_SQL="cdb2sql ${CDB2_OPTIONS} partitiondb default"
2428
S0_SQLT="cdb2sql --tabs ${CDB2_OPTIONS} ${DBNAME} default"
2529
S0_SQL="cdb2sql ${CDB2_OPTIONS} ${DBNAME} default"
2630
S1_SQLT="cdb2sql --tabs ${SECONDARY_CDB2_OPTIONS} ${SECONDARY_DBNAME} default"
@@ -43,7 +47,7 @@ function fail_exit()
4347
}
4448

4549
function setup_testcase {
46-
$S0_SQL "DROP TABLE IF EXISTS t"
50+
$P_SQL "DROP TABLE IF EXISTS t"
4751
}
4852

4953
function verify_table {
@@ -90,24 +94,24 @@ function verify_llmeta {
9094
}
9195

9296
function test_creation_nonkey {
93-
$S0_SQL "create table t(a int , b int) partitioned by columns(a) on (${shards})"
97+
$P_SQL "create table t(a int , b int) partitioned by columns(a) on (${shards})"
9498
if (( $? == 0 )); then
9599
fail_exit "test_creation succeeded. Should have failed creating a sharded table with a non-key sharding key"
96100
fi
97101
}
98102

99103
function test_deletion {
100-
$S0_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
104+
$P_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
101105
if (( $? != 0 )); then
102106
fail_exit "test_creation failed. Could not create table"
103107
fi
104108
verify_table "t"
105-
$S0_SQL "drop table t"
109+
$P_SQL "drop table t"
106110
verify_llmeta ''
107111
}
108112

109113
function test_creation {
110-
$S0_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
114+
$P_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
111115
if (( $? != 0 )); then
112116
fail_exit "test_creation failed. Could not create table"
113117
fi

tests/tools/cdb2api_unit.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ void test_read_comdb2db_cfg()
194194
int num_db_hosts = 0;
195195
int dbnum = 0;
196196
int stack_at_open = 0;
197+
char shards[10][DBNAME_LEN];
198+
int num_shards = 0;
197199

198200
const char *buf =
199201
"\
@@ -206,17 +208,20 @@ void test_read_comdb2db_cfg()
206208
buf, comdb2db_hosts,
207209
&num_hosts, &comdb2db_num, dbname,
208210
db_hosts, &num_db_hosts,
209-
&dbnum, &stack_at_open);
211+
&dbnum, &stack_at_open,
212+
shards, &num_shards);
210213

211214
assert(num_hosts == 0);
212215
assert(comdb2db_num == 0);
213216
assert(num_db_hosts == 0);
214217
assert(dbnum == 0);
218+
assert(num_shards == 0);
215219

216220
const char *buf2 =
217221
"\n\
218222
comdb2dbnm:a,b,c:d:e \n\
219223
mydb:n1,n2,n3:n4:n5,n6 \n\
224+
shard mydb:mydb1,mydb2,mydb3,mydb4 \n\
220225
comdb2_config:default_type:testsuite \n\
221226
comdb2_config:portmuxport=12345 \n\
222227
comdb2_config:allow_pmux_route:true \
@@ -226,7 +231,8 @@ void test_read_comdb2db_cfg()
226231
buf2, comdb2db_hosts,
227232
&num_hosts, &comdb2db_num, dbname,
228233
db_hosts, &num_db_hosts,
229-
&dbnum, &stack_at_open);
234+
&dbnum, &stack_at_open,
235+
shards, &num_shards);
230236

231237
assert(num_hosts == 5);
232238
assert(comdb2db_num == 0);
@@ -247,12 +253,21 @@ void test_read_comdb2db_cfg()
247253
assert(dbnum == 0);
248254
assert(12345 == CDB2_PORTMUXPORT);
249255

256+
assert(num_shards == 4);
257+
assert(strcmp(shards[0], "mydb1") == 0);
258+
assert(strcmp(shards[1], "mydb2") == 0);
259+
assert(strcmp(shards[2], "mydb3") == 0);
260+
assert(strcmp(shards[3], "mydb4") == 0);
261+
250262
// test with buf3 which provokes buffer overflow in cdb2api
263+
// make sure cannot use mydb as shard name (will be ignored)
251264
num_hosts = 0;
252265
num_db_hosts = 0;
266+
num_shards = 0;
253267
const char *buf3 = "\
254268
comdb2dbnm:test_short_hostname,test_long_hostname_xf00fxf00fxf00fxf00fxf00fxf00fxf00fxf00fxf00f,test_overflow_hostname_extra_text_is_truncatedtest_overflow_hostname_extra_text_is_truncatedtest_overflow_hostname_extra_text_is_truncated \n\
255269
mydb:test_short_hostname,test_long_hostname_xf00fxf00fxf00fxf00fxf00fxf00fxf00fxf00fxf00f,test_overflow_hostname_extra_text_is_truncatedtest_overflow_hostname_extra_text_is_truncatedtest_overflow_hostname_extra_text_is_truncated \n\
270+
shard mydb:test_short_shard,mydb,test_long_shard_xf00fxf00fxf00f,test_overflow_shard_extra_text_is_truncated \n\
256271
comdb2_config:default_type:test_overflow_when_assigning_the_default_type_extra_text_is_truncated \n\
257272
comdb2_config:room:test_overflow_when_assigning_the_room_extra_text_is_truncated \n\
258273
comdb2_config:comdb2dbname:test_overflow_when_assigning_the_dbname_extra_text_is_truncated \n\
@@ -262,7 +277,8 @@ void test_read_comdb2db_cfg()
262277
buf3, comdb2db_hosts,
263278
&num_hosts, &comdb2db_num, dbname,
264279
db_hosts, &num_db_hosts,
265-
&dbnum, &stack_at_open);
280+
&dbnum, &stack_at_open,
281+
shards, &num_shards);
266282

267283
assert(num_db_hosts == 3);
268284
assert(num_hosts == 3);
@@ -276,6 +292,11 @@ void test_read_comdb2db_cfg()
276292
assert(strcmp(cdb2_machine_room, "test_overflow_w") == 0);
277293
assert(strcmp(cdb2_comdb2dbname, "test_overflow_when_assigning_th") == 0);
278294
assert(strcmp(cdb2_dnssuffix, "test_overflow_when_assigning_the_dnssuffix_extra_text_is_truncatedtest_overflow_when_assigning_the_dnssuffix_extra_text_is_truncatedtest_overflow_when_assigning_the_dnssuffix_extra_text_is_truncatedtest_overflow_when_assigning_the_dnssuffix_extra_text_is") == 0);
295+
296+
assert(num_shards == 3);
297+
assert(strcmp(shards[0], "test_short_shard") == 0);
298+
assert(strcmp(shards[1], "test_long_shard_xf00fxf00fxf00f") == 0);
299+
assert(strcmp(shards[2], "test_overflow_shard_extra_text_is_truncated") == 0);
279300
}
280301

281302

tests/tools/test_get_comdb2db_hosts.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int main()
2424

2525
rc = get_comdb2db_hosts(NULL,NULL, NULL, &master,
2626
NULL, &num_hosts, NULL,NULL,
27-
NULL, &num_db_hosts, NULL, 1);
27+
NULL, &num_db_hosts, NULL, 1, NULL, NULL);
2828

2929
assert(rc == -1);
3030
assert(num_hosts == -1);
@@ -34,7 +34,7 @@ int main()
3434

3535
rc = get_comdb2db_hosts(NULL,NULL, NULL, &master,
3636
NULL, &num_hosts, NULL,NULL,
37-
NULL, &num_db_hosts, NULL, 1); //just get defaults
37+
NULL, &num_db_hosts, NULL, 1, NULL, NULL); //just get defaults
3838

3939
assert(rc == 0);
4040
assert(num_hosts == 0);
@@ -47,7 +47,7 @@ int main()
4747
char db_hosts[MAX_NODES][CDB2HOSTNAME_LEN] = {0};
4848
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
4949
NULL, &num_hosts, NULL, NULL,
50-
db_hosts, &num_db_hosts, NULL, 1);
50+
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);
5151

5252
assert(rc == 0);
5353
assert(num_db_hosts == 0);
@@ -66,7 +66,7 @@ int main()
6666
char db_hosts[MAX_NODES][CDB2HOSTNAME_LEN] = {0};
6767
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
6868
NULL, &num_hosts, NULL, NULL,
69-
db_hosts, &num_db_hosts, NULL, 1);
69+
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);
7070

7171
assert(rc == 0);
7272
assert(num_hosts == 0);
@@ -86,7 +86,7 @@ int main()
8686
int comdb2db_num = 0;
8787
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
8888
NULL, &num_hosts, &comdb2db_num, NULL,
89-
db_hosts, &num_db_hosts, NULL, 1);
89+
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);
9090

9191
assert(rc == 0);
9292
assert(num_hosts == 3);
@@ -106,7 +106,7 @@ int main()
106106
int comdb2db_num = 0;
107107
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
108108
NULL, &num_hosts, &comdb2db_num, NULL,
109-
db_hosts, &num_db_hosts, NULL, 1);
109+
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);
110110

111111
assert(rc == -1);
112112
assert(num_hosts == 0);
@@ -123,7 +123,7 @@ int main()
123123
int comdb2db_num = 0;
124124
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
125125
NULL, &num_hosts, &comdb2db_num, NULL,
126-
db_hosts, &num_db_hosts, NULL, 1);
126+
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);
127127

128128
assert(rc == 0);
129129
assert(num_hosts == 3);

0 commit comments

Comments
 (0)