Changeset: 4cf411d38ca6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4cf411d38ca6
Modified Files:
gdk/gdk_batop.c
gdk/gdk_posix.c
gdk/gdk_utils.c
monetdb5/extras/jaql/jaqlscenario.c
monetdb5/mal/mal.c
monetdb5/mal/mal.h
monetdb5/mal/mal_client.c
monetdb5/mal/mal_client.h
monetdb5/mal/mal_dataflow.c
monetdb5/mal/mal_debugger.c
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_recycle.c
monetdb5/mal/mal_scenario.c
monetdb5/mal/mal_session.c
monetdb5/modules/kernel/status.c
monetdb5/modules/mal/clients.c
monetdb5/modules/mal/clients.mal
monetdb5/modules/mal/mdb.c
sql/backends/monet5/sql_scenario.c
Branch: default
Log Message:
Merge with Feb2013 branch.
diffs (truncated from 806 to 300 lines):
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -1315,8 +1315,14 @@ BATsubsort(BAT **sorted, BAT **order, BA
/* no place to put result, so we're done quickly */
return GDK_SUCCEED;
}
- if (BATcount(b) <= 1 || (BATtordered(b) && o == NULL && g == NULL &&
groups == NULL)) {
- /* trivially (sub)sorted */
+ if (BATcount(b) <= 1 ||
+ ((reverse ? BATtrevordered(b) : BATtordered(b)) &&
+ o == NULL && g == NULL &&
+ (groups == NULL || BATtkey(b) ||
+ (reverse ? BATtordered(b) : BATtrevordered(b))))) {
+ /* trivially (sub)sorted, and either we don't need to
+ * return group information, or we can trivially
+ * deduce the groups */
if (sorted) {
BBPfix(b->batCacheid);
bn = b;
@@ -1332,12 +1338,23 @@ BATsubsort(BAT **sorted, BAT **order, BA
*order = on;
}
if (groups) {
- gn = BATnew(TYPE_void, TYPE_void, BATcount(b));
- if (gn == NULL)
- goto error;
- BATsetcount(gn, BATcount(b));
+ if (BATtkey(b)) {
+ /* singleton groups */
+ gn = BATnew(TYPE_void, TYPE_void, BATcount(b));
+ if (gn == NULL)
+ goto error;
+ BATsetcount(gn, BATcount(b));
+ BATseqbase(BATmirror(gn), 0);
+ } else {
+ /* single group */
+ const oid *o = 0;
+ assert(BATcount(b) == 1 ||
+ (BATtordered(b) && BATtrevordered(b)));
+ gn = BATconstant(TYPE_oid, &o, BATcount(b));
+ if (gn == NULL)
+ goto error;
+ }
BATseqbase(gn, 0);
- BATseqbase(BATmirror(gn), 0);
*groups = gn;
}
return GDK_SUCCEED;
@@ -1380,6 +1397,7 @@ BATsubsort(BAT **sorted, BAT **order, BA
}
BATseqbase(on, 0);
on->tsorted = on->trevsorted = 0;
+ on->tdense = 0;
*order = on;
}
if (g) {
@@ -1434,7 +1452,7 @@ BATsubsort(BAT **sorted, BAT **order, BA
} else if (b->U->count <= 1) {
b->tsorted = b->trevsorted = 1;
}
- if ((!(reverse && bn->trevsorted) && !(!reverse &&
bn->tsorted)) &&
+ if (!(reverse ? bn->trevsorted : bn->tsorted) &&
do_sort(Tloc(bn, BUNfirst(bn)),
on ? Tloc(on, BUNfirst(on)) : NULL,
bn->T->vheap ? bn->T->vheap->base : NULL,
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -34,10 +34,6 @@
#include <unistd.h> /* sbrk on Solaris */
#include <string.h> /* strncpy */
-#ifdef __hpux
-extern char *sbrk(int);
-#endif
-
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
@@ -277,7 +273,7 @@ char *MT_heapbase = NULL;
void
MT_init_posix(void)
{
- MT_heapbase = (char *) sbrk(0);
+ MT_heapbase = 0;
}
/* return RSS in bytes */
@@ -362,7 +358,7 @@ MT_getrss(void)
char *
MT_heapcur(void)
{
- return (char *) sbrk(0);
+ return 0;
}
void *
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -433,10 +433,7 @@ MT_init(void)
size_t
GDKmem_cursize(void)
{
- /* RAM/swapmem that Monet has claimed from OS */
- size_t heapsize = MT_heapcur() - MT_heapbase;
-
- return (size_t) SEG_SIZE(heapsize, MT_VMUNITLOG);
+ return GDKmem_inuse();
}
size_t
@@ -639,15 +636,18 @@ GDKmemfail(str s, size_t len)
/* allocate 8 bytes extra (so it stays 8-bytes aligned) and put
* realsize in front */
-#define GDKmalloc_prefixsize(s,size) \
- do { \
- s = (ssize_t *) malloc(size + MALLOC_EXTRA_SPACE + GLIBC_BUG); \
- if (s != NULL) { \
- assert((((size_t) s)&7) == 0); /* no MISALIGN */ \
- s = (ssize_t*) ((char*) s + MALLOC_EXTRA_SPACE); \
- s[-1] = (ssize_t) (size + MALLOC_EXTRA_SPACE); \
- } \
- } while (0)
+static inline void *
+GDKmalloc_prefixsize(size_t size)
+{
+ ssize_t *s;
+
+ if ((s = malloc(size + MALLOC_EXTRA_SPACE + GLIBC_BUG)) != NULL) {
+ assert((((size_t) s) & 7) == 0); /* no MISALIGN */
+ s = (ssize_t*) ((char*) s + MALLOC_EXTRA_SPACE);
+ s[-1] = (ssize_t) (size + MALLOC_EXTRA_SPACE);
+ }
+ return s;
+}
/*
* The emergency flag can be set to force a fatal error if needed.
@@ -657,7 +657,7 @@ GDKmemfail(str s, size_t len)
void *
GDKmallocmax(size_t size, size_t *maxsize, int emergency)
{
- ssize_t *s = NULL;
+ void *s;
if (size == 0) {
#ifdef GDK_MEM_NULLALLOWED
@@ -667,10 +667,10 @@ GDKmallocmax(size_t size, size_t *maxsiz
#endif
}
size = (size + 7) & ~7; /* round up to a multiple of eight */
- GDKmalloc_prefixsize(s, size);
+ s = GDKmalloc_prefixsize(size);
if (s == NULL) {
GDKmemfail("GDKmalloc", size);
- GDKmalloc_prefixsize(s, size);
+ s = GDKmalloc_prefixsize(size);
if (s == NULL) {
if (emergency == 0) {
GDKerror("GDKmallocmax: failed for " SZFMT "
bytes", size);
@@ -683,7 +683,7 @@ GDKmallocmax(size_t size, size_t *maxsiz
}
*maxsize = size;
heapinc(size + MALLOC_EXTRA_SPACE);
- return (void *) s;
+ return s;
}
#undef GDKmalloc
diff --git a/monetdb5/extras/jaql/jaqlscenario.c
b/monetdb5/extras/jaql/jaqlscenario.c
--- a/monetdb5/extras/jaql/jaqlscenario.c
+++ b/monetdb5/extras/jaql/jaqlscenario.c
@@ -155,7 +155,7 @@ JAQLreader(Client c)
/* "activate" the stream by sending a prompt (client sync) */
if (c->fdin->eof != 0) {
if (mnstr_flush(c->fdout) < 0) {
- c->mode = FINISHING;
+ c->mode = FINISHCLIENT;
} else {
c->fdin->eof = 0;
}
@@ -180,7 +180,7 @@ JAQLparser(Client c)
fprintf(stderr, "%s, cannot handle client!\n", errmsg);
/* stop here, instead of printing the exception below to the
* client in an endless loop */
- c->mode = FINISHING;
+ c->mode = FINISHCLIENT;
return errmsg;
}
@@ -204,7 +204,7 @@ JAQLparser(Client c)
/* stop if it seems nothing is going to come any more */
if (j->scanstreameof == 1) {
- c->mode = FINISHING;
+ c->mode = FINISHCLIENT;
freetree(j->p);
j->p = NULL;
return MAL_SUCCEED;
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -18,9 +18,6 @@
*/
/*
- * @f mal
- * @-
- * @node Design Considerations, Architecture Overview, Design Overview,
Design Overview
* @+ Design Considerations
* Redesign of the MonetDB software stack was driven by the need to
* reduce the effort to extend the system into novel directions
@@ -73,7 +70,7 @@
* Moreover, a textual interface reduces the programming
* effort otherwise needed to develop test and application programs.
* The XML trend as the language for tool interaction supports our decision.
- * @-
+ *
* @node Architecture Overview, MAL Synopsis, Design Considerations, Design
Overview
* @+ Architecture Overview
* The architecture is built around a few independent components:
@@ -294,60 +291,79 @@ int mal_init(void){
return 0;
}
/*
- * @-
* Upon exit we should attempt to remove all allocated memory explicitly.
* This seemingly superflous action is necessary to simplify analyis of
* memory leakage problems later on.
*/
+
+/* stopping clients should be done with care, as they may be in the mids of
+ * transactions. One safe place is between MAL instructions, which would
+ * abort the transaction by raising an exception. All non-console sessions are
+ * terminate this way.
+ * We should also ensure that no new client enters the scene while shutting
down.
+ * For this we mark the client records as BLOCKCLIENT.
+ *
+ * Beware, mal_exit is also called during a SIGTERM from the monetdb tool
+ */
+static void stopClients(void)
+{
+ Client cntxt = mal_clients;
+
+ MT_lock_set(&mal_contextLock,"stopClients");
+ for(cntxt= mal_clients +1; cntxt < mal_clients+MAL_MAXCLIENTS; cntxt++)
+ if ( cntxt->mode == RUNCLIENT)
+ cntxt->mode = FINISHCLIENT;
+ else if (cntxt->mode == FREECLIENT)
+ cntxt->mode = BLOCKCLIENT;
+ MT_lock_unset(&mal_contextLock,"stopClients");
+}
+
int
moreClients(int reruns)
{
- int freeclient=0, finishing=0, claimed=0;
+ int freeclient=0, finishing=0, running=0, blocked = 0;
Client cntxt = mal_clients;
- freeclient=0; finishing=0; claimed=0;
for(cntxt= mal_clients+1; cntxt<mal_clients+MAL_MAXCLIENTS; cntxt++){
freeclient += (cntxt->mode == FREECLIENT);
- finishing += (cntxt->mode == FINISHING);
- claimed += (cntxt->mode == CLAIMED);
- if( cntxt->mode & FINISHING)
- printf("#Client %d %d\n",(int)(cntxt - mal_clients),
cntxt->idx);
+ finishing += (cntxt->mode == FINISHCLIENT);
+ running += (cntxt->mode == RUNCLIENT);
+ blocked += (cntxt->mode == BLOCKCLIENT);
}
- if( reruns == 3){
- mnstr_printf(mal_clients->fdout,"#MALexit: server forced exit"
- " %d finishing %d claimed\n",
- finishing,claimed);
+ if( reruns > 3){
+ printf("MALexit: server forced exit %d free %d finishing %d
running %d blocked\n",
+ freeclient, finishing,running, blocked);
return 0;
}
- return finishing+claimed;
+ return finishing+running;
}
+
void mal_exit(void){
str err;
/*
- * @-
* Before continuing we should make sure that all clients
* (except the console) have left the scene.
*/
- RECYCLEdrop(mal_clients); /* remove any left over intermediates */
- stopProfiling();
+ stopClients();
+#if 0
+{
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list