Changeset: 020e1d9adae8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=020e1d9adae8
Modified Files:
monetdb5/extras/jaql/Tests/json05.stable.out
monetdb5/extras/jaql/json.c
tools/merovingian/ChangeLog.Jul2012
tools/merovingian/daemon/forkmserver.c
tools/merovingian/daemon/merovingian.c
tools/mserver/mserver5.c
Branch: default
Log Message:
Merged from Jul2012
diffs (truncated from 584 to 300 lines):
diff --git a/monetdb5/extras/jaql/Tests/json05.stable.out
b/monetdb5/extras/jaql/Tests/json05.stable.out
--- a/monetdb5/extras/jaql/Tests/json05.stable.out
+++ b/monetdb5/extras/jaql/Tests/json05.stable.out
@@ -61,7 +61,7 @@ end main;
[ 0@0, 1 ]
[ 0@0, 1 ]
[ 0@0, 2.2999999999999998 ]
-[ 0@0, inf ]
+[ 0@0, 0 ]
[ 0@0, 4 ]
[ "str" ]
#---------------------------------#
diff --git a/monetdb5/extras/jaql/json.c b/monetdb5/extras/jaql/json.c
--- a/monetdb5/extras/jaql/json.c
+++ b/monetdb5/extras/jaql/json.c
@@ -1462,7 +1462,7 @@ JSONunwrap(Client cntxt, MalBlkPtr mb, M
break;
case 'n':
default:
- d = 0.1 / (1.0
- 1.0);
+ d = 0.0;
BUNins(r, &v,
&d, FALSE);
break;
}
diff --git a/tools/merovingian/ChangeLog.Jul2012
b/tools/merovingian/ChangeLog.Jul2012
--- a/tools/merovingian/ChangeLog.Jul2012
+++ b/tools/merovingian/ChangeLog.Jul2012
@@ -1,3 +1,7 @@
# ChangeLog file for sql/src/backends/monet5/merovingian
# This file is updated with mchangelog
+* Wed Jul 18 2012 Fabian Groffen <[email protected]>
+- Resolved a problem where automatic starting of a database initiated by
+ multiple clients at the same time could cause failed starts. Bug #3107
+
diff --git a/tools/merovingian/daemon/forkmserver.c
b/tools/merovingian/daemon/forkmserver.c
--- a/tools/merovingian/daemon/forkmserver.c
+++ b/tools/merovingian/daemon/forkmserver.c
@@ -40,6 +40,8 @@
#include "forkmserver.h"
+static pthread_mutex_t fork_lock = PTHREAD_MUTEX_INITIALIZER;
+
/**
* Fork an mserver and detach. Before forking off, Sabaoth is consulted
* to see if forking makes sense, or whether it is necessary at all, or
@@ -86,6 +88,29 @@ forkMserver(char *database, sabdb** stat
* more than one entry in the list, so we assume we have the right
* one here. */
+ if ((*stats)->state == SABdbRunning)
+ /* return before doing expensive stuff, when this db just seems
+ * to be running */
+ return(NO_ERR);
+
+ /* Make sure we only start one mserver5 at the same time, this is a
+ * horsedrug for preventing race-conditions where two or more
+ * clients start the same database at the same time, because they
+ * were all identified as being SABdbInactive. If this "global"
+ * lock ever becomes a problem, we can reduce it to a per-database
+ * lock instead. */
+ pthread_mutex_lock(&fork_lock);
+
+ /* refetch the status, as it may have changed */
+ msab_freeStatus(stats);
+ er = msab_getStatus(stats, database);
+ if (er != NULL) {
+ err e = newErr("%s", er);
+ free(er);
+ pthread_mutex_unlock(&fork_lock);
+ return(e);
+ }
+
ckv = getDefaultProps();
readProps(ckv, (*stats)->path);
kv = findConfKey(ckv, "type");
@@ -98,6 +123,7 @@ forkMserver(char *database, sabdb** stat
kv->val, database);
freeConfFile(ckv);
free(ckv);
+ pthread_mutex_unlock(&fork_lock);
return(NO_ERR);
} else {
Mfprintf(stdout, "startup of %s under maintenance "
@@ -113,6 +139,7 @@ forkMserver(char *database, sabdb** stat
msab_freeStatus(stats);
freeConfFile(ckv);
free(ckv);
+ pthread_mutex_unlock(&fork_lock);
return(e);
}
@@ -120,6 +147,7 @@ forkMserver(char *database, sabdb** stat
case SABdbRunning:
freeConfFile(ckv);
free(ckv);
+ pthread_mutex_unlock(&fork_lock);
return(NO_ERR);
case SABdbCrashed:
t = localtime(&info.lastcrash);
@@ -152,6 +180,7 @@ forkMserver(char *database, sabdb** stat
msab_freeStatus(stats);
freeConfFile(ckv);
free(ckv);
+ pthread_mutex_unlock(&fork_lock);
return(newErr("unknown state: %d",
(int)(*stats)->state));
}
@@ -161,6 +190,7 @@ forkMserver(char *database, sabdb** stat
msab_freeStatus(stats);
freeConfFile(ckv);
free(ckv);
+ pthread_mutex_unlock(&fork_lock);
return(newErr("unable to create pipe: %s", strerror(errno)));
}
if (pipe(pfde) == -1) {
@@ -169,6 +199,7 @@ forkMserver(char *database, sabdb** stat
msab_freeStatus(stats);
freeConfFile(ckv);
free(ckv);
+ pthread_mutex_unlock(&fork_lock);
return(newErr("unable to create pipe: %s", strerror(errno)));
}
@@ -198,6 +229,7 @@ forkMserver(char *database, sabdb** stat
getErrMsg(er));
freeConfFile(ckv);
free(ckv);
+ pthread_mutex_unlock(&fork_lock);
return(er);
}
freeConfFile(ckv);
@@ -211,8 +243,10 @@ forkMserver(char *database, sabdb** stat
* it's not really a problem we exit here */
err e = newErr("%s", er);
free(er);
+ pthread_mutex_unlock(&fork_lock);
return(e);
}
+ pthread_mutex_unlock(&fork_lock);
return(NO_ERR);
}
@@ -223,6 +257,7 @@ forkMserver(char *database, sabdb** stat
msab_freeStatus(stats);
freeConfFile(ckv);
free(ckv);
+ pthread_mutex_unlock(&fork_lock);
return(newErr("cannot start database '%s': no .vaultkey found "
"(did you create the database with
`monetdb create %s`?)",
database, database));
@@ -411,6 +446,7 @@ forkMserver(char *database, sabdb** stat
* it's not really a problem we exit here */
err e = newErr("%s", er);
free(er);
+ pthread_mutex_unlock(&fork_lock);
return(e);
}
if ((*stats)->state == SABdbRunning &&
@@ -458,6 +494,7 @@ forkMserver(char *database, sabdb** stat
* starting */
if (dp == NULL) {
pthread_mutex_unlock(&_mero_topdp_lock);
+ pthread_mutex_unlock(&fork_lock);
switch (state) {
case SABdbRunning:
/* right, it's not there, but
it's running */
@@ -488,6 +525,7 @@ forkMserver(char *database, sabdb** stat
* we don't want */
terminateProcess(dp);
pthread_mutex_unlock(&_mero_topdp_lock);
+ pthread_mutex_unlock(&fork_lock);
switch (state) {
case SABdbRunning:
@@ -530,6 +568,7 @@ forkMserver(char *database, sabdb** stat
"mode during startup\n", database);
}
+ pthread_mutex_unlock(&fork_lock);
return(NO_ERR);
}
/* forking failed somehow, cleanup the pipes */
diff --git a/tools/merovingian/daemon/merovingian.c
b/tools/merovingian/daemon/merovingian.c
--- a/tools/merovingian/daemon/merovingian.c
+++ b/tools/merovingian/daemon/merovingian.c
@@ -48,13 +48,11 @@
* number of times over a recent period. Note that to date, no such
* thing has been implemented as the need for it has not arisen yet.
*
- * By default, merovingian will monitor and control the dbfarm in the
- * build-time configured prefix under var/monetdb5/dbfarm. However,
- * when a path is given as first argument, merovingian will attempt to
- * monitor and control the directory the path points to. This allows
- * users to create their own dbfarm, but also expert users to run
- * multiple merovingians on the same system easily, since the
- * (persistent) configuration is read from the dbfarm directory.
+ * merovingian will monitor and control the dbfarm given by path in the
+ * first argument. This allows users to create their own dbfarm, but
+ * also expert users to run multiple merovingians on the same system
+ * easily, since the (persistent) configuration is read from the dbfarm
+ * directory.
*/
#include "monetdb_config.h"
diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c
--- a/tools/mserver/mserver5.c
+++ b/tools/mserver/mserver5.c
@@ -46,14 +46,14 @@
#endif
#ifdef _MSC_VER
-#include <Psapi.h> /* for GetModuleFileName */
+#include <Psapi.h> /* for GetModuleFileName */
#endif
#ifdef _CRTDBG_MAP_ALLOC
/* Windows only:
our definition of new and delete clashes with the one if
_CRTDBG_MAP_ALLOC is defined.
-*/
+ */
#undef _CRTDBG_MAP_ALLOC
#endif
@@ -75,7 +75,7 @@ mserver_abort()
#endif
static void usage(char *prog)
- __attribute__((__noreturn__));
+__attribute__((__noreturn__));
static void
usage(char *prog)
@@ -92,20 +92,20 @@ usage(char *prog)
fprintf(stderr, " --help Print this list of
options\n");
fprintf(stderr, " --version Print version and
compile time info\n");
- fprintf(stderr,"The debug, testing & trace options:\n");
- fprintf(stderr," --threads\n");
- fprintf(stderr," --memory\n");
- fprintf(stderr," --io\n");
- fprintf(stderr," --heaps\n");
- fprintf(stderr," --properties\n");
- fprintf(stderr," --transactions\n");
- fprintf(stderr," --modules\n");
- fprintf(stderr," --algorithms\n");
- fprintf(stderr," --xproperties\n");
- fprintf(stderr," --performance\n");
- fprintf(stderr," --optimizers\n");
- fprintf(stderr," --forcemito\n");
- fprintf(stderr," --debug=<bitmask>\n");
+ fprintf(stderr, "The debug, testing & trace options:\n");
+ fprintf(stderr, " --threads\n");
+ fprintf(stderr, " --memory\n");
+ fprintf(stderr, " --io\n");
+ fprintf(stderr, " --heaps\n");
+ fprintf(stderr, " --properties\n");
+ fprintf(stderr, " --transactions\n");
+ fprintf(stderr, " --modules\n");
+ fprintf(stderr, " --algorithms\n");
+ fprintf(stderr, " --xproperties\n");
+ fprintf(stderr, " --performance\n");
+ fprintf(stderr, " --optimizers\n");
+ fprintf(stderr, " --forcemito\n");
+ fprintf(stderr, " --debug=<bitmask>\n");
exit(0);
}
@@ -119,9 +119,9 @@ monet_hello(void)
char *linkinfo = "dynamically";
#endif
- dbl sz_mem_h;
+ dbl sz_mem_h;
char *qc = " kMGTPE";
- int qi = 0;
+ int qi = 0;
monet_memory = MT_npages() * MT_pagesize();
sz_mem_h = (dbl) monet_memory;
@@ -140,7 +140,7 @@ monet_hello(void)
GDKnr_threads, (GDKnr_threads != 1) ? "s" : "");
printf("# Compiled for %s/" SZFMT "bit with " SZFMT "bit OIDs %s
linked\n",
HOST, sizeof(ptr) * 8, sizeof(oid) * 8, linkinfo);
- printf("# Found %.3f %ciB available main-memory.\n",
+ printf("# Found %.3f %ciB available main-memory.\n",
sz_mem_h, qc[qi]);
#ifdef MONET_GLOBAL_DEBUG
printf("# Database farm:%s\n", GDKgetenv("gdk_dbfarm"));
@@ -157,7 +157,7 @@ absolute_path(str s)
if (!MT_path_absolute(s)) {
str ret = (str) GDKmalloc(strlen(s) + strlen(monet_cwd) + 2);
- if ( ret )
+ if (ret)
sprintf(ret, "%s%c%s", monet_cwd, DIR_SEP, s);
return ret;
}
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list