Changeset: d6901566806b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d6901566806b
Modified Files:
sql/backends/monet5/iot/Tests/iot05.sql
sql/backends/monet5/iot/Tests/iot10.sql
sql/backends/monet5/iot/petrinet.c
sql/backends/monet5/iot/petrinet.h
Branch: iot
Log Message:
Fixing naming
- tests should be cleaned.
- show errors from query execution
diffs (192 lines):
diff --git a/sql/backends/monet5/iot/Tests/iot05.sql
b/sql/backends/monet5/iot/Tests/iot05.sql
--- a/sql/backends/monet5/iot/Tests/iot05.sql
+++ b/sql/backends/monet5/iot/Tests/iot05.sql
@@ -13,6 +13,8 @@ set cnt = 0;
-- this way their naming becomes easier, and mult-statement
-- actions are better supported.
+--However, these queries won't run because the SQL context
+--holding the variables is not generally known
create procedure clk1()
begin
set hbclk1 = hbclk1+1;
@@ -21,14 +23,19 @@ end;
create procedure clk3()
begin
set hbclk1 = hbclk1+1;
- set hbclk1 = hbclk1+1;
+ set hbclk2 = hbclk2+2;
--set cnt =(select count(*) from stmp);
end;
-- alternative is a simple query
call iot.query('iot','clk1');
call iot.query('iot','clk3');
-call iot.query('select 1;');
select * from iot.baskets();
select * from iot.queries();
+
+select hbclk1, hbclk2;
+call iot.activate();
+select hbclk1, hbclk2;
+
+
diff --git a/sql/backends/monet5/iot/Tests/iot10.sql
b/sql/backends/monet5/iot/Tests/iot10.sql
--- a/sql/backends/monet5/iot/Tests/iot10.sql
+++ b/sql/backends/monet5/iot/Tests/iot10.sql
@@ -1,19 +1,24 @@
--- introduce a heartbeat query
+-- use accumulated aggregation
set schema iot;
-set optimizer='iot_pipe';
create table tmp_aggregate(tmp_total decimal(8,2), tmp_count decimal(8,2));
insert into tmp_aggregate values(0.0,0.0);
-
create procedure collector()
begin
update tmp_aggregate
- set tmp_total = tmp_total + (select sum(val) from
iot.stream_tmp),
- tmp_count = tmp_total + (select count(*) from
iot.stream_tmp);
+ set tmp_total = tmp_total + (select sum(val) from iot.stmp),
+ tmp_count = tmp_total + (select count(*) from iot.stmp);
+ delete from iot.stmp;
end;
-iot.query('iot','collector');
+insert into stmp values('2005-09-23 12:34:26.736',1,12.34);
+select * from stmp;
+
+call iot.query('iot','collector');
select * from iot.baskets();
select * from iot.queries();
+
+call iot.activate();
+select * from tmp_aggregate;
diff --git a/sql/backends/monet5/iot/petrinet.c
b/sql/backends/monet5/iot/petrinet.c
--- a/sql/backends/monet5/iot/petrinet.c
+++ b/sql/backends/monet5/iot/petrinet.c
@@ -150,7 +150,7 @@ PNregisterInternal(Client cntxt, MalBlkP
pnet[pnettop].modname = GDKstrdup(getModuleId(sig));
pnet[pnettop].fcnname = GDKstrdup(getFunctionId(sig));
snprintf(buf,IDLENGTH,"petri_%d",pnettop);
- s = newFunction("iot", buf, FUNCTIONsymbol);
+ s = newFunction(iotRef, putName(buf,strlen(buf)), FUNCTIONsymbol);
nmb = s->def;
setArgType(nmb, nmb->stmt[0],0, TYPE_void);
(void) newStmt(nmb, sqlRef, transactionRef);
@@ -304,6 +304,7 @@ PNexecute( void *n)
{
PNnode *node= (PNnode *) n;
int i,j, idx;
+ str msg= MAL_SUCCEED;
_DEBUG_PETRINET_ mnstr_printf(PNout, "#petrinet.execute
%s.%s\n",node->modname, node->fcnname);
// first grab exclusive access to all streams.
MT_lock_set(&iotLock);
@@ -315,10 +316,10 @@ PNexecute( void *n)
_DEBUG_PETRINET_ mnstr_printf(PNout, "#petrinet.execute %s.%s all
locked\n",node->modname, node->fcnname);
- runMALsequence(mal_clients, node->mb, 1, 0, node->stk, 0, 0);
+ msg = runMALsequence(mal_clients, node->mb, 1, 0, node->stk, 0, 0);
node->status = PNPAUSED;
- _DEBUG_PETRINET_ mnstr_printf(PNout, "#petrinet.execute %s.%s
transition done\n",node->modname, node->fcnname);
+ _DEBUG_PETRINET_ mnstr_printf(PNout, "#petrinet.execute %s.%s
transition done:%s\n",node->modname, node->fcnname, (msg !=
MAL_SUCCEED?msg:""));
MT_lock_set(&iotLock);
for ( i=0; i< j && node->enabled && node->places[i]; i++) {
@@ -330,7 +331,7 @@ PNexecute( void *n)
}
static void
-PNcontroller(void *dummy)
+PNscheduler(void *dummy)
{
int idx = -1, i, j;
int k = -1;
@@ -339,6 +340,7 @@ PNcontroller(void *dummy)
str msg = MAL_SUCCEED;
lng t, analysis, now;
int claimed[MAXBSKT];
+ timestamp ts, tn;
_DEBUG_PETRINET_ mnstr_printf(PNout, "#petrinet.controller started\n");
cntxt = mal_clients; /* run as admin in SQL mode*/
@@ -348,7 +350,6 @@ PNcontroller(void *dummy)
status = PNRUNNING;
while( pnettop > 0){
- _DEBUG_PETRINET_ mnstr_printf(PNout, "#petrinet.controller next
step\n");
if (cycleDelay)
MT_sleep_ms(cycleDelay); /* delay to make it more
tractable */
while (status == PNPAUSED) { /* scheduler is paused */
@@ -365,8 +366,9 @@ PNcontroller(void *dummy)
now = GDKusec();
for (k = i = 0; i < pnettop; i++)
if ( pnet[i].status == PNRUNNING ){
+ pnet[i].enabled = 1;
+
// check if all baskets are available and non-empty
- pnet[i].enabled = 1;
for (j = 0; j < MAXBSKT && pnet[i].enabled &&
pnet[i].places[j]; j++) {
idx = pnet[i].places[j];
if (baskets[idx].status == BSKTRUNNING &&
@@ -374,11 +376,7 @@ PNcontroller(void *dummy)
pnet[i].enabled = 0;
break;
}
- }
- if (pnet[i].enabled) {
- timestamp ts, tn;
/* only look at large enough baskets */
- /* check heart beat delays */
if (baskets[idx].beat) {
(void) MTIMEunix_epoch(&ts);
(void) MTIMEtimestamp_add(&tn,
&baskets[idx].seen, &baskets[idx].beat);
@@ -387,6 +385,9 @@ PNcontroller(void *dummy)
break;
}
}
+ }
+
+ if (pnet[i].enabled) {
/* a basket can enable at most one transition */
for (j = 0; j < MAXBSKT && pnet[i].enabled &&
pnet[i].places[j]; j++)
if( claimed[pnet[i].places[j]]){
@@ -414,7 +415,6 @@ PNcontroller(void *dummy)
if (pnet[i].enabled ) {
_DEBUG_PETRINET_ mnstr_printf(PNout, "#Run
transition %s \n", pnet[i].fcnname);
- (void)
MTIMEcurrent_timestamp(&baskets[idx].seen);
t = GDKusec();
pnet[i].cycles++;
// Fork MAL execution thread
@@ -456,9 +456,9 @@ PNstartScheduler(void)
int s;
(void) s;
- _DEBUG_PETRINET_ mnstr_printf(PNout, "#Start PNcontroller\n");
- if (status== PNINIT && MT_create_thread(&pid, PNcontroller, &s,
MT_THR_JOINABLE) != 0){
- _DEBUG_PETRINET_ mnstr_printf(PNout, "#Start PNcontroller
failed\n");
+ _DEBUG_PETRINET_ mnstr_printf(PNout, "#Start PNscheduler\n");
+ if (status== PNINIT && MT_create_thread(&pid, PNscheduler, &s,
MT_THR_JOINABLE) != 0){
+ _DEBUG_PETRINET_ mnstr_printf(PNout, "#Start PNscheduler
failed\n");
GDKerror( "petrinet creation failed");
}
(void) pid;
diff --git a/sql/backends/monet5/iot/petrinet.h
b/sql/backends/monet5/iot/petrinet.h
--- a/sql/backends/monet5/iot/petrinet.h
+++ b/sql/backends/monet5/iot/petrinet.h
@@ -25,7 +25,7 @@
#define _DEBUG_PETRINET_ if(1)
-#define PNout mal_clients[0].fdout
+#define PNout mal_clients[1].fdout
/*#define _BASKET_SIZE_*/
#ifdef WIN32
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list