Skip to content

Commit 79245c7

Browse files
committed
syntax check and running argument and case
1 parent eecc2a1 commit 79245c7

File tree

5 files changed

+147
-31
lines changed

5 files changed

+147
-31
lines changed

db/sqlglue.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9742,6 +9742,12 @@ static int _ucancel_sql_statements_run(void)
97429742
return 0;
97439743
}
97449744

9745+
static int _ucancel_sql_statements_que(void)
9746+
{
9747+
return 0;
9748+
}
9749+
9750+
97459751
/*
97469752
* "Unified" sql statements cancel routine
97479753
* MODES:
@@ -9758,8 +9764,9 @@ int ucancel_sql_statements(enum ucancel_type type, char *uuid) {
97589764
return _ucancel_sql_statements_cno(uuid);
97599765
case UCANCEL_RUN:
97609766
return _ucancel_sql_statements_run();
9761-
case UCANCEL_ALL:
97629767
case UCANCEL_QUE:
9768+
return _ucancel_sql_statements_que();
9769+
case UCANCEL_ALL:
97639770
case UCANCEL_FPT:
97649771
logmsg(LOGMSG_ERROR, "%d unimplemented\n", type);
97659772
return -1;

lua/syssp.c.in

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -491,36 +491,32 @@ static int db_send(Lua L)
491491

492492
static int db_unified_cancel(Lua L)
493493
{
494-
char *type;
495-
char *uuid = NULL;
494+
const char *type;
495+
const char *uuid = NULL;
496496
char cmd[256];
497497

498498
int nargs = lua_gettop(L);
499+
assert(nargs == 2);
500+
499501
/* type */
500-
if (nargs == 2) {
501-
if (!lua_isstring(L, -2))
502-
return luaL_error(L, "Expected string type argument: all|queued|running|cnonce|fp");
503-
type = (char*) lua_tostring(L, -2);
504-
if (strncasecmp(type, "cnonce", sizeof("cnonce")) != 0 &&
505-
strncasecmp(type, "fp", sizeof("fp")) != 0) {
506-
return luaL_error(L, "Extra argument present\n");
507-
}
502+
if (!lua_isstring(L, -2))
503+
return luaL_error(L, "Expected string type argument: all|queued|running|cnonce|fp");
504+
type = lua_tostring(L, -2);
505+
/* check argument combinations */
506+
if (strncasecmp(type, "all", sizeof("all")) == 0 ||
507+
strncasecmp(type, "running", sizeof("running")) == 0 ||
508+
strncasecmp(type, "queued", sizeof("queued")) == 0) {
509+
if (!lua_isnil(L, -1))
510+
return luaL_error(L, "Extra argument present for type %s", type);
511+
} else if (strncasecmp(type, "cnonce", sizeof("cnonce")) == 0 ||
512+
strncasecmp(type, "fp", sizeof("fp")) == 0) {
513+
if (lua_isnil(L, -1))
514+
return luaL_error(L, "Missing uuid for type %s", type);
515+
uuid = lua_tostring(L, -1);
508516
} else {
509-
if (!lua_isstring(L, -1))
510-
return luaL_error(L, "Expected string type argument: all|queued|running|cnonce|fp");
511-
type = (char*) lua_tostring(L, -1);
512-
if (strncasecmp(type, "all", sizeof("all")) != 0 &&
513-
strncasecmp(type, "running", sizeof("running")) != 0 &&
514-
strncasecmp(type, "queued", sizeof("queued")) != 0) {
515-
return luaL_error(L, "Expected string type argument: all|queued|running|cnonce|fp");
516-
}
517+
return luaL_error(L, "Unrecognized cancel type %s", type);
517518
}
518519

519-
if (nargs == 2) {
520-
if (!lua_isstring(L, -1))
521-
return luaL_error(L, "Wrong type uuid for %s type", type);
522-
uuid = (char*) lua_tostring(L, -1);
523-
}
524520
lua_settop(L, 0);
525521

526522
snprintf(cmd, sizeof(cmd), "sql ucancel %s%s%s\n", type, uuid ? " ": "", uuid ? uuid : "");

tests/fdb_push.test/test_fdb_push.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ EOF
229229
#convert the table to actual dbname
230230
sed "s/dorintdb/${a_remdbname}/g" output.log > output.log.actual
231231

232-
#convert the table to actual dbname
233-
sed "s/dorintdb/${a_remdbname}/g" output.log > output.log.actual
234-
235232
# validate results
236233
testcase_output=$(cat $output)
237234
expected_output=$(cat output.log.actual)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[exec procedure sys.cmd.cancel()] failed with rc -3 [local msg = sys.cancel(cmd, uui...]:10: Expected string type argument: all|queued|running|cnonce|fp
2+
[exec procedure sys.cmd.cancel(123)] failed with rc -3 [local msg = sys.cancel(cmd, uui...]:10: Unrecognized cancel type 123
3+
[exec procedure sys.cmd.cancel('blah')] failed with rc -3 [local msg = sys.cancel(cmd, uui...]:10: Unrecognized cancel type blah
4+
[exec procedure sys.cmd.cancel('cnonce')] failed with rc -3 [local msg = sys.cancel(cmd, uui...]:10: Missing uuid for type cnonce
5+
[ERROR] Failed to parse uuid "123"
6+
[ERROR] Failed to parse uuid "1-23-456"

tests/unifiedcancel.test/test_cancel.sh

Lines changed: 114 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ set -x
77

88
# args
99
# <dbname> <autodbname> <dbdir> <testdir>
10-
a_rdbname=$4
11-
a_rcdb2config=$2
1210
a_dbname=$1
1311
a_cdb2config=$2
1412
a_dbdir=$3
@@ -29,7 +27,24 @@ function header
2927
echo "$2"
3028
}
3129

32-
header 1 "running a long query, retrieve it and cancel it"
30+
function waitforsql
31+
{
32+
local cnt=0
33+
local mx=$1
34+
local itr=0
35+
36+
while true; do
37+
cnt=`$S_TSQL "select count(*) from comdb2_connections where sql like '%sleep%' and sql not like '%connections%'"`
38+
echo "Found $d queries iteration $itr"
39+
if [[ "$cnt" -eq "$mx" ]] ; then
40+
echo "Done waiting after $itr iterations"
41+
break;
42+
fi
43+
let itr=itr+1
44+
sleep 1
45+
done
46+
}
47+
3348
echo "Running tests on node ${mach}"
3449
echo "inserting 60 records"
3550
$S_SQL "insert into t select * from generate_series(1,60)"
@@ -38,13 +53,16 @@ if [[ $? != 0 ]] ; then
3853
exit 1
3954
fi
4055

56+
header 1 "running a long query, retrieve it and cancel it"
4157
echo "running async select sleep"
4258
$S_SQL "select *, sleep(1) from t order by 1" &
4359
if [[ $? != 0 ]] ; then
4460
echo "Failed to async run sleep"
4561
exit 1
4662
fi
4763

64+
waitforsql 1
65+
4866
echo "collecting the sleep uuid"
4967
uuid=`$S_TSQL "select uuid from comdb2_connections where sql like '%sleep%' and sql not like '%connections%'"`
5068
if [[ $? != 0 ]] ; then
@@ -58,7 +76,7 @@ if [[ -z ${uuid} ]] ; then
5876
exit 1
5977
fi
6078

61-
echo "running cancel ${uuid} trap"
79+
echo "running cancel('cnonce', '${uuid}') trap"
6280
$S_SQL "exec procedure sys.cmd.cancel('cnonce', '${uuid}')"
6381
if [[ $? != 0 ]] ; then
6482
echo "Failed to run cancel message"
@@ -79,4 +97,96 @@ if [[ ! -z ${found_uuid} ]] ; then
7997
exit 1
8098
fi
8199

100+
101+
header 2 "running three long queries, and cancel all running"
102+
103+
for cnt in {1..3} ; do
104+
echo "running async select sleep $cnt"
105+
$S_SQL "select *, sleep(1) from t order by 1" &
106+
if [[ $? != 0 ]] ; then
107+
echo "Failed to async run sleep $cnt"
108+
exit 1
109+
fi
110+
done
111+
112+
waitforsql 3
113+
114+
echo "running cancel('running') trap"
115+
$S_SQL "exec procedure sys.cmd.cancel('running')"
116+
if [[ $? != 0 ]] ; then
117+
echo "Failed to run cancel message"
118+
exit 1
119+
fi
120+
121+
sleep 6
122+
123+
echo "check if the sleepy queries are gone"
124+
found_uuid=`$S_TSQL "select uuid from comdb2_connections where sql like '%sleep%' and sql not like '%connections%'"`
125+
if [[ $? != 0 ]] ; then
126+
echo "Failed to run cancel message"
127+
exit 1
128+
fi
129+
130+
if [[ ! -z ${found_uuid} ]] ; then
131+
echo "Failed to cancel the sleep select, found $found_uuid"
132+
exit 1
133+
fi
134+
135+
ooo=run.log
136+
137+
header 3 "checking syntax arguments"
138+
139+
$S_TSQL "exec procedure sys.cmd.cancel()" > $ooo 2>&1
140+
if [[ $? == 0 ]] ; then
141+
echo "Failed no type"
142+
exit 1
143+
fi
144+
$S_TSQL "exec procedure sys.cmd.cancel(123)" >> $ooo 2>&1
145+
if [[ $? == 0 ]] ; then
146+
echo "Failed wrong non-string type"
147+
exit 1
148+
fi
149+
$S_TSQL "exec procedure sys.cmd.cancel('blah')" >> $ooo 2>&1
150+
if [[ $? == 0 ]] ; then
151+
echo "Failed bogus string type"
152+
exit 1
153+
fi
154+
$S_TSQL "exec procedure sys.cmd.cancel('cnonce')" >> $ooo 2>&1
155+
if [[ $? == 0 ]] ; then
156+
echo "Failed no uuid cnonce"
157+
exit 1
158+
fi
159+
$S_TSQL "exec procedure sys.cmd.cancel('cnonce', 123)" >> $ooo 2>&1
160+
if [[ $? != 0 ]] ; then
161+
echo "Failed wrong type uuid cnonce"
162+
exit 1
163+
fi
164+
$S_TSQL "exec procedure sys.cmd.cancel('cnonce', '1-23-456')" >> $ooo 2>&1
165+
if [[ $? != 0 ]] ; then
166+
echo "Failed invalid uuid cnonce"
167+
exit 1
168+
fi
169+
170+
#convert the table to actual dbname
171+
sed "s/dorintdb/${a_dbname}/g" output.log > output.log.actual
172+
173+
# validate results
174+
testcase_output=$(cat ${ooo})
175+
expected_output=$(cat output.log.actual)
176+
if [[ "$testcase_output" != "$expected_output" ]]; then
177+
178+
# print message
179+
echo " ^^^^^^^^^^^^"
180+
echo "The above testcase (${testcase}) has failed!!!"
181+
echo " "
182+
echo "Use 'diff <expected-output> <my-output>' to see why:"
183+
echo "> diff ${PWD}/{${ooo}, output.log.actual}"
184+
echo " "
185+
diff ${ooo} output.log.actual
186+
echo " "
187+
188+
# quit
189+
exit 1
190+
fi
191+
82192
echo "Testcase passed."

0 commit comments

Comments
 (0)