Changeset: fc0ca64a3128 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fc0ca64a3128 Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/MAL-signatures.stable.out.int128 clients/Tests/exports.stable.out monetdb5/modules/kernel/alarm.c monetdb5/modules/kernel/alarm.mal sql/ChangeLog sql/backends/monet5/sql_upgrades.c sql/scripts/25_debug.sql sql/test/emptydb/Tests/check.stable.out sql/test/emptydb/Tests/check.stable.out.32bit sql/test/emptydb/Tests/check.stable.out.int128 sql/test/sys-schema/Tests/systemfunctions.stable.out sql/test/sys-schema/Tests/systemfunctions.stable.out.int128 Branch: linear-hashing Log Message:
Backported sleep procedure/function into linear-hashing diffs (truncated from 372 to 300 lines): diff --git a/clients/Tests/MAL-signatures.stable.out b/clients/Tests/MAL-signatures.stable.out --- a/clients/Tests/MAL-signatures.stable.out +++ b/clients/Tests/MAL-signatures.stable.out @@ -532,7 +532,9 @@ stdout of test 'MAL-signatures` in direc [ "aggr", "variancep", "command aggr.variancep(b:bat[:any_2]):dbl ", "ALGvariancep;", "Gives the variance of all tail values" ] [ "alarm", "ctime", "unsafe command alarm.ctime():str ", "ALARMctime;", "Return the current time as a C-time string." ] [ "alarm", "epoch", "unsafe command alarm.epoch():int ", "ALARMepoch;", "Return time since Jan 1, 1970 in seconds." ] -[ "alarm", "sleep", "unsafe command alarm.sleep(secs:int):void ", "ALARMsleep;", "Sleep a few seconds" ] +[ "alarm", "sleep", "unsafe pattern alarm.sleep(msecs:bat[:int]):bat[:int] ", "ALARMsleep;", "Sleep a few milliseconds and return the slept value" ] +[ "alarm", "sleep", "unsafe pattern alarm.sleep(msecs:int):int ", "ALARMsleep;", "Sleep a few milliseconds and return the slept value" ] +[ "alarm", "sleep", "unsafe pattern alarm.sleep(msecs:int):void ", "ALARMsleep;", "Sleep a few milliseconds" ] [ "alarm", "time", "unsafe command alarm.time():int ", "ALARMtime;", "Return time since program start in milliseconds." ] [ "alarm", "usec", "unsafe command alarm.usec():lng ", "ALARMusec;", "Return time since Jan 1, 1970 in microseconds." ] [ "algebra", "antijoin", "function algebra.antijoin(l:bat[:any_1], r:bat[:any_1], sl:bat[:oid], sr:bat[:oid], nil_matches:bit, estimate:lng) (X_0:bat[:oid], X_1:bat[:oid]);", "", "" ] diff --git a/clients/Tests/MAL-signatures.stable.out.int128 b/clients/Tests/MAL-signatures.stable.out.int128 --- a/clients/Tests/MAL-signatures.stable.out.int128 +++ b/clients/Tests/MAL-signatures.stable.out.int128 @@ -636,7 +636,9 @@ stdout of test 'MAL-signatures` in direc [ "aggr", "variancep", "command aggr.variancep(b:bat[:any_2]):dbl ", "ALGvariancep;", "Gives the variance of all tail values" ] [ "alarm", "ctime", "unsafe command alarm.ctime():str ", "ALARMctime;", "Return the current time as a C-time string." ] [ "alarm", "epoch", "unsafe command alarm.epoch():int ", "ALARMepoch;", "Return time since Jan 1, 1970 in seconds." ] -[ "alarm", "sleep", "unsafe command alarm.sleep(secs:int):void ", "ALARMsleep;", "Sleep a few seconds" ] +[ "alarm", "sleep", "unsafe pattern alarm.sleep(msecs:bat[:int]):bat[:int] ", "ALARMsleep;", "Sleep a few milliseconds and return the slept value" ] +[ "alarm", "sleep", "unsafe pattern alarm.sleep(msecs:int):int ", "ALARMsleep;", "Sleep a few milliseconds and return the slept value" ] +[ "alarm", "sleep", "unsafe pattern alarm.sleep(msecs:int):void ", "ALARMsleep;", "Sleep a few milliseconds" ] [ "alarm", "time", "unsafe command alarm.time():int ", "ALARMtime;", "Return time since program start in milliseconds." ] [ "alarm", "usec", "unsafe command alarm.usec():lng ", "ALARMusec;", "Return time since Jan 1, 1970 in microseconds." ] [ "algebra", "antijoin", "function algebra.antijoin(l:bat[:any_1], r:bat[:any_1], sl:bat[:oid], sr:bat[:oid], nil_matches:bit, estimate:lng) (X_0:bat[:oid], X_1:bat[:oid]);", "", "" ] diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -707,7 +707,7 @@ str AGGRvariance3_dbl(bat *retval, const str AGGRvariancep3_dbl(bat *retval, const bat *bid, const bat *gid, const bat *eid); str ALARMctime(str *res); str ALARMepoch(int *res); -str ALARMsleep(void *res, int *secs); +str ALARMsleep(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); str ALARMtime(int *res); str ALARMusec(lng *ret); str ALGbandjoin(bat *r1, bat *r2, const bat *lid, const bat *rid, const bat *slid, const bat *srid, const void *low, const void *high, const bit *li, const bit *hi, const lng *estimate); diff --git a/monetdb5/modules/kernel/alarm.c b/monetdb5/modules/kernel/alarm.c --- a/monetdb5/modules/kernel/alarm.c +++ b/monetdb5/modules/kernel/alarm.c @@ -22,19 +22,16 @@ */ #include "monetdb_config.h" #include "mal.h" -#include <signal.h> +#include "mal_client.h" +#include "mal_interpreter.h" #include <time.h> mal_export str ALARMusec(lng *ret); -mal_export str ALARMsleep(void *res, int *secs); +mal_export str ALARMsleep(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); mal_export str ALARMctime(str *res); mal_export str ALARMepoch(int *res); mal_export str ALARMtime(int *res); -#include "mal.h" -#include "mal_exception.h" - - str ALARMusec(lng *ret) { @@ -43,13 +40,57 @@ ALARMusec(lng *ret) } str -ALARMsleep(void *res, int *secs) +ALARMsleep(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { - (void) res; /* fool compilers */ - if (*secs < 0) - throw(MAL, "alarm.sleep", "negative delay"); + BAT *r, *b; + int *restrict rb, *restrict bb; + BUN i, j; + + (void) cntxt; + if (getArgType(mb, pci, 0) != TYPE_void && isaBatType(getArgType(mb, pci, 1))) { + bat *res = getArgReference_bat(stk, pci, 0); + bat *bid = getArgReference_bat(stk, pci, 1); + + if (!(b = BATdescriptor(*bid))) + throw(MAL, "alarm.sleepr", SQLSTATE(HY005) "Cannot access column descriptor"); + + j = BATcount(b); + bb = Tloc(b, 0); + for (i = 0; i < j ; i++) { + if (is_int_nil(bb[i])) { + BBPunfix(b->batCacheid); + throw(MAL, "alarm.sleepr", "NULL values not allowed for the sleeping time"); + } else if (bb[i]) { + BBPunfix(b->batCacheid); + throw(MAL, "alarm.sleepr", "Cannot sleep for a negative time"); + } + } - MT_sleep_ms(*secs * 1000); + r = COLnew(0, TYPE_int, j, TRANSIENT); + if (r == NULL) { + BBPunfix(b->batCacheid); + throw(MAL, "alarm.sleepr", SQLSTATE(HY013) MAL_MALLOC_FAIL); + } + + rb = Tloc(r, 0); + for (i = 0; i < j ; i++) { + MT_sleep_ms(bb[i]); + rb[i] = bb[i]; + } + + BBPunfix(b->batCacheid); + BBPkeepref(*res = r->batCacheid); + } else { + int *res = (int*) getArgReference(stk, pci, 0), *msecs = (int*) getArgReference(stk,pci,1); + + if (is_int_nil(*msecs)) + throw(MAL, "alarm.sleepr", "NULL values not allowed for the sleeping time"); + else if (*msecs < 0) + throw(MAL, "alarm.sleepr", "Cannot sleep for a negative time"); + + MT_sleep_ms(*msecs); + *res = *msecs; + } return MAL_SUCCEED; } diff --git a/monetdb5/modules/kernel/alarm.mal b/monetdb5/modules/kernel/alarm.mal --- a/monetdb5/modules/kernel/alarm.mal +++ b/monetdb5/modules/kernel/alarm.mal @@ -6,9 +6,17 @@ module alarm; -unsafe command alarm.sleep(secs:int):void +unsafe pattern alarm.sleep(msecs:int) :void +address ALARMsleep +comment "Sleep a few milliseconds"; + +unsafe pattern alarm.sleep(msecs:int) :int address ALARMsleep -comment "Sleep a few seconds"; +comment "Sleep a few milliseconds and return the slept value"; + +unsafe pattern alarm.sleep(msecs:bat[:int]) :bat[:int] +address ALARMsleep +comment "Sleep a few milliseconds and return the slept value"; unsafe command alarm.usec() :lng address ALARMusec diff --git a/sql/ChangeLog b/sql/ChangeLog --- a/sql/ChangeLog +++ b/sql/ChangeLog @@ -1,6 +1,11 @@ # ChangeLog file for sql # This file is updated with Maddlog +* Thu Jan 23 2020 Pedro Ferreira <pedro.ferre...@monetdbsolutions.com> +- Added sys.sleep(int n) procedure, which makes the client's thread to + sleep for n milliseconds. Also added the function version, where it + returns the input value as result. + * Tue Dec 17 2019 Pedro Ferreira <pedro.ferre...@monetdbsolutions.com> - Added prepared_statements_args view, which details the arguments for the prepared statements created in the current session. diff --git a/sql/backends/monet5/sql_upgrades.c b/sql/backends/monet5/sql_upgrades.c --- a/sql/backends/monet5/sql_upgrades.c +++ b/sql/backends/monet5/sql_upgrades.c @@ -2497,10 +2497,14 @@ sql_update_default(Client c, mvc *sql, c " external name mdb.\"setDebug\";\n" "create function sys.debugflags()\n" " returns table(flag string, val bool)\n" - " external name mdb.\"getDebugFlags\";\n"); + " external name mdb.\"getDebugFlags\";\n" + "create procedure sys.\"sleep\"(msecs int)\n" + " external name \"alarm\".\"sleep\";\n" + "create function sys.\"sleep\"(msecs int) returns integer\n" + " external name \"alarm\".\"sleep\";\n"); pos += snprintf(buf + pos, bufsize - pos, "update sys.functions set system = true where schema_id = (select id from sys.schemas where name = 'sys')" - " and name in ('debug', 'debugflags');\n"); + " and name in ('debug', 'debugflags', 'sleep');\n"); /* 26_sysmon */ t = mvc_bind_table(sql, sys, "queue"); diff --git a/sql/scripts/25_debug.sql b/sql/scripts/25_debug.sql --- a/sql/scripts/25_debug.sql +++ b/sql/scripts/25_debug.sql @@ -54,11 +54,11 @@ create procedure sys.flush_log () -- Helper function to disable the log merger create procedure suspend_log_flushing() - external name sql.suspend_log_flushing; + external name sql.suspend_log_flushing; -- Helper function to enable the log merger create procedure resume_log_flushing() - external name sql.resume_log_flushing; + external name sql.resume_log_flushing; create function sys.debug(debug int) returns integer external name mdb."setDebug"; @@ -71,13 +71,21 @@ create function sys.debugflags() external name mdb."getDebugFlags"; create function sys.deltas ("schema" string) - returns table ("id" int, "cleared" boolean, "immutable" bigint, "inserted" bigint, "updates" bigint, "deletes" bigint, "level" int) - external name "sql"."deltas"; + returns table ("id" int, "cleared" boolean, "immutable" bigint, "inserted" bigint, "updates" bigint, "deletes" bigint, "level" int) + external name "sql"."deltas"; create function sys.deltas ("schema" string, "table" string) - returns table ("id" int, "cleared" boolean, "immutable" bigint, "inserted" bigint, "updates" bigint, "deletes" bigint, "level" int) - external name "sql"."deltas"; + returns table ("id" int, "cleared" boolean, "immutable" bigint, "inserted" bigint, "updates" bigint, "deletes" bigint, "level" int) + external name "sql"."deltas"; create function sys.deltas ("schema" string, "table" string, "column" string) - returns table ("id" int, "cleared" boolean, "immutable" bigint, "inserted" bigint, "updates" bigint, "deletes" bigint, "level" int) - external name "sql"."deltas"; + returns table ("id" int, "cleared" boolean, "immutable" bigint, "inserted" bigint, "updates" bigint, "deletes" bigint, "level" int) + external name "sql"."deltas"; + +-- Sleep procedure +create procedure sys."sleep"(msecs int) + external name "alarm"."sleep"; + +-- Sleep function +create function sys."sleep"(msecs int) returns integer + external name "alarm"."sleep"; diff --git a/sql/test/emptydb/Tests/check.stable.out b/sql/test/emptydb/Tests/check.stable.out --- a/sql/test/emptydb/Tests/check.stable.out +++ b/sql/test/emptydb/Tests/check.stable.out @@ -254,6 +254,7 @@ stdout of test 'check` in directory 'sql \dSf sys."shpload" \dSf sys."shrink" \dSf sys."shutdown" +\dSf sys."sleep" \dSf sys."st_area" \dSf sys."st_asbinary" \dSf sys."st_asewkt" @@ -724,6 +725,8 @@ SYSTEM FUNCTION sys.sign SYSTEM FUNCTION sys.similarity SYSTEM FUNCTION sys.sin SYSTEM FUNCTION sys.sinh +SYSTEM FUNCTION sys.sleep +SYSTEM PROCEDURE sys.sleep SYSTEM FUNCTION sys.soundex SYSTEM FUNCTION sys.space SYSTEM FUNCTION sys.splitpart @@ -1174,6 +1177,8 @@ create procedure shpload(fid integer, fi create procedure shrink(sys string, tab string) external name sql.shrink; create procedure sys.shutdown(delay tinyint) external name sql.shutdown; create procedure sys.shutdown(delay tinyint, force bool) external name sql.shutdown; +create function sys."sleep"(msecs int) returns integer external name "alarm"."sleep"; +create procedure sys."sleep"(msecs int) external name "alarm"."sleep"; create function st_area(geom geometry) returns double external name geom."Area"; create function st_asbinary(geom geometry) returns string external name geom."AsBinary"; create function st_asewkt(geom geometry) returns string external name geom."AsEWKT"; @@ -3389,6 +3394,8 @@ drop function pcre_replace(string, strin [ "sys", "sin", "SYSTEM", "sin", "mmath", "Internal C", "Scalar function", false, false, false, "res_0", "real", 24, 0, "out", "arg_1", "real", 24, 0, "in", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ] [ "sys", "sinh", "SYSTEM", "sinh", "mmath", "Internal C", "Scalar function", false, false, false, "res_0", "double", 53, 0, "out", "arg_1", "double", 53, 0, "in", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ] [ "sys", "sinh", "SYSTEM", "sinh", "mmath", "Internal C", "Scalar function", false, false, false, "res_0", "real", 24, 0, "out", "arg_1", "real", 24, 0, "in", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ] +[ "sys", "sleep", "SYSTEM", "create function sys.\"sleep\"(msecs int) returns integer external name \"alarm\".\"sleep\";", "alarm", "MAL", "Scalar function", false, false, false, "result", "int", 32, 0, "out", "msecs", "int", 32, 0, "in", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ] +[ "sys", "sleep", "SYSTEM", "create procedure sys.\"sleep\"(msecs int) external name \"alarm\".\"sleep\";", "alarm", "MAL", "Procedure", true, false, false, "msecs", "int", 32, 0, "in", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ] [ "sys", "soundex", "SYSTEM", "soundex", "txtsim", "Internal C", "Scalar function", false, false, false, "res_0", "char", 0, 0, "out", "arg_1", "char", 0, 0, "in", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ] [ "sys", "soundex", "SYSTEM", "soundex", "txtsim", "Internal C", "Scalar function", false, false, false, "res_0", "clob", 0, 0, "out", "arg_1", "clob", 0, 0, "in", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ] [ "sys", "soundex", "SYSTEM", "soundex", "txtsim", "Internal C", "Scalar function", false, false, false, "res_0", "varchar", 0, 0, "out", "arg_1", "varchar", 0, 0, "in", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ] diff --git a/sql/test/emptydb/Tests/check.stable.out.32bit b/sql/test/emptydb/Tests/check.stable.out.32bit --- a/sql/test/emptydb/Tests/check.stable.out.32bit +++ b/sql/test/emptydb/Tests/check.stable.out.32bit @@ -256,6 +256,7 @@ stdout of test 'check` in directory 'sql \dSf sys."shpload" \dSf sys."shrink" \dSf sys."shutdown" +\dSf sys."sleep" \dSf sys."st_area" \dSf sys."st_asbinary" \dSf sys."st_asewkt" @@ -728,6 +729,8 @@ SYSTEM FUNCTION sys.sign SYSTEM FUNCTION sys.similarity SYSTEM FUNCTION sys.sin SYSTEM FUNCTION sys.sinh +SYSTEM FUNCTION sys.sleep +SYSTEM PROCEDURE sys.sleep SYSTEM FUNCTION sys.soundex SYSTEM FUNCTION sys.space SYSTEM FUNCTION sys.splitpart @@ -1168,6 +1171,8 @@ create procedure shpload(fid integer, fi create procedure shrink(sys string, tab string) external name sql.shrink; create procedure sys.shutdown(delay tinyint) external name sql.shutdown; create procedure sys.shutdown(delay tinyint, force bool) external name sql.shutdown; +create function sys."sleep"(msecs int) returns integer external name "alarm"."sleep"; +create procedure sys."sleep"(msecs int) external name "alarm"."sleep"; create function st_area(geom geometry) returns double external name geom."Area"; create function st_asbinary(geom geometry) returns string external name geom."AsBinary"; create function st_asewkt(geom geometry) returns string external name geom."AsEWKT"; @@ -3372,6 +3377,8 @@ drop function pcre_replace(string, strin _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list