Changeset: f564817d28ff for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f564817d28ff
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_client.h
        monetdb5/mal/mal_factory.c
        monetdb5/mal/mal_import.c
        monetdb5/mal/mal_interpreter.c
        monetdb5/mal/mal_private.h
        monetdb5/mal/mal_session.c
        sql/backends/monet5/sql_cquery.c
        sql/backends/monet5/wlr.c
        tools/mserver/shutdowntest.c
Branch: trails
Log Message:

Move plants to the MAL client definition. Previously it was a global variable.


diffs (truncated from 703 to 300 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
@@ -1348,7 +1348,7 @@ str MBMskewed(bat *ret, oid *base, lng *
 str MBMuniform(bat *ret, oid *base, lng *size, int *domain);
 int MCactiveClients(void);
 str MCawakeClient(int id);
-void MCcloseClient(Client c, int which_client);
+void MCcloseClient(Client c);
 int MCdefault;
 Client MCforkClient(Client father);
 Client MCgetClient(int id);
@@ -2278,7 +2278,7 @@ MT_Lock mal_copyLock;
 void mal_dataflow_reset(void) __attribute__((__visibility__("hidden")));
 MT_Lock mal_delayLock;
 void mal_exit(void);
-void mal_factory_reset(void) __attribute__((__visibility__("hidden")));
+void mal_factory_reset(Client cntxt) __attribute__((__visibility__("hidden")));
 int mal_init(void);
 void mal_instruction_reset(void);
 void mal_linker_reset(void) __attribute__((__visibility__("hidden")));
@@ -2355,7 +2355,7 @@ MalStkPtr newGlobalStack(int size);
 InstrPtr newInstruction(MalBlkPtr mb, str modnme, str fcnnme);
 MalBlkPtr newMalBlk(int elements);
 int newMalBlkStmt(MalBlkPtr mb, int elements);
-Plant newPlant(MalBlkPtr mb);
+Plant newPlant(Client cntxt, MalBlkPtr mb);
 InstrPtr newRaiseStmt(MalBlkPtr mb, str nme);
 str newRef;
 InstrPtr newReturnStmt(MalBlkPtr mb);
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -149,7 +149,6 @@ void mserver_reset(int exit)
        MTIMEreset();
 #endif
 */
-       mal_factory_reset();
        mal_dataflow_reset();
        THRdel(mal_clients->mythread);
        GDKfree(mal_clients->errbuf);
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
@@ -260,6 +260,10 @@ MCinitClientRecord(Client c, oid user, b
        c->blocksize = BLOCK;
        c->protocol = PROTOCOL_9;
        c->compute_column_widths = 0;
+
+       c->lastPlant = 0;
+       c->plantId = 1;
+       c->plants = 0;
        MT_sema_init(&c->s, 0, "Client->s");
        return c;
 }
@@ -417,6 +421,7 @@ freeClient(Client c)
        if (t)
                THRdel(t);  /* you may perform suicide */
        MT_sema_destroy(&c->s);
+       mal_factory_reset(c);
        c->mode = MCshutdowninprogress()? BLOCKCLIENT: FREECLIENT;
 }
 
@@ -475,7 +480,7 @@ MCactiveClients(void)
 }
 
 void
