Changeset: edd9b49ac528 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=edd9b49ac528 Removed Files: monetdb5/mal/mal_box.c monetdb5/mal/mal_box.h Branch: default Log Message:
Remove the Box semantics The Box semantics was originally introduced to enable simple key-value pairs to be associated with MAL blocks as a kind of persistent variables. It was also intended to orchestrate access control to these variables. It was never really exploited within the code base. As such, after a decade of useless inclusion, it has be dropped for ease of code maintenance. A more versatile key-value store will be sufficient for the cases anticipated. diffs (truncated from 827 to 300 lines): diff --git a/monetdb5/mal/mal_box.c b/monetdb5/mal/mal_box.c deleted file mode 100644 --- a/monetdb5/mal/mal_box.c +++ /dev/null @@ -1,766 +0,0 @@ -/* - * The contents of this file are subject to the MonetDB Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.monetdb.org/Legal/MonetDBLicense - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is the MonetDB Database System. - * - * The Initial Developer of the Original Code is CWI. - * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. - * Copyright August 2008-2014 MonetDB B.V. - * All Rights Reserved. - */ - -/* - * @a M.L. Kersten - * @+ Boxed Variables - * Clients sessions often come with a global scope of variable settings. - * Access to these global variables should be easy, - * but they should also provide protection against concurrent update - * when the client wishes to perform parallel processing. - * Likewise, databases, query languages, etc. may define constants and variables - * accessible, e.g., relational schemas, to a selected user group. - * - * The approach taken is to rely on persistent object spaces - * as pioniered in Lynda and -later- JavaSpaces. - * They are called boxes in MonetDB and act as managed containers - * for persistent variables. - * - * Before a client program can interact with a box, it - * should open it, passing qualifying authorization - * information and parameters to instruct the box-manager - * of the intended use. A built-in box is implicitly - * opened when you request for its service. - * - * At the end of a session, the box should be closed. Some box-managers - * may implement a lease-scheme to automatically close interaction - * with a client when the lease runs out. Likewise, the box can - * be notified when the last reference to a leased object - * ceases to exist. - * - * A box can be extended with a new object using the function - * deposit(name) with name a local variable. - * The default implementation silently accepts any new definition of the box. - * If the variable was known already in the box, its value is overwritten. - * - * A local copy of an object can be obtained using the - * pattern 'take(name,[param])', where name denotes the variable - * of interest. The type of the receiving variable should - * match the one known for the object. Whether an actual - * copy is produced or a reference to a shared object - * is returned is defined by the box manager. - * - * The object is given back to the box manager calling 'release(name)'. - * It may update the content of the repository accordingly, release locks, - * and move the value to persistent store. Whatever the semantics - * of the box requires. [The default implementation is a no-op] - * - * Finally, the object manager can be requested to 'discard(name)' - * a variable completely. The default implementation is to reclaim - * the space in the box. - * - * Concurrency control, replication services, as well as access - * to remote stores may be delegated to a box manager. - * Depending on the intended semantics, the box manager - * may keep track of the clients holding links to this members, - * provide a traditional 2-phase - * locking scheme, optimistic control, or check-out/check-in scheme. - * In all cases, these management issues are transparant to the - * main thread (=client) of control, which operates on a temporary - * snapshot. For the time being we realize the managers as critical - * code sections, i.e. one client is permitted access to the box space - * at a time. - * - * Fo example, consider the client function: - * @example - * function myfcn():void; - * b:bat[:oid,:int] := bbp.take("mytable"); - * c:bat[:int,:str] := sql.take("person","age"); - * d:= intersect(b,c); - * io.print(d); - * u:str:= client.take(user); - * io.print(u); - * client.release(user); - * end function; - * @end example - * - * The function binds to a copy from the local persistent BAT space, - * much like bat-names are resolved in earlier MonetDB versions. The second - * statement uses an implementation of take that searches a variable - * of interest using two string properties. It illustrates that - * a box manager is free to extend/overload the predefined scheme, - * which is geared towards storing MAL variables. - * - * The result bat @sc{c} is temporary and disappears upon garbage - * collection. The variable @sc{u} is looked up as the string object user. - * - * Note that BATs @sc{b} and @sc{c} need be released at some point. In general - * this point in time does not coincide with a computational boundary - * like a function return. During a session, several bats may be taken - * out of the box, being processed, and only at the end of a session - * being released. In this example, it means that the reference to - * b and c is lost at the end of the function (due to garbarge collection) - * and that subsequent use requires another take() call. - * The box manager bbp is notified of the implicit release and - * can take garbage collection actions. - * - * The box may be inspected at several times during a scenario run. - * The first time is when the MAL program is type-checked for the - * box operations. Typechecking a take() function is tricky. - * If the argument is a string literal, the box can be queried - * directly for the objects' type. - * If found, its type is matched against the lhs variable. - * This strategy fails in the situation when at - * runtime the object is subsequently replaced by another - * typed-instance in the box. We assume this not to happen and - * the exceptions it raises a valuable advice to reconsider - * the programming style. - * - * The type indicator for the destination variable should be - * provided to proceed with proper type checking. - * It can resolve overloaded function selection. - * - * Inspection of the Box can be encoded using an iterator at the MAL - * layer and relying on the functionality of the box. - * However, to improve introspection, we assume that all box - * implementations provide a few rudimentary functions, called objects(arglist) - * and dir(arglist). The function objects() produces a BAT with - * the object names, possibly limited to those identified by - * the arglist. - * - * The world of boxes has not been explored deeply yet. - * It is envisioned that it could play a role to import/export - * different objects, e.g., - * introduce xml.take() which converts an XML document to a BAT, - * jpeg.take() similer for an image. - * - * Nesting boxes is possible. It provides a simple - * containment scheme between boxes, but in general will interfere with - * the semantics of each box. - * - * Each box has (should) have an access control list, which names - * the users having permission to read/write its content. - * The first one to create the box becomes the owner. He may grant/revoke - * access to the box to users on a selective basis. - * - * @- Session Box - * Aside from box associated with the modules, a session box is created - * dynamically on behalf of each client. Such boxes are considered private - * and require access by the user name (and password). - * At the end of a session they are closed, which means that they are - * saved in persistent store until the next session starts. - * For example: - * @example - * function m():void; - * box.open("client_name"); - * box.deposit("client_name","pi",3.417:flt); - * f:flt := box.take("client_name","pi"); - * io.print(t); - * box.close("client_name"); - * end function; - * @end example - * @- - * In the namespace it is placed subordinate to any space introduced by the - * system administrator. It will contain global client data, e.g., - * user, language, database, port, and any other session parameter. - * The boxes are all collected in the context of the database directory, - * i.e. the directory <dbpath>/box - * - * @- Garbage Collection - * The key objects managed by MonetDB are the persistent BATs, which - * call for an efficient scheme to make them accessible for manipulation - * in the MAL procedures taking into account a possibly hostile - * parallel access. - * - * Most kernel routines produce BATs as a result, which will be referenced - * from the runtime stack. They should be garbage collected as soon as - * deemed possible to free-up space. By default, temporary results are - * garbage collected before returning from a MAL function. - * - * @- Globale Environment - * The top level interaction keeps a 'box' with global variables, - * i.e. each MAL statement is interpreted in an already initialized - * stack frame. - * This causes the following problems: 1) how to get rid of global variables - * and 2) how to deal with variables that can take 'any' type. - * It is illustrated as follows: - * @example - * f:= const.take("dbname"); - * io.print(f); - * @end example - * When executed in the context of a function, the answer will be - * simple [ nil ]. The reason is that the expecteed type is not known - * at compilation time. The correct definition would have been - * @example - * f:str:= const.take("dbname"); - * io.print(f); - * @end example - */ -/* - * The hierarchy of object spaces ends at the root of the tree. - * This is a dummy element and should contain system-wide objects - * only. - */ - -#include "monetdb_config.h" -#include "mal_box.h" -#include "mal_interpreter.h" /* for garbageCollector() & garbageElement() */ -#include "mal_client.h" -#include "mal_private.h" - -#if defined(_MSC_VER) && _MSC_VER >= 1400 -#define access _access -#define chmod _chmod -#endif - -#define MAXSPACES 64 /* >MAXCLIENTS+ max modules !! */ -static Box malbox[MAXSPACES]; -static int topbox=0; - -static str boxFileName(Box box, str extension); -static int saveBox(Box box, int flag); -static void loadBox(str name); - -static Box -newBox(str name) -{ - Box obj = 0; - int i; - - MT_lock_set(&mal_contextLock, "newBox"); -#ifdef DEBUG_MAL_BOX - mnstr_printf(GDKout, "create new box '%s'\n", name); -#endif - for (i = 0; i < topbox; i++) - if (malbox[i] != NULL && idcmp(name, malbox[i]->name) == 0) { - MT_lock_unset(&mal_contextLock, "newBox"); -#ifdef DEBUG_MAL_BOX - mnstr_printf(GDKout,"newBox:duplicate box definition\n"); -#endif - return malbox[i]; - } - for (i = 0; i < topbox; i++) - if (malbox[i] == NULL) { - obj= (Box) GDKzalloc(sizeof(BoxRecord)); - if( obj == NULL){ - showException(GDKout, MAL,"box.new", MAL_MALLOC_FAIL); - return NULL; - } - obj->name= GDKstrdup(name); - obj->sym= newMalBlk(MAXVARS,STMT_INCREMENT); - obj->val = newGlobalStack(MAXVARS); - if ( obj->val == NULL || obj->sym == NULL){ - showException(GDKout, MAL,"box.new", MAL_MALLOC_FAIL); - return NULL; - } - MT_lock_init(&obj->lock,"M5_box_lock"); - malbox[i] = obj; - break; - } - MT_lock_unset(&mal_contextLock, "newBox"); - if (i == topbox) { - if ( topbox < MAXSPACES){ - obj= (Box) GDKzalloc(sizeof(BoxRecord)); - if( obj == NULL){ - showException(GDKout, MAL,"box.new", MAL_MALLOC_FAIL); - return NULL; - } - obj->name= GDKstrdup(name); - obj->sym= newMalBlk(MAXVARS,STMT_INCREMENT); - obj->val = newGlobalStack(MAXVARS); - if ( obj->val == NULL || obj->sym == NULL){ - showException(GDKout, MAL,"box.new", MAL_MALLOC_FAIL); - return NULL; - } - MT_lock_init(&obj->lock,"M5_box_lock"); - malbox[topbox++] = obj; - } else - return NULL; - } -#ifdef DEBUG_MAL_BOX - mnstr_printf(GDKout, "succeeded at %d\n", i); -#endif - return obj; - -} - -#if 0 -static void -freeBox(Client cntxt, int i){ _______________________________________________ checkin-list mailing list [email protected] https://www.monetdb.org/mailman/listinfo/checkin-list
