Skip to content
Merged
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
209 changes: 157 additions & 52 deletions cdb2api/cdb2api.c

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions tests/partitiondb.test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export SECONDARY_DB_PREFIX=s1

ifeq ($(TESTSROOTDIR),)
include ../testcase.mk
else
include $(TESTSROOTDIR)/testcase.mk
endif
ifeq ($(TEST_TIMEOUT),)
export TEST_TIMEOUT=2m
endif
1 change: 1 addition & 0 deletions tests/partitiondb.test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test that a partition database name gets mapped onto a shard via the api.
2 changes: 2 additions & 0 deletions tests/partitiondb.test/lrl.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foreign_db_resolve_local 1
foreign_db_push_remote_writes 1
22 changes: 22 additions & 0 deletions tests/partitiondb.test/runit
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
bash -n "$0" | exit 1
set -x

SHARDS_LIST="$DBNAME $SECONDARY_DBNAME"

# for pdb discovery to work for this test, we need to add the cluster lines from the extra dbs into the primary db comdb2 config
# since SECONDARY_CDB2_OPTIONS will not be used when querying partitiondb
cluster_line=$(head -n 1 $DBDIR/comdb2db.cfg)
echo "s1$cluster_line" >> $DBDIR/comdb2db.cfg

echo "partition partitiondb:$SHARDS_LIST" >> $DBDIR/comdb2db.cfg

P_SQL="cdb2sql --tabs ${CDB2_OPTIONS} partitiondb default"

shard=$($P_SQL "select comdb2_dbname()")
if [[ $shard != $DBNAME && $shard != $SECONDARY_DBNAME ]]; then
echo "Got dbname $shard but expected one in ($DBNAME, $SECONDARY_DBNAME)"
exit 1
fi;

echo "Success"
21 changes: 16 additions & 5 deletions tests/remotecreate.test/runit
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ shards=""
SHARDS_LIST="$DBNAME $SECONDARY_DBNAME $TERTIARY_DBNAME $QUATERNARY_DBNAME"
numshards=4

# for pdb discovery to work for this test, we need to add the cluster lines from the extra dbs into the primary db comdb2 config
# since SECONDARY_CDB2_OPTIONS, TERTIARY_CDB2_OPTIONS, etc. will not be used when querying partitiondb
cluster_line=$(head -n 1 $DBDIR/comdb2db.cfg)
echo "s1$cluster_line" >> $DBDIR/comdb2db.cfg
echo "s2$cluster_line" >> $DBDIR/comdb2db.cfg
echo "s3$cluster_line" >> $DBDIR/comdb2db.cfg

echo "partition partitiondb:$SHARDS_LIST" >> $DBDIR/comdb2db.cfg

P_SQLT="cdb2sql --tabs ${CDB2_OPTIONS} partitiondb default"
P_SQL="cdb2sql ${CDB2_OPTIONS} partitiondb default"
S0_SQLT="cdb2sql --tabs ${CDB2_OPTIONS} ${DBNAME} default"
S0_SQL="cdb2sql ${CDB2_OPTIONS} ${DBNAME} default"
S1_SQLT="cdb2sql --tabs ${SECONDARY_CDB2_OPTIONS} ${SECONDARY_DBNAME} default"
Expand All @@ -43,7 +54,7 @@ function fail_exit()
}

function setup_testcase {
$S0_SQL "DROP TABLE IF EXISTS t"
$P_SQL "DROP TABLE IF EXISTS t"
}

function verify_table {
Expand Down Expand Up @@ -90,24 +101,24 @@ function verify_llmeta {
}

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

function test_deletion {
$S0_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
$P_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
if (( $? != 0 )); then
fail_exit "test_creation failed. Could not create table"
fi
verify_table "t"
$S0_SQL "drop table t"
$P_SQL "drop table t"
verify_llmeta ''
}

function test_creation {
$S0_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
$P_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})"
if (( $? != 0 )); then
fail_exit "test_creation failed. Could not create table"
fi
Expand Down
27 changes: 24 additions & 3 deletions tests/tools/cdb2api_unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ void test_read_comdb2db_cfg()
int num_db_hosts = 0;
int dbnum = 0;
int stack_at_open = 0;
char shards[10][DBNAME_LEN];
int num_shards = 0;

const char *buf =
"\
Expand All @@ -206,17 +208,20 @@ void test_read_comdb2db_cfg()
buf, comdb2db_hosts,
&num_hosts, &comdb2db_num, dbname,
db_hosts, &num_db_hosts,
&dbnum, &stack_at_open);
&dbnum, &stack_at_open,
shards, &num_shards);

assert(num_hosts == 0);
assert(comdb2db_num == 0);
assert(num_db_hosts == 0);
assert(dbnum == 0);
assert(num_shards == 0);

const char *buf2 =
"\n\
comdb2dbnm:a,b,c:d:e \n\
mydb:n1,n2,n3:n4:n5,n6 \n\
partition mydb:mydb1,mydb2,mydb3,mydb4 \n\
comdb2_config:default_type:testsuite \n\
comdb2_config:portmuxport=12345 \n\
comdb2_config:allow_pmux_route:true \
Expand All @@ -226,7 +231,8 @@ void test_read_comdb2db_cfg()
buf2, comdb2db_hosts,
&num_hosts, &comdb2db_num, dbname,
db_hosts, &num_db_hosts,
&dbnum, &stack_at_open);
&dbnum, &stack_at_open,
shards, &num_shards);

assert(num_hosts == 5);
assert(comdb2db_num == 0);
Expand All @@ -247,12 +253,21 @@ void test_read_comdb2db_cfg()
assert(dbnum == 0);
assert(12345 == CDB2_PORTMUXPORT);

assert(num_shards == 4);
assert(strcmp(shards[0], "mydb1") == 0);
assert(strcmp(shards[1], "mydb2") == 0);
assert(strcmp(shards[2], "mydb3") == 0);
assert(strcmp(shards[3], "mydb4") == 0);

// test with buf3 which provokes buffer overflow in cdb2api
// make sure cannot use mydb as shard name (will be ignored)
num_hosts = 0;
num_db_hosts = 0;
num_shards = 0;
const char *buf3 = "\
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\
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\
partition mydb:test_short_shard,mydb,test_long_shard_xf00fxf00fxf00f,test_overflow_shard_extra_text_is_truncated \n\
comdb2_config:default_type:test_overflow_when_assigning_the_default_type_extra_text_is_truncated \n\
comdb2_config:room:test_overflow_when_assigning_the_room_extra_text_is_truncated \n\
comdb2_config:comdb2dbname:test_overflow_when_assigning_the_dbname_extra_text_is_truncated \n\
Expand All @@ -262,7 +277,8 @@ void test_read_comdb2db_cfg()
buf3, comdb2db_hosts,
&num_hosts, &comdb2db_num, dbname,
db_hosts, &num_db_hosts,
&dbnum, &stack_at_open);
&dbnum, &stack_at_open,
shards, &num_shards);

assert(num_db_hosts == 3);
assert(num_hosts == 3);
Expand All @@ -276,6 +292,11 @@ void test_read_comdb2db_cfg()
assert(strcmp(cdb2_machine_room, "test_overflow_w") == 0);
assert(strcmp(cdb2_comdb2dbname, "test_overflow_when_assigning_th") == 0);
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);

assert(num_shards == 3);
assert(strcmp(shards[0], "test_short_shard") == 0);
assert(strcmp(shards[1], "test_long_shard_xf00fxf00fxf00f") == 0);
assert(strcmp(shards[2], "test_overflow_shard_extra_text_is_truncated") == 0);
}


Expand Down
14 changes: 7 additions & 7 deletions tests/tools/test_get_comdb2db_hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main()

rc = get_comdb2db_hosts(NULL,NULL, NULL, &master,
NULL, &num_hosts, NULL,NULL,
NULL, &num_db_hosts, NULL, 1);
NULL, &num_db_hosts, NULL, 1, NULL, NULL);

assert(rc == -1);
assert(num_hosts == -1);
Expand All @@ -34,7 +34,7 @@ int main()

rc = get_comdb2db_hosts(NULL,NULL, NULL, &master,
NULL, &num_hosts, NULL,NULL,
NULL, &num_db_hosts, NULL, 1); //just get defaults
NULL, &num_db_hosts, NULL, 1, NULL, NULL); //just get defaults

assert(rc == 0);
assert(num_hosts == 0);
Expand All @@ -47,7 +47,7 @@ int main()
char db_hosts[MAX_NODES][CDB2HOSTNAME_LEN] = {0};
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
NULL, &num_hosts, NULL, NULL,
db_hosts, &num_db_hosts, NULL, 1);
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);

assert(rc == 0);
assert(num_db_hosts == 0);
Expand All @@ -66,7 +66,7 @@ int main()
char db_hosts[MAX_NODES][CDB2HOSTNAME_LEN] = {0};
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
NULL, &num_hosts, NULL, NULL,
db_hosts, &num_db_hosts, NULL, 1);
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);

assert(rc == 0);
assert(num_hosts == 0);
Expand All @@ -86,7 +86,7 @@ int main()
int comdb2db_num = 0;
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
NULL, &num_hosts, &comdb2db_num, NULL,
db_hosts, &num_db_hosts, NULL, 1);
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);

assert(rc == 0);
assert(num_hosts == 3);
Expand All @@ -106,7 +106,7 @@ int main()
int comdb2db_num = 0;
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
NULL, &num_hosts, &comdb2db_num, NULL,
db_hosts, &num_db_hosts, NULL, 1);
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);

assert(rc == -1);
assert(num_hosts == 0);
Expand All @@ -123,7 +123,7 @@ int main()
int comdb2db_num = 0;
rc = get_comdb2db_hosts(NULL, comdb2db_hosts, NULL, &master,
NULL, &num_hosts, &comdb2db_num, NULL,
db_hosts, &num_db_hosts, NULL, 1);
db_hosts, &num_db_hosts, NULL, 1, NULL, NULL);

assert(rc == 0);
assert(num_hosts == 3);
Expand Down