-MCcloseClient(Client c, int which_client)
+MCcloseClient(Client c)
 {
 #ifdef MAL_DEBUG_CLIENT
        fprintf(stderr,"closeClient %d " OIDFMT "\n", (int) (c - mal_clients), 
c->user);
@@ -484,15 +489,11 @@ MCcloseClient(Client c, int which_client
        if (!isAdministrator(c)) {
                freeClient(c);
                return;
-       } else if(which_client == WLR_CLIENT) {
-               freeClient(c);
        }
 
        /* adm is set to disallow new clients entering */
        mal_clients[CONSOLE].mode = FINISHCLIENT;
-       if(which_client != CQ_CLIENT) {
-               mal_exit();
-       }
+       mal_exit();
 }
 
 str
diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h
--- a/monetdb5/mal/mal_client.h
+++ b/monetdb5/mal/mal_client.h
@@ -28,10 +28,7 @@ enum clientmode {
 };
 
 #define PROCESSTIMEOUT  2   /* seconds */
-
-#define REGULAR_CLIENT  0
-#define CQ_CLIENT       1
-#define WLR_CLIENT      2
+#define MAXPLANTS 256
 
 /*
  * The prompt structure is designed to simplify recognition of the
@@ -60,6 +57,23 @@ typedef struct CURRENT_INSTR{
        InstrPtr        pci;
 } Workset;
 
+/*
+ * MAL factories definition.
+ */
+typedef struct {
+       int id;                 /* unique plant number */
+       MalBlkPtr factory;
+       MalStkPtr stk;          /* private state */
+       int pc;                 /* where we are */
+       int inuse;              /* able to handle it */
+       int next;               /* next plant of same factory */
+       int policy;             /* flags to control behavior */
+
+       MalBlkPtr caller;       /* from routine */
+       MalStkPtr env;          /* with the stack  */
+       InstrPtr pci;           /* with the instruction */
+} PlantRecord, *Plant;
+
 typedef struct CLIENT {
        int idx;        /* entry in mal_clients */
        oid user;       /* user id in the auth administration */
@@ -195,6 +209,10 @@ typedef struct CLIENT {
        size_t blocksize;
        protocol_version protocol;
        int compute_column_widths;
+
+       PlantRecord *plants;
+       int lastPlant;
+       int plantId;
 } *Client, ClientRec;
 
 mal_export void    MCinit(void);
@@ -211,7 +229,7 @@ mal_export Client  MCforkClient(Client f
 mal_export void           MCstopClients(Client c);
 mal_export int     MCshutdowninprogress(void);
 mal_export int    MCactiveClients(void);
-mal_export void    MCcloseClient(Client c, int which_client);
+mal_export void    MCcloseClient(Client c);
 mal_export str     MCsuspendClient(int id);
 mal_export str     MCawakeClient(int id);
 mal_export int     MCpushClientInput(Client c, bstream *new_input, int 
listing, char *prompt);
diff --git a/monetdb5/mal/mal_factory.c b/monetdb5/mal/mal_factory.c
--- a/monetdb5/mal/mal_factory.c
+++ b/monetdb5/mal/mal_factory.c
@@ -21,42 +21,54 @@
 #include "mal_namespace.h"
 #include "mal_private.h"
 
-typedef struct {
-       int id;                 /* unique plant number */
-       MalBlkPtr factory;
-       MalStkPtr stk;          /* private state */
-       int pc;                 /* where we are */
-       int inuse;              /* able to handle it */
-       int next;               /* next plant of same factory */
-       int policy;             /* flags to control behavior */
+static int
+findPlant(Client cntxt, MalBlkPtr mb){
+       int i, lastplant= cntxt->lastPlant;
+       Plant cpl = cntxt->plants;
 
-       Client client;          /* who called it */
-       MalBlkPtr caller;       /* from routine */
-       MalStkPtr env;          /* with the stack  */
-       InstrPtr pci;           /* with the instruction */
-} PlantRecord, *Plant;
+       for(i=0; i< lastplant; i++)
+               if( cpl[i].factory == mb)
+                       return i;
+       return -1;
+}
+
+mal_export Plant newPlant(Client cntxt, MalBlkPtr mb);
 
-#define MAXPLANTS 256
-static PlantRecord plants[MAXPLANTS];
-static int lastPlant= 0;
-static int plantId = 1;
-
-mal_export Plant newPlant(MalBlkPtr mb);
-
+/*
+ * A new plant is constructed. The properties of the factory
+ * should be known upon compile time. They are retrieved from
+ * the signature of the factory definition.
+ */
+Plant
+newPlant(Client cntxt, MalBlkPtr mb)
+{
+       Plant p, plim;
+       MalStkPtr stk;
 
-static int
-findPlant(MalBlkPtr mb){
-       int i;
-       for(i=0; i<lastPlant; i++)
-       if( plants[i].factory == mb)
-               return i;
-       return -1;
+       plim = cntxt->plants + cntxt->lastPlant;
+       for (p = cntxt->plants; p < plim && p->factory; p++)
+               ;
+       stk = newGlobalStack(mb->vsize);
+       if (cntxt->lastPlant == MAXPLANTS || stk == NULL){
+               if( stk) GDKfree(stk);
+               return 0;
+       }
+       if (p == plim)
+               cntxt->lastPlant++;
+       p->factory = mb;
+       p->id = cntxt->plantId++;
+
+       p->pc = 1;              /* where we start */
+       p->stk = stk;
+       p->stk->blk = mb;
+       p->stk->keepAlive = TRUE;
+       return p;
 }
 
 str
 runFactory(Client cntxt, MalBlkPtr mb, MalBlkPtr mbcaller, MalStkPtr stk, 
InstrPtr pci)
 {
-       Plant pl=0;
+       Plant pl=0, cpl;
        int firstcall= TRUE, i, k;
        InstrPtr psig = getInstrPtr(mb, 0);
        ValPtr lhs, rhs;
@@ -66,39 +78,45 @@ runFactory(Client cntxt, MalBlkPtr mb, M
 #ifdef DEBUG_MAL_FACTORY
        fprintf(stderr, "#factoryMgr called\n");
 #endif
+       if(!cntxt->plants){
+               cntxt->plants = GDKzalloc(MAXPLANTS * sizeof(PlantRecord));
+               if(!cntxt->plants)
+                       throw(MAL, "factory.call", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+       }
+       cpl = cntxt->plants;
+
        /* the lookup can be largely avoided by handing out the index
           upon factory definition. todo
                Alternative is to move them to the front
         */
-       for(i=0; i< lastPlant; i++)
-       if( plants[i].factory == mb){
-               if(i > 0 && i< lastPlant ){
-                       PlantRecord prec= plants[i-1];
-                       plants[i-1] = plants[i];
-                       plants[i]= prec;
+       for(i=0; i< cntxt->lastPlant; i++)
+       if( cpl[i].factory == mb){
+               if(i > 0 && i< cntxt->lastPlant ){
+                       PlantRecord prec= cpl[i-1];
+                       cpl[i-1] = cpl[i];
+                       cpl[i]= prec;
                        i--;
                }
-               pl= plants+i;
+               pl= cpl+i;
                firstcall= FALSE;
                break;
        }
        if (pl == 0) {
                /* compress the plant table*/
-               for(k=i=0;i<=lastPlant; i++)
-               if( plants[i].inuse)
-                       plants[k++]= plants[i];
-               lastPlant = k;
+               for(k=i=0;i<=cntxt->lastPlant; i++)
+               if( cpl[i].inuse)
+                       cpl[k++]= cpl[i];
+               cntxt->lastPlant = k;
                /* initialize a new plant using the owner policy */
-               pl = newPlant(mb);
+               pl = newPlant(cntxt, mb);
                if (pl == NULL)
-                       throw(MAL, "factory.new", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+                       throw(MAL, "factory.call", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
        }
        /*
         * We have found a factory to process the request.
         * Let's call it as a synchronous action, without concern on 
parallelism.
         */
        /* remember context */
-       pl->client = cntxt;
        pl->caller = mbcaller;
        pl->env = stk;
        pl->pci = pci;
@@ -106,7 +124,7 @@ runFactory(Client cntxt, MalBlkPtr mb, M
        /* inherit debugging */
        cmd = stk->cmd;
        if ( pl->stk == NULL)
-               throw(MAL, "factory.new", "internal error, stack frame 
missing");
+               throw(MAL, "factory.call", "internal error, stack frame 
missing");
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to