MonetDB: default - Implemented a MNSTR_TIMEOUT error type for st...

2014-03-26 Thread Sjoerd Mullender
Changeset: a7ffb37fdf0b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a7ffb37fdf0b
Modified Files:
common/stream/stream.c
common/stream/stream.h
monetdb5/mal/mal_client.c
Branch: default
Log Message:

Implemented a MNSTR_TIMEOUT error type for streams.
When a read timeout is set (mnstr_settimeout() on a read stream),
socket reads may time out.  If they do, they return an error and set
mnstr_errnr() to MNSTR_TIMEOUT (or they return the data read so far,
if any).  Upper layers will need to deal with this.  One instance of
this has been implemented.
(Note, we don't actually set the timeout yet.)


diffs (75 lines):

diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -502,6 +502,9 @@ error(stream *s)
case MNSTR_WRITE_ERROR:
snprintf(buf, BUFSIZ, "error writing file %s\n", s->name);
return strdup(buf);
+   case MNSTR_TIMEOUT:
+   snprintf(buf, BUFSIZ, "timeout on %s\n", s->name);
+   return strdup(buf);
}
return strdup("Unknown error");
 }
@@ -1518,7 +1521,10 @@ socket_write(stream *s, const void *buf,
if ((size_t) res >= elmsize)
return (ssize_t) (res / elmsize);
if (nr < 0) {
-   s->errnr = MNSTR_WRITE_ERROR;
+   if (s->timeout > 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
+   s->errnr = MNSTR_TIMEOUT;
+   else
+   s->errnr = MNSTR_WRITE_ERROR;
return -1;
}
return 0;
@@ -1546,7 +1552,10 @@ socket_read(stream *s, void *buf, size_t
nr = read(s->stream_data.s, (char *) buf + s->len, size - s->len);
 #endif
if (nr == -1) {
-   s->errnr = MNSTR_READ_ERROR;
+   if (s->timeout > 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
+   s->errnr = MNSTR_TIMEOUT;
+   else
+   s->errnr = MNSTR_READ_ERROR;
return -1;
}
if (nr == 0)
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -236,7 +236,8 @@ typedef enum mnstr_errors {
MNSTR_NO__ERROR = 0,
MNSTR_OPEN_ERROR,
MNSTR_READ_ERROR,
-   MNSTR_WRITE_ERROR
+   MNSTR_WRITE_ERROR,
+   MNSTR_TIMEOUT
 } mnstr_errors;
 
 #endif /*_STREAM_H_*/
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -526,7 +526,20 @@ MCreadClient(Client c)
mnstr_flush(c->fdout);
in->eof = 0;
}
-   while ((rd = bstream_next(in)) > 0 && !in->eof) {
+   for (;;) {
+   rd = bstream_next(in);
+   if (GDKexiting())
+   return 0;
+   if (rd < 0) {
+   if (mnstr_errnr(in->s) == MNSTR_TIMEOUT) {
+   mnstr_clearerr(in->s);
+   continue;
+   }
+   /* read error */
+   return 0;
+   }
+   if (in->eof)
+   break;
sum += rd;
if (!in->mode) /* read one line at a time in line mode 
*/
break;
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merge with Jan2014 branch.

2014-03-26 Thread Sjoerd Mullender
Changeset: a005b45fe545 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a005b45fe545
Modified Files:
common/stream/stream.c
Branch: default
Log Message:

Merge with Jan2014 branch.


diffs (truncated from 507 to 300 lines):

diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -149,9 +149,9 @@ struct stream {
} stream_data;
int errnr;
ssize_t (*read) (stream *s, void *buf, size_t elmsize, size_t cnt);
-   ssize_t (*readline) (stream *s, void *buf, size_t maxcnt);
ssize_t (*write) (stream *s, const void *buf, size_t elmsize, size_t 
cnt);
void (*close) (stream *s);
+   void (*clrerr) (stream *s);
char *(*error) (stream *s);
void (*destroy) (stream *s);
int (*flush) (stream *s);
@@ -159,6 +159,11 @@ struct stream {
int (*fgetpos) (stream *s, lng *p);
int (*fsetpos) (stream *s, lng p);
void (*update_timeout) (stream *s);
+   /* in case read() read a non-integral number of elements we
+* save the last partial element here (only used in
+* socket_read() */
+   void *buf;
+   size_t len;
 };
 
 int
@@ -198,30 +203,61 @@ mnstr_read(stream *s, void *buf, size_t 
return (*s->read) (s, buf, elmsize, cnt);
 }
 
-/* Read one line (seperated by \n) of atmost maxcnt characters from
+/* Read one line (seperated by \n) of at most maxcnt-1 characters from
  * the stream.  Returns the number of characters actually read,
- * includes the trailing \n */
+ * includes the trailing \n; terminated by a NULL byte. */
 ssize_t
 mnstr_readline(stream *s, void *buf, size_t maxcnt)
 {
+   char *b = buf, *start = buf;
+
 #ifdef STREAM_DEBUG
printf("readline %s " SZFMT "\n", s->name ? s->name : "", 
maxcnt);
 #endif
assert(s->access == ST_READ);
if (s->errnr)
return -1;
-   if (!s->readline) {
-   size_t len = 0;
-   char *b = buf, *start = buf;
-   while ((*s->read) (s, start, 1, 1) > 0 && len < maxcnt) {
-   if (*start++ == '\n')
-   break;
+   if (maxcnt == 0)
+   return 0;
+   if (maxcnt == 1) {
+   *start = 0;
+   return 0;
+   }
+   for (;;) {
+   switch ((*s->read)(s, start, 1, 1)) {
+   case 1:
+   /* successfully read a character,
+* check whether it is the line
+* separator and whether we have space
+* left for more */
+   if (*start++ == '\n' || --maxcnt == 1) {
+   *start = 0;
+#if 0
+   if (s->type == ST_ASCII &&
+   start[-1] == '\n' &&
+   start > b + 1 &&
+   start[-2] == '\r') {
+   /* convert CR-LF to just LF */
+   start[-2] = start[-1];
+   start--;
+   }
+#endif
+   return (ssize_t) (start - b);
+   }
+   break;
+   case -1:
+   /* error: if we didn't read anything yet,
+* return the error, otherwise return what we
+* have */
+   if (start == b)
+   return -1;
+   /* fall through */
+   case 0:
+   /* end of file: return what we have */
+   *start = 0;
+   return (ssize_t) (start - b);
}
-   if (s->errnr)
-   return -1;
-   return (ssize_t) (start - b);
-   } else
-   return (*s->readline) (s, buf, maxcnt);
+   }
 }
 
 /* Write cnt elements of size elmsize to the stream.  Returns the
@@ -361,8 +397,11 @@ mnstr_errnr(stream *s)
 void
 mnstr_clearerr(stream *s)
 {
-   if (s != NULL)
+   if (s != NULL) {
s->errnr = MNSTR_NO__ERROR;
+   if (s->clrerr)
+   (*s->clrerr) (s);
+   }
 }
 
 int
@@ -442,6 +481,8 @@ get_extention(const char *file)
 static void
 destroy(stream *s)
 {
+   if (s->buf)
+   free(s->buf);
free(s->name);
free(s);
 }
@@ -481,9 +522,9 @@ create_stream(const char *name)
s->errnr = MNSTR_NO__ERROR;
s->stream_data.p = NULL;
s->read = NULL;
-   s->readline = NULL;
s->write = NULL;
s->close = NULL;
+   s->clrerr = NULL;
s->error = error;
s->destroy = destroy;
s->flush = NULL;
@@ -492,6 +533,8 @@ create_stream(const char *name)
s->fsetpos = NULL;
s-

MonetDB: Jan2014 - Propagate errors up, propagate error clearing...

2014-03-26 Thread Sjoerd Mullender
Changeset: ef558e1a0506 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ef558e1a0506
Modified Files:
common/stream/stream.c
Branch: Jan2014
Log Message:

Propagate errors up, propagate error clearing down, cleanup.

The mnstr_readline function is now defined similarly to the fgets
library function in that it reads at most one fewer bytes than the
size of the buffer, and that the result is null terminated.
Removed socket_readline since it was basically the same as
mnstr_readline itself.  And since this was the only specialized
readline function, removed the readline function pointer from the
stream structure.
Added a clrerr function pointer to the stream structure that is used
to clear errors from layered streams.
Simplified socket_read to not contain a loop.  The upper layers need
to do the loop already, so no sense in doing that at multiple levels.
If socket_read is called with an element size greater than 1, and if
the read/recv returns an incomplete record, we now save that record
for the next call.  (This may be useful when we have a relatively
short socket read timeout.)


diffs (truncated from 507 to 300 lines):

diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -149,9 +149,9 @@ struct stream {
} stream_data;
int errnr;
ssize_t (*read) (stream *s, void *buf, size_t elmsize, size_t cnt);
-   ssize_t (*readline) (stream *s, void *buf, size_t maxcnt);
ssize_t (*write) (stream *s, const void *buf, size_t elmsize, size_t 
cnt);
void (*close) (stream *s);
+   void (*clrerr) (stream *s);
char *(*error) (stream *s);
void (*destroy) (stream *s);
int (*flush) (stream *s);
@@ -159,6 +159,11 @@ struct stream {
int (*fgetpos) (stream *s, lng *p);
int (*fsetpos) (stream *s, lng p);
void (*update_timeout) (stream *s);
+   /* in case read() read a non-integral number of elements we
+* save the last partial element here (only used in
+* socket_read() */
+   void *buf;
+   size_t len;
 };
 
 int
@@ -198,30 +203,61 @@ mnstr_read(stream *s, void *buf, size_t 
return (*s->read) (s, buf, elmsize, cnt);
 }
 
-/* Read one line (seperated by \n) of atmost maxcnt characters from
+/* Read one line (seperated by \n) of at most maxcnt-1 characters from
  * the stream.  Returns the number of characters actually read,
- * includes the trailing \n */
+ * includes the trailing \n; terminated by a NULL byte. */
 ssize_t
 mnstr_readline(stream *s, void *buf, size_t maxcnt)
 {
+   char *b = buf, *start = buf;
+
 #ifdef STREAM_DEBUG
printf("readline %s " SZFMT "\n", s->name ? s->name : "", 
maxcnt);
 #endif
assert(s->access == ST_READ);
if (s->errnr)
return -1;
-   if (!s->readline) {
-   size_t len = 0;
-   char *b = buf, *start = buf;
-   while ((*s->read) (s, start, 1, 1) > 0 && len < maxcnt) {
-   if (*start++ == '\n')
-   break;
+   if (maxcnt == 0)
+   return 0;
+   if (maxcnt == 1) {
+   *start = 0;
+   return 0;
+   }
+   for (;;) {
+   switch ((*s->read)(s, start, 1, 1)) {
+   case 1:
+   /* successfully read a character,
+* check whether it is the line
+* separator and whether we have space
+* left for more */
+   if (*start++ == '\n' || --maxcnt == 1) {
+   *start = 0;
+#if 0
+   if (s->type == ST_ASCII &&
+   start[-1] == '\n' &&
+   start > b + 1 &&
+   start[-2] == '\r') {
+   /* convert CR-LF to just LF */
+   start[-2] = start[-1];
+   start--;
+   }
+#endif
+   return (ssize_t) (start - b);
+   }
+   break;
+   case -1:
+   /* error: if we didn't read anything yet,
+* return the error, otherwise return what we
+* have */
+   if (start == b)
+   return -1;
+   /* fall through */
+   case 0:
+   /* end of file: return what we have */
+   *start = 0;
+   return (ssize_t) (start - b);
}
-   if (s->errnr)
-   return -1;
-   return (ssize_t) (start - b);
-   } else
-   return (*s->readline) (s, buf, maxcnt);
+   }
 }
 
 /* Write cnt elemen

MonetDB: Jan2014 - generalized isMatOp

2014-03-26 Thread Niels Nes
Changeset: fbef2821e2a1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fbef2821e2a1
Modified Files:
monetdb5/optimizer/opt_support.c
Branch: Jan2014
Log Message:

generalized isMatOp


diffs (20 lines):

diff --git a/monetdb5/optimizer/opt_support.c b/monetdb5/optimizer/opt_support.c
--- a/monetdb5/optimizer/opt_support.c
+++ b/monetdb5/optimizer/opt_support.c
@@ -828,13 +828,9 @@ int isAllScalar(MalBlkPtr mb, InstrPtr p
 int isMapOp(InstrPtr p){
return  getModuleId(p) &&
((getModuleId(p) == malRef && getFunctionId(p) == multiplexRef) 
||
-   (getModuleId(p)== batcalcRef && getFunctionId(p) != mark_grpRef 
&& getFunctionId(p) != rank_grpRef) ||
-   (getModuleId(p)== batmtimeRef) ||
-   (getModuleId(p)== batstrRef) ||
-   (getModuleId(p)== batmmathRef) ||
-   (getModuleId(p)== batxmlRef) ||
-   (strcmp(getModuleId(p),"batsql") == 0) ||
-   (getModuleId(p)== mkeyRef));
+   (getModuleId(p) == batcalcRef && getFunctionId(p) != 
mark_grpRef && getFunctionId(p) != rank_grpRef) ||
+   (getModuleId(p) != batcalcRef && strncmp(getModuleId(p), "bat", 
3) == 0) ||
+   (getModuleId(p) == mkeyRef));
 }
 
 int isLikeOp(InstrPtr p){
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - merged with Jan2014

2014-03-26 Thread Niels Nes
Changeset: d519f022c93d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d519f022c93d
Modified Files:
monetdb5/optimizer/opt_support.c
Branch: default
Log Message:

merged with Jan2014


diffs (20 lines):

diff --git a/monetdb5/optimizer/opt_support.c b/monetdb5/optimizer/opt_support.c
--- a/monetdb5/optimizer/opt_support.c
+++ b/monetdb5/optimizer/opt_support.c
@@ -840,13 +840,9 @@ int isAllScalar(MalBlkPtr mb, InstrPtr p
 int isMapOp(InstrPtr p){
return  getModuleId(p) &&
((getModuleId(p) == malRef && getFunctionId(p) == multiplexRef) 
||
-   (getModuleId(p)== batcalcRef && getFunctionId(p) != mark_grpRef 
&& getFunctionId(p) != rank_grpRef) ||
-   (getModuleId(p)== batmtimeRef) ||
-   (getModuleId(p)== batstrRef) ||
-   (getModuleId(p)== batmmathRef) ||
-   (getModuleId(p)== batxmlRef) ||
-   (strcmp(getModuleId(p),"batsql") == 0) ||
-   (getModuleId(p)== mkeyRef));
+   (getModuleId(p) == batcalcRef && getFunctionId(p) != 
mark_grpRef && getFunctionId(p) != rank_grpRef) ||
+   (getModuleId(p) != batcalcRef && strncmp(getModuleId(p), "bat", 
3) == 0) ||
+   (getModuleId(p) == mkeyRef));
 }
 
 int isLikeOp(InstrPtr p){
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - A few more fixes in datacell

2014-03-26 Thread Martin Kersten
Changeset: 85e320911054 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=85e320911054
Modified Files:
sql/backends/monet5/datacell/Tests/scenario04.stable.out
sql/backends/monet5/datacell/basket.c
sql/backends/monet5/datacell/datacell.c
sql/backends/monet5/datacell/petrinet.c
Branch: default
Log Message:

A few more fixes in datacell
compilation of functions seem to work
7 tests still fail.


diffs (117 lines):

diff --git a/sql/backends/monet5/datacell/Tests/scenario04.stable.out 
b/sql/backends/monet5/datacell/Tests/scenario04.stable.out
--- a/sql/backends/monet5/datacell/Tests/scenario04.stable.out
+++ b/sql/backends/monet5/datacell/Tests/scenario04.stable.out
@@ -1,33 +1,50 @@
 stdout of test 'scenario04` in directory 'sql/backends/monet5/datacell` itself:
 
 
-# 16:50:39 >  
-# 16:50:39 >   mserver5  --debug=10 --set gdk_nr_threads=0  --set 
"gdk_dbfarm=/net/rig.ins.cwi.nl/export/scratch0/manegold/Monet/HG/Aug2011/prefix/--enable-datacell_--disable-debug_--enable-optimize_--disable-assert/var/MonetDB"
 --set mapi_open=true --set mapi_port=36254 --set monet_prompt= --trace 
--forcemito --set mal_listing=2  "--dbname=mTests_backends_monet5_datacell" 
--set mal_listing=0 ; echo ; echo Over..
-# 16:50:39 >  
+# 15:16:33 >  
+# 15:16:33 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=38868" "--set" 
"mapi_usock=/var/tmp/mtest-23824/.s.monetdb.38868" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/export/scratch1/mk/current//Linux/var/MonetDB/mTests_sql_backends_monet5_datacell"
 "--set" "mal_listing=0"
+# 15:16:33 >  
 
-# MonetDB 5 server v11.5.0
+# MonetDB 5 server v11.18.0
 # This is an unreleased version
-# Serving database 'mTests_backends_monet5_datacell', using 4 threads
+# Serving database 'mTests_sql_backends_monet5_datacell', using 8 threads
 # Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically 
linked
-# Found 7.749 GiB available main-memory.
+# Found 15.591 GiB available main-memory.
 # Copyright (c) 1993-July 2008 CWI.
 # Copyright (c) August 2008-2014 MonetDB B.V., all rights reserved
 # Visit http://www.monetdb.org/ for further information
-# Listening for connection requests on mapi:monetdb://rig.ins.cwi.nl:36254/
+# Listening for connection requests on mapi:monetdb://vienna.ins.cwi.nl:38868/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-23824/.s.monetdb.38868
 # MonetDB/GIS module loaded
+# MonetDB/JAQL module loaded
 # MonetDB/SQL module loaded
-# MonetDB/DataCell module loaded
+# MonetDB/DataCell loaded
 
 Ready.
 
+# 15:16:33 >  
+# 15:16:33 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-23824" "--port=38868"
+# 15:16:33 >  
 
-# 16:50:39 >  
-# 16:50:39 >  mclient -lsql -ftest -i -e --host=rig --port=36254 
-# 16:50:39 >  
+#set optimizer='datacell_pipe';
+#create table datacell.winin(
+#id integer,
+#tag timestamp,
+#payload integer
+#);
+#create table datacell.winout( tag timestamp, mi integer, ma integer, su 
bigint);
+#call datacell.dump();
+#baskets[ 1] datacell.winin columns 3 threshold 0 window=[0,0] time 
window=[0,0] beat 0 milliseconds events 0
+#baskets[ 2] datacell.winout columns 4 threshold 0 window=[0,0] time 
window=[0,0] beat 0 milliseconds events 0
+#receptor datacell.winin at localhost:50504 protocol=TCP mode=passive 
status=running delay=1000 
+#emitter datacell.winout at localhost:50604 protocol=UDP mode=active 
status=running delay=1000
+#scheduler status running
+#[0]   datacell.mavg running delay 0 cycles 0 events 0 time 0 ms
+#<--   datacell.winin basket[1] 0 0
+#drop table datacell.winin;
+#drop table datacell.winout;
 
-= to be checked / approved !
+# 15:16:34 >  
+# 15:16:34 >  "Done."
+# 15:16:34 >  
 
-# 16:50:40 >  
-# 16:50:40 >  Done.
-# 16:50:40 >  
-
diff --git a/sql/backends/monet5/datacell/basket.c 
b/sql/backends/monet5/datacell/basket.c
--- a/sql/backends/monet5/datacell/basket.c
+++ b/sql/backends/monet5/datacell/basket.c
@@ -174,6 +174,8 @@ BSKTregister(Client cntxt, MalBlkPtr mb,
char buf[BUFSIZ], *lsch, *ltbl;
str tbl;
 
+   if ( msg != MAL_SUCCEED)
+   return msg;
BSKTelements(tbl = *(str *) getArgReference(stk, pci, 1), buf, &lsch, 


MonetDB: default - Extended test with pqueue_max

2014-03-26 Thread Martin Kersten
Changeset: eaa896b25a0d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=eaa896b25a0d
Modified Files:
monetdb5/modules/mal/Tests/pqueue.mal
monetdb5/modules/mal/Tests/pqueue.stable.out
Branch: default
Log Message:

Extended test with pqueue_max


diffs (133 lines):

diff --git a/monetdb5/modules/mal/Tests/pqueue.mal 
b/monetdb5/modules/mal/Tests/pqueue.mal
--- a/monetdb5/modules/mal/Tests/pqueue.mal
+++ b/monetdb5/modules/mal/Tests/pqueue.mal
@@ -29,3 +29,23 @@ bp:= pqueue.topn_min(b,7:wrd,false);
 io.print(bp);
 bp:= pqueue.topn_min(b,8:wrd,false);
 io.print(bp);
+
+bp:= pqueue.topn_max(b,0:wrd,false);
+io.print(bp);
+bp:= pqueue.topn_max(b,1:wrd,false);
+io.print(bp);
+bp:= pqueue.topn_max(b,2:wrd,false);
+io.print(bp);
+bp:= pqueue.topn_max(b,3:wrd,false);
+io.print(bp);
+bp:= pqueue.topn_max(b,4:wrd,false);
+io.print(bp);
+bp:= pqueue.topn_max(b,5:wrd,false);
+io.print(bp);
+bp:= pqueue.topn_max(b,6:wrd,false);
+io.print(bp);
+bp:= pqueue.topn_max(b,7:wrd,false);
+io.print(bp);
+bp:= pqueue.topn_max(b,8:wrd,false);
+io.print(bp);
+
diff --git a/monetdb5/modules/mal/Tests/pqueue.stable.out 
b/monetdb5/modules/mal/Tests/pqueue.stable.out
--- a/monetdb5/modules/mal/Tests/pqueue.stable.out
+++ b/monetdb5/modules/mal/Tests/pqueue.stable.out
@@ -47,6 +47,24 @@ function user.main():void;
 io.print(bp);
 bp := pqueue.topn_min(b,8:wrd,false);
 io.print(bp);
+bp := pqueue.topn_max(b,0:wrd,false);
+io.print(bp);
+bp := pqueue.topn_max(b,1:wrd,false);
+io.print(bp);
+bp := pqueue.topn_max(b,2:wrd,false);
+io.print(bp);
+bp := pqueue.topn_max(b,3:wrd,false);
+io.print(bp);
+bp := pqueue.topn_max(b,4:wrd,false);
+io.print(bp);
+bp := pqueue.topn_max(b,5:wrd,false);
+io.print(bp);
+bp := pqueue.topn_max(b,6:wrd,false);
+io.print(bp);
+bp := pqueue.topn_max(b,7:wrd,false);
+io.print(bp);
+bp := pqueue.topn_max(b,8:wrd,false);
+io.print(bp);
 end main;
 #--#
 # ht  # name
@@ -130,6 +148,77 @@ end main;
 [ 4@0, 6@0  ]
 [ 5@0, 5@0  ]
 [ 6@0, 4@0  ]
+#--#
+# ht  # name
+# void oid  # type
+#--#
+#--#
+# ht  # name
+# void oid  # type
+#--#
+[ 0@0, 4@0  ]
+#--#
+# ht  # name
+# void oid  # type
+#--#
+[ 0@0, 4@0  ]
+[ 1@0, 5@0  ]
+#--#
+# ht  # name
+# void oid  # type
+#--#
+[ 0@0, 4@0  ]
+[ 1@0, 5@0  ]
+[ 2@0, 6@0  ]
+#--#
+# ht  # name
+# void oid  # type
+#--#
+[ 0@0, 4@0  ]
+[ 1@0, 5@0  ]
+[ 2@0, 6@0  ]
+[ 3@0, 3@0  ]
+#--#
+# ht  # name
+# void oid  # type
+#--#
+[ 0@0, 4@0  ]
+[ 1@0, 5@0  ]
+[ 2@0, 6@0  ]
+[ 3@0, 3@0  ]
+[ 4@0, 2@0  ]
+#--#
+# ht  # name
+# void oid  # type
+#--#
+[ 0@0, 4@0  ]
+[ 1@0, 5@0  ]
+[ 2@0, 6@0  ]
+[ 3@0, 3@0  ]
+[ 4@0, 2@0  ]
+[ 5@0, 0@0  ]
+#--#
+# ht  # name
+# void oid  # type
+#--#
+[ 0@0, 4@0  ]
+[ 1@0, 5@0  ]
+[ 2@0, 6@0  ]
+[ 3@0, 3@0  ]
+[ 4@0, 2@0  ]
+[ 5@0, 0@0  ]
+[ 6@0, 1@0  ]
+#--#
+# ht  # name
+# void oid  # type
+#--#
+[ 0@0, 4@0  ]
+[ 1@0, 5@0  ]
+[ 2@0, 6@0  ]
+[ 3@0, 3@0  ]
+[ 4@0, 2@0  ]
+[ 5@0, 0@0  ]
+[ 6@0, 1@0  ]
 
 # 21:06:19 >  
 # 21:06:19 >  "Done."
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Make SQL procedure compilation visible

2014-03-26 Thread Martin Kersten
Changeset: d8fe9f2108fb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d8fe9f2108fb
Modified Files:
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/sql_gencode.h
Branch: default
Log Message:

Make SQL procedure compilation visible


diffs (22 lines):

diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -2366,7 +2366,7 @@ monet5_resolve_function(ptr M, sql_func 
 }
 
 /* TODO handle aggr */
-static int
+int
 backend_create_func(backend *be, sql_func *f, list *restypes, list *ops)
 {
mvc *m = be->mvc;
diff --git a/sql/backends/monet5/sql_gencode.h 
b/sql/backends/monet5/sql_gencode.h
--- a/sql/backends/monet5/sql_gencode.h
+++ b/sql/backends/monet5/sql_gencode.h
@@ -34,5 +34,6 @@ sql5_export void backend_call(backend *b
 sql5_export void initSQLreferences(void);
 sql5_export str backend_name(cq *cq);
 sql5_export int monet5_resolve_function(ptr M, sql_func *f);
+sql5_export int backend_create_func(backend *be, sql_func *f, list *restypes, 
list *ops);
 
 #endif /* _SQL2MAL_H */
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Add # debugging markers

2014-03-26 Thread Martin Kersten
Changeset: c9f7e8d7e297 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c9f7e8d7e297
Modified Files:
gdk/gdk_logger.c
Branch: default
Log Message:

Add # debugging markers


diffs (truncated from 314 to 300 lines):

diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -18,12 +18,8 @@
  */
 
 /*
- * @f gdk_logger
- * @t Transactions
- * @a N. J. Nes
- * @v 2.0
+ * (author) N. J. Nes
  *
- * @* Introduction
  * In the philosophy of MonetDB, transaction management overhead
  * should only be paid when necessary. Transaction management is for
  * this purpose implemented as a separate module and applications are
@@ -38,7 +34,7 @@
  * file stores information about the version of the logger and the
  * transaction log files. This file is a simple ascii file with the
  * following format:
- *  @code{6DIGIT-VERSION\n[log file number \n]*]*}
+ *  {6DIGIT-VERSION\n[log file number \n]*]*}
  * The transaction log files have a binary format, which stores fixed
  * size logformat headers (flag,nr,bid), where the flag is the type of
  * update logged.  The nr field indicates how many changes there were
@@ -67,8 +63,6 @@
  * or abort on the changed bats. Once all logs have been read, the
  * changes to the bats are made persistent, i.e. a bbp sub-commit is
  * done.
- *
- * @* Implementation Code
  */
 #include "monetdb_config.h"
 #include "gdk.h"
@@ -201,7 +195,7 @@ static void
 log_read_clear(logger *lg, trans *tr, char *name)
 {
if (lg->debug & 1)
-   fprintf(stderr, "logger found log_read_clear %s\n", name);
+   fprintf(stderr, "#logger found log_read_clear %s\n", name);
 
if (tr_grow(tr)) {
tr->changes[tr->nr].type = LOG_CLEAR;
@@ -216,6 +210,8 @@ la_bat_clear(logger *lg, logaction *la)
log_bid bid = logger_find_bat(lg, la->name);
BAT *b;
 
+   if (lg->debug & 1)
+   fprintf(stderr, "#la_bat_clear %s\n", la->name);
/* do we need to skip these old updates */
if (BATcount(lg->snapshots_bid)) {
BUN p = BUNfndT(lg->snapshots_bid, &bid);
@@ -266,7 +262,7 @@ log_read_updates(logger *lg, trans *tr, 
int ht = -1, tt = -1, hseq = 0, tseq = 0;
 
if (lg->debug & 1)
-   fprintf(stderr, "logger found log_read_updates %s %s %d\n", 
name, l->flag == LOG_INSERT ? "insert" : l->flag == LOG_DELETE ? "delete" : 
"update", l->nr);
+   fprintf(stderr, "#logger found log_read_updates %s %s %d\n", 
name, l->flag == LOG_INSERT ? "insert" : l->flag == LOG_DELETE ? "delete" : 
"update", l->nr);
 
if (b) {
ht = b->htype;
@@ -498,7 +494,7 @@ log_read_create(logger *lg, trans *tr, c
char *buf = log_read_string(lg);
 
if (lg->debug & 1)
-   fprintf(stderr, "log_read_create %s\n", name);
+   fprintf(stderr, "#log_read_create %s\n", name);
 
if (!buf) {
return LOG_ERR;
@@ -693,7 +689,7 @@ tr_commit(logger *lg, trans *tr)
int i;
 
if (lg->debug & 1)
-   fprintf(stderr, "tr_commit\n");
+   fprintf(stderr, "#tr_commit\n");
 
for (i = 0; i < tr->nr; i++) {
la_apply(lg, &tr->changes[i]);
@@ -708,7 +704,7 @@ tr_abort(logger *lg, trans *tr)
int i;
 
if (lg->debug & 1)
-   fprintf(stderr, "tr_abort\n");
+   fprintf(stderr, "#tr_abort\n");
 
for (i = 0; i < tr->nr; i++)
la_destroy(&tr->changes[i]);
@@ -788,7 +784,7 @@ logger_readlog(logger *lg, char *filenam
}
}
if (lg->debug & 1) {
-   fprintf(stderr, "logger_readlog: ");
+   fprintf(stderr, "#logger_readlog: ");
if (l.flag > 0 &&
l.flag < (char) (sizeof(log_commands) / 
sizeof(log_commands[0])))
fprintf(stderr, "%s", log_commands[(int) 
l.flag]);
@@ -808,7 +804,7 @@ logger_readlog(logger *lg, char *filenam
lg->tid = l.nr;
tr = tr_create(tr, l.nr);
if (lg->debug & 1)
-   fprintf(stderr, "logger tstart %d\n", tr->tid);
+   fprintf(stderr, "#logger tstart %d\n", tr->tid);
break;
case LOG_END:
if (tr == NULL)
@@ -879,7 +875,7 @@ logger_readlogs(logger *lg, FILE *fp, ch
char id[BUFSIZ];
 
if (lg->debug & 1)
-   fprintf(stderr, "logger_readlogs %s\n", filename);
+   fprintf(stderr, "#logger_readlogs %s\n", filename);
 
while (fgets(id, BUFSIZ, fp) != NULL) {
char buf[BUFSIZ];
@@ -909,7 +905,7 @@ logger_commit(logger *lg)
BUN p;
 
if (lg->debug & 1)
-   fprintf(stderr, "logger_commit\n");
+   f

MonetDB: default - Removed unused function SERVERexit.

2014-03-26 Thread Sjoerd Mullender
Changeset: 13cbdabc3df5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=13cbdabc3df5
Modified Files:
clients/Tests/exports.stable.out
monetdb5/modules/mal/mal_mapi.c
monetdb5/modules/mal/mal_mapi.h
Branch: default
Log Message:

Removed unused function SERVERexit.


diffs (40 lines):

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
@@ -1994,7 +1994,6 @@ str SERVERdisconnectALL(int *ret);
 str SERVERdisconnectWithAlias(int *ret, str *db_alias);
 str SERVERerror(int *ret, int *idx);
 str SERVERexecute(int *ret, int *idx);
-void SERVERexit(void);
 str SERVERexplain(str *ret, int *idx);
 str SERVERfetch_all_rows(lng *ret, int *idx);
 str SERVERfetch_field_bat(int *bid, int *idx);
diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c
--- a/monetdb5/modules/mal/mal_mapi.c
+++ b/monetdb5/modules/mal/mal_mapi.c
@@ -641,14 +641,6 @@ SERVERclient(int *res, stream **In, stre
return MAL_SUCCEED;
 }
 
-void
-SERVERexit(void){
-   int ret;
-   SERVERstop(&ret);
-   /* remove any port identity file */
-   ret = system("rm -rf .*_port");
-   (void) ret;
-}
 /*
  * @+ Remote Processing
  * The remainder of the file contains the wrappers around
diff --git a/monetdb5/modules/mal/mal_mapi.h b/monetdb5/modules/mal/mal_mapi.h
--- a/monetdb5/modules/mal/mal_mapi.h
+++ b/monetdb5/modules/mal/mal_mapi.h
@@ -54,7 +54,6 @@ mal_mapi_export str SERVERlisten_usock(i
 mal_mapi_export str SERVERstop(int *ret);
 mal_mapi_export str SERVERsuspend(int *ret);
 mal_mapi_export str SERVERresume(int *ret);
-mal_mapi_export void SERVERexit(void);
 
 mal_mapi_export str SERVERconnect(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pc);
 mal_mapi_export str SERVERdisconnectWithAlias(int *ret, str *db_alias);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - MT_kill_thread is no longer used outside gdk.

2014-03-26 Thread Sjoerd Mullender
Changeset: 5a64b9f0ee21 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5a64b9f0ee21
Modified Files:
clients/Tests/exports.stable.out
gdk/gdk_system.h
gdk/gdk_system_private.h
Branch: default
Log Message:

MT_kill_thread is no longer used outside gdk.


diffs (31 lines):

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
@@ -310,7 +310,6 @@ size_t MT_getrss(void);
 void MT_global_exit(int status) __attribute__((__noreturn__));
 void MT_init(void);
 int MT_join_thread(MT_Id t);
-int MT_kill_thread(MT_Id t);
 int MT_lockf(char *filename, int mode, off_t off, off_t len);
 MT_Id MT_locktrace;
 unsigned long long MT_locktrace_cnt[65536];
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -137,7 +137,6 @@ gdk_export void MT_exiting_thread(void);
__attribute__((__noreturn__));
 gdk_export MT_Id MT_getpid(void);
 gdk_export int MT_join_thread(MT_Id t);
-gdk_export int MT_kill_thread(MT_Id t);
 
 #if SIZEOF_VOID_P == 4
 /* "limited" stack size on 32-bit systems */
diff --git a/gdk/gdk_system_private.h b/gdk/gdk_system_private.h
--- a/gdk/gdk_system_private.h
+++ b/gdk/gdk_system_private.h
@@ -25,3 +25,5 @@
 
 __declspec(noreturn) void MT_exit_thread(int status)
__attribute__((__noreturn__));
+int MT_kill_thread(MT_Id t)
+   __attribute__((__visibility__("hidden")));
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: default - Merge with Jan2014 branch.

2014-03-26 Thread Sjoerd Mullender
Changeset: 1636b83d9230 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1636b83d9230
Added Files:
sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.sql

sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.stable.err

sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.stable.out
Modified Files:
gdk/gdk_utils.c
monetdb5/modules/mal/Tests/remote12.mal
monetdb5/modules/mal/mal_mapi.c
monetdb5/modules/mal/remote.c
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql.c
sql/rel.txt
sql/server/rel_optimizer.c
sql/test/BugTracker-2014/Tests/All
Branch: default
Log Message:

Merge with Jan2014 branch.


diffs (truncated from 436 to 300 lines):

diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1150,25 +1150,37 @@ void
 GDKexit(int status)
 {
if (ATOMIC_TAS(GDKstopped, GDKstoppedLock, "GDKexit") == 0) {
+   MT_Id pid = MT_getpid();
+   Thread t, s;
+   int i;
+
MT_lock_set(&GDKthreadLock, "GDKexit");
GDKnrofthreads = 0;
MT_lock_unset(&GDKthreadLock, "GDKexit");
if (GDKvmtrim_id)
MT_join_thread(GDKvmtrim_id);
-   MT_sleep_ms(CATNAP);
-
-   /* Kill all threads except myself */
+   /* first give the other threads a chance to exit */
+   for (i = 0; i < 10; i++) {
+   MT_lock_set(&GDKthreadLock, "GDKexit");
+   for (t = GDKthreads, s = t + THREADS; t < s; t++)
+   if (t->pid && t->pid != pid)
+   break;
+   MT_lock_unset(&GDKthreadLock, "GDKexit");
+   if (t == s) /* no other threads? */
+   break;
+   MT_sleep_ms(CATNAP);
+   }
if (status == 0) {
-   MT_Id pid = MT_getpid();
-   Thread t, s;
-
+   /* they had there chance, now kill them */
MT_lock_set(&GDKthreadLock, "GDKexit");
for (t = GDKthreads, s = t + THREADS; t < s; t++) {
if (t->pid) {
MT_Id victim = t->pid;
 
-   if (t->pid != pid)
+   if (t->pid != pid) {
+   fprintf(stderr, "#GDKexit: 
killing thread\n");
MT_kill_thread(victim);
+   }
}
}
MT_lock_unset(&GDKthreadLock, "GDKexit");
diff --git a/monetdb5/modules/mal/Tests/remote12.mal 
b/monetdb5/modules/mal/Tests/remote12.mal
--- a/monetdb5/modules/mal/Tests/remote12.mal
+++ b/monetdb5/modules/mal/Tests/remote12.mal
@@ -1,4 +1,4 @@
-#causing a sigfault 
+#causing a segfault 
 uri := sabaoth.getLocalConnectionURI();
 conn:str := remote.connect(uri, "monetdb", "monetdb");
 e := nil:BAT;
diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c
--- a/monetdb5/modules/mal/mal_mapi.c
+++ b/monetdb5/modules/mal/mal_mapi.c
@@ -178,9 +178,13 @@ doChallenge(stream *in, stream *out) {
MSscheduleClient(buf, challenge, bs, fdout);
 }
 
-static MT_Id listener[8];
-static int lastlistener=0;
-static int serveractive=TRUE;
+static volatile ATOMIC_TYPE nlistener = 0; /* nr of listeners */
+static volatile ATOMIC_TYPE serveractive = 0;
+static volatile ATOMIC_TYPE serverexiting = 0; /* listeners should exit */
+#ifdef ATOMIC_LOCK
+/* lock for all three ATOMIC_TYPE variables above */
+static MT_Lock atomicLock MT_LOCK_INITIALIZER("atomicLock");
+#endif
 
 static void
 SERVERlistenThread(SOCKET *Sock)
@@ -199,8 +203,7 @@ SERVERlistenThread(SOCKET *Sock)
GDKfree(Sock);
}
 
-   if (lastlistener < 8)
-   listener[lastlistener++] = MT_getpid();
+   (void) ATOMIC_INC(nlistener, atomicLock, "SERVERlistenThread");
 
do {
FD_ZERO(&fds);
@@ -221,7 +224,8 @@ SERVERlistenThread(SOCKET *Sock)
msgsock = usock;
 #endif
retval = select((int)msgsock + 1, &fds, NULL, NULL, &tv);
-   if (GDKexiting())
+   if (ATOMIC_GET(serverexiting, atomicLock, "SERVERlistenThread") 
||
+   GDKexiting())
break;
if (retval == 0) {
/* nothing interesting has happened */
@@ -236,7 +240,7 @@ SERVERlistenThread(SOCKET *Sock)
}
if (sock != INVALID_SOCKET && FD_ISSET(sock, &fds)) {
if ((msgsock = accept(sock, (SOCKPTR)0

MonetDB: Jan2014 - cleanup/remove comments

2014-03-26 Thread Niels Nes
Changeset: 0fd0390e069b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0fd0390e069b
Modified Files:
sql/backends/monet5/rel_bin.c
Branch: Jan2014
Log Message:

cleanup/remove comments


diffs (14 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -757,9 +757,7 @@ stmt_idx( mvc *sql, sql_idx *i, stmt *de
 static stmt *
 stmt_dels( mvc *sql, sql_table *t) 
 {
-// if (!t->readonly) 
-   return stmt_tid(sql->sa, t);
-// return NULL;
+   return stmt_tid(sql->sa, t);
 }
 
 
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: Jan2014 - fixed bug 3446, ie readonly needs to use the ...

2014-03-26 Thread Niels Nes
Changeset: 5e7f1c747884 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5e7f1c747884
Added Files:
sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.sql

sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.stable.err

sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.stable.out
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql.c
sql/test/BugTracker-2014/Tests/All
Branch: Jan2014
Log Message:

fixed bug 3446, ie readonly needs to use the 'tid' column and only
set to read only when there are no (unflushed) updates.


diffs (201 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -757,9 +757,9 @@ stmt_idx( mvc *sql, sql_idx *i, stmt *de
 static stmt *
 stmt_dels( mvc *sql, sql_table *t) 
 {
-   if (!t->readonly) 
+// if (!t->readonly) 
return stmt_tid(sql->sa, t);
-   return NULL;
+// return NULL;
 }
 
 
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -480,6 +480,21 @@ create_table_or_view(mvc *sql, char *sna
return MAL_SUCCEED;
 }
 
+static int
+table_has_updates(sql_trans *tr, sql_table *t)
+{
+   node *n;
+   int cnt = 0;
+
+   for ( n = t->columns.set->h; !cnt && n; n = n->next) {
+   sql_column *c = n->data;
+   BAT *b = store_funcs.bind_col(tr, c, RD_UPD);
+   cnt += BATcount(b);
+   BBPunfix(b->batCacheid);
+   }
+   return cnt;
+}
+
 static str
 alter_table(mvc *sql, char *sname, sql_table *t)
 {
@@ -509,8 +524,11 @@ alter_table(mvc *sql, char *sname, sql_t
}
}
 
-   if (t->readonly != nt->readonly)
+   if (t->readonly != nt->readonly) {
+   if (t->readonly && table_has_updates(sql->session->tr, nt)) 
+   return sql_message("4!ALTER TABLE: set READONLY not 
possible with outstanding updates (wait until updates are flushed)\n");
mvc_readonly(sql, nt, t->readonly);
+   }
 
/* check for changes */
if (t->tables.dset)
diff --git a/sql/test/BugTracker-2014/Tests/All 
b/sql/test/BugTracker-2014/Tests/All
--- a/sql/test/BugTracker-2014/Tests/All
+++ b/sql/test/BugTracker-2014/Tests/All
@@ -9,3 +9,4 @@ sample-crash.Bug-3429
 indices.Bug-3435
 utf8bom.Bug-3436
 left-outer-join-with-and.Bug-3444
+setreadonly_forgets_changes.Bug-3446
diff --git 
a/sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.sql 
b/sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.sql
@@ -0,0 +1,18 @@
+create table t3446(a int);
+insert into t3446 values (1),(3),(2),(3),(3),(3);
+
+select * from t3446;
+
+-- remove the 3s
+delete from t3446 where a = 3;
+select * from t3446;
+
+-- Oops, the 3s are back when the table is set read-only
+alter table t3446 set read only;
+select * from t3446;
+
+-- Oops, the 3s are gone again when the table is read/write again
+alter table t3446 set read write;
+select * from t3446;
+
+drop table t3446;
diff --git 
a/sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.stable.err
 
b/sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.stable.err
new file mode 100644
--- /dev/null
+++ 
b/sql/test/BugTracker-2014/Tests/setreadonly_forgets_changes.Bug-3446.stable.err
@@ -0,0 +1,35 @@
+stderr of test 'setreadonly_forgets_changes.Bug-3446` in directory 
'sql/test/BugTracker-2014` itself:
+
+
+# 11:47:14 >  
+# 11:47:14 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=37218" "--set" 
"mapi_usock=/var/tmp/mtest-9874/.s.monetdb.37218" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2014"
 "--set" "mal_listing=0"
+# 11:47:14 >  
+
+# builtin opt  gdk_dbpath = 
/home/niels/scratch/rc-clean/Linux-x86_64/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 5
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 37218
+# cmdline opt  mapi_usock = /var/tmp/mtest-9874/.s.monetdb.37218
+# cmdline opt  monet_prompt = 
+# cmdline opt  mal_listing = 2
+# cmdline opt  gdk_dbpath = 
/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2014
+# cmdline opt  mal_listing = 0
+
+# 11:47:14 >  
+# 11:47:14 >  "mclient" "-lsql" 

MonetDB: Jan2014 - Wait a bit longer for threads to exit, but on...

2014-03-26 Thread Sjoerd Mullender
Changeset: bc121719042d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bc121719042d
Modified Files:
gdk/gdk_utils.c
Branch: Jan2014
Log Message:

Wait a bit longer for threads to exit, but only if there are other threads.
Also print a message when we do kill threads.


diffs (48 lines):

diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1150,25 +1150,37 @@ void
 GDKexit(int status)
 {
if (ATOMIC_TAS(GDKstopped, GDKstoppedLock, "GDKexit") == 0) {
+   MT_Id pid = MT_getpid();
+   Thread t, s;
+   int i;
+
MT_lock_set(&GDKthreadLock, "GDKexit");
GDKnrofthreads = 0;
MT_lock_unset(&GDKthreadLock, "GDKexit");
if (GDKvmtrim_id)
MT_join_thread(GDKvmtrim_id);
-   MT_sleep_ms(CATNAP);
-
-   /* Kill all threads except myself */
+   /* first give the other threads a chance to exit */
+   for (i = 0; i < 10; i++) {
+   MT_lock_set(&GDKthreadLock, "GDKexit");
+   for (t = GDKthreads, s = t + THREADS; t < s; t++)
+   if (t->pid && t->pid != pid)
+   break;
+   MT_lock_unset(&GDKthreadLock, "GDKexit");
+   if (t == s) /* no other threads? */
+   break;
+   MT_sleep_ms(CATNAP);
+   }
if (status == 0) {
-   MT_Id pid = MT_getpid();
-   Thread t, s;
-
+   /* they had there chance, now kill them */
MT_lock_set(&GDKthreadLock, "GDKexit");
for (t = GDKthreads, s = t + THREADS; t < s; t++) {
if (t->pid) {
MT_Id victim = t->pid;
 
-   if (t->pid != pid)
+   if (t->pid != pid) {
+   fprintf(stderr, "#GDKexit: 
killing thread\n");
MT_kill_thread(victim);
+   }
}
}
MT_lock_unset(&GDKthreadLock, "GDKexit");
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: Jan2014 - Fix potential race conditions, and avoid kill...

2014-03-26 Thread Sjoerd Mullender
Changeset: f3bdb8dcaebf for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f3bdb8dcaebf
Modified Files:
monetdb5/modules/mal/mal_mapi.c
Branch: Jan2014
Log Message:

Fix potential race conditions, and avoid killing threads.


diffs (96 lines):

diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c
--- a/monetdb5/modules/mal/mal_mapi.c
+++ b/monetdb5/modules/mal/mal_mapi.c
@@ -178,9 +178,13 @@ doChallenge(stream *in, stream *out) {
MSscheduleClient(buf, challenge, bs, fdout);
 }
 
-static MT_Id listener[8];
-static int lastlistener=0;
-static int serveractive=TRUE;
+static volatile ATOMIC_TYPE nlistener = 0; /* nr of listeners */
+static volatile ATOMIC_TYPE serveractive = 0;
+static volatile ATOMIC_TYPE serverexiting = 0; /* listeners should exit */
+#ifdef ATOMIC_LOCK
+/* lock for all three ATOMIC_TYPE variables above */
+static MT_Lock atomicLock MT_LOCK_INITIALIZER("atomicLock");
+#endif
 
 static void
 SERVERlistenThread(SOCKET *Sock)
@@ -199,8 +203,7 @@ SERVERlistenThread(SOCKET *Sock)
GDKfree(Sock);
}
 
-   if (lastlistener < 8)
-   listener[lastlistener++] = MT_getpid();
+   (void) ATOMIC_INC(nlistener, atomicLock, "SERVERlistenThread");
 
do {
FD_ZERO(&fds);
@@ -221,7 +224,8 @@ SERVERlistenThread(SOCKET *Sock)
msgsock = usock;
 #endif
retval = select((int)msgsock + 1, &fds, NULL, NULL, &tv);
-   if (GDKexiting())
+   if (ATOMIC_GET(serverexiting, atomicLock, "SERVERlistenThread") 
||
+   GDKexiting())
break;
if (retval == 0) {
/* nothing interesting has happened */
@@ -236,7 +240,7 @@ SERVERlistenThread(SOCKET *Sock)
}
if (sock != INVALID_SOCKET && FD_ISSET(sock, &fds)) {
if ((msgsock = accept(sock, (SOCKPTR)0, (socklen_t 
*)0)) == INVALID_SOCKET) {
-   if (MT_geterrno() != EINTR || serveractive == 
FALSE) {
+   if (MT_geterrno() != EINTR || 
!ATOMIC_GET(serveractive, atomicLock, "SERVERlistenThread")) {
msg = "accept failed";
goto error;
}
@@ -330,7 +334,9 @@ SERVERlistenThread(SOCKET *Sock)
doChallenge(
socket_rastream(msgsock, "Server read"),
socket_wastream(msgsock, "Server write"));
-   } while (!GDKexiting());
+   } while (!ATOMIC_GET(serverexiting, atomicLock, "SERVERlistenThread") &&
+!GDKexiting());
+   (void) ATOMIC_DEC(nlistener, atomicLock, "SERVERlistenThread");
return;
 error:
fprintf(stderr, "!mal_mapi.listen: %s, terminating listener\n", msg);
@@ -599,12 +605,12 @@ SERVERlisten_port(int *ret, int *pid)
 str
 SERVERstop(int *ret)
 {
-   int i;
-
-printf("SERVERstop\n");
-   for( i=0; i< lastlistener; i++)
-   MT_kill_thread(listener[i]);
-   lastlistener = 0;
+fprintf(stderr, "SERVERstop\n");
+   ATOMIC_SET(serverexiting, 1, atomicLock, "SERVERstop");
+   /* wait until they all exited, but skip the wait if the whole
+* system is going down */
+   while (ATOMIC_GET(nlistener, atomicLock, "SERVERstop") > 0 && 
!GDKexiting())
+   MT_sleep_ms(100);
(void) ret; /* fool compiler */
return MAL_SUCCEED;
 }
@@ -614,14 +620,14 @@ str
 SERVERsuspend(int *res)
 {
(void) res;
-   serveractive= FALSE;
+   ATOMIC_SET(serveractive, 0, atomicLock, "SERVERsuspend");
return MAL_SUCCEED;
 }
 
 str
 SERVERresume(int *res)
 {
-   serveractive= TRUE;
+   ATOMIC_SET(serveractive, 1, atomicLock, "SERVERsuspend");
(void) res;
return MAL_SUCCEED;
 }
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: Jan2014 - Typos.

2014-03-26 Thread Sjoerd Mullender
Changeset: 9f59caaa08cb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9f59caaa08cb
Modified Files:
monetdb5/modules/mal/Tests/remote12.mal
monetdb5/modules/mal/remote.c
Branch: Jan2014
Log Message:

Typos.


diffs (21 lines):

diff --git a/monetdb5/modules/mal/Tests/remote12.mal 
b/monetdb5/modules/mal/Tests/remote12.mal
--- a/monetdb5/modules/mal/Tests/remote12.mal
+++ b/monetdb5/modules/mal/Tests/remote12.mal
@@ -1,4 +1,4 @@
-#causing a sigfault 
+#causing a segfault 
 uri := sabaoth.getLocalConnectionURI();
 conn:str := remote.connect(uri, "monetdb", "monetdb");
 e := nil:BAT;
diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c
--- a/monetdb5/modules/mal/remote.c
+++ b/monetdb5/modules/mal/remote.c
@@ -175,7 +175,7 @@ str RMTconnectScen(
throw(ILLARG, "remote.connect", ILLEGAL_ARGUMENT ": scenario is 
"
"NULL or nil");
if (strcmp(*scen, "mal") != 0 && strcmp(*scen, "msql") != 0)
-   throw(ILLARG, "remote.connect", ILLEGAL_ARGUMENT ": scenation 
'%s' "
+   throw(ILLARG, "remote.connect", ILLEGAL_ARGUMENT ": scenario 
'%s' "
"is not supported", *scen);
 
m = mapi_mapiuri(*ouri, *user, *passwd, *scen);
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: Jan2014 - fixed reduce_groupby optimizer to remove cons...

2014-03-26 Thread Niels Nes
Changeset: 054a2242663a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=054a2242663a
Modified Files:
sql/rel.txt
sql/server/rel_optimizer.c
Branch: Jan2014
Log Message:

fixed reduce_groupby optimizer to remove constants


diffs (71 lines):

diff --git a/sql/rel.txt b/sql/rel.txt
--- a/sql/rel.txt
+++ b/sql/rel.txt
@@ -106,7 +106,7 @@ e_convert
 
 e_cmp
-> lleft sub expression
-   -> rright sub expression (f second arg for range expressions)
+   -> rright sub expression (f second arg (->f) for range expressions)
-> flag compare type
(   cmp_gt = 0,
cmp_gte = 1,
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -3940,6 +3940,55 @@ rel_reduce_groupby_exps(int *changes, mv
free(tbls);
free(scores);
}
+   /* remove constants from group by list */
+   if (is_groupby(rel->op) && rel->r && !rel_is_ref(rel)) {
+   int i;
+   node *n;
+   
+   for (i = 0, n = gbe->h; n; n = n->next) {
+   sql_exp *e = n->data;
+
+   if (exp_is_atom(e))
+   i++;
+   }
+   if (i) {
+   list *ngbe = new_exp_list(sql->sa);
+   list *dgbe = new_exp_list(sql->sa);
+
+   for (n = gbe->h; n; n = n->next) {
+   sql_exp *e = n->data;
+
+   if (!exp_is_atom(e))
+   append(ngbe, e);
+   else
+   append(dgbe, e);
+   }
+   rel->r = ngbe;
+   if (!list_empty(dgbe)) {
+   /* use atom's directly in the aggr expr list */
+   list *nexps = new_exp_list(sql->sa);
+
+   for (n = rel->exps->h; n; n = n->next) {
+   sql_exp *e = n->data, *ne = NULL;
+
+   if (is_column(e->type)) {
+   if (e->l) 
+   ne = 
exps_bind_column2(dgbe, e->l, e->r);
+   else
+   ne = 
exps_bind_column(dgbe, e->r, NULL);
+   if (ne) {
+   ne = exp_copy(sql->sa, 
ne);
+   exp_setname(sql->sa, 
ne, e->rname, e->name);
+   e = ne;
+   }
+   }
+   append(nexps, e);
+   }
+   rel->exps = nexps;
+   }
+   (*changes)++;
+   }
+   }
return rel;
 }
 
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list