Changeset: fb731e605ae0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fb731e605ae0
Modified Files:
tools/merovingian/daemon/forkmserver.c
tools/merovingian/utils/properties.c
tools/merovingian/utils/properties.h
tools/merovingian/utils/utils.c
tools/merovingian/utils/utils.h
Branch: transaction-replication
Log Message:
Add monetdbd support for any property
- Do not modify the behaviour for the existing properties in monetdbd
- Pass any other properties verbatim as strings.
diffs (truncated from 316 to 300 lines):
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
@@ -63,7 +63,7 @@ forkMserver(char *database, sabdb** stat
char upmin[8];
char upavg[8];
char upmax[8];
- confkeyval *ckv, *kv;
+ confkeyval *ckv, *kv, *list;
SABdbState state;
er = msab_getStatus(stats, database);
@@ -113,7 +113,7 @@ forkMserver(char *database, sabdb** stat
}
ckv = getDefaultProps();
- readProps(ckv, (*stats)->path);
+ readAllProps(ckv, (*stats)->path);
kv = findConfKey(ckv, "type");
if (kv->val == NULL)
kv = findConfKey(_mero_db_props, "type");
@@ -280,7 +280,8 @@ forkMserver(char *database, sabdb** stat
char nclients[24];
char pipeline[512];
char *readonly = NULL;
- char *argv[24]; /* for the exec arguments */
+ char *argv[512]; /* for the exec arguments */
+ char property_other[1024];
int c = 0;
unsigned int mport;
@@ -323,9 +324,6 @@ forkMserver(char *database, sabdb** stat
if (kv->val != NULL && strcmp(kv->val, "no") != 0)
readonly = "--readonly";
- freeConfFile(ckv);
- free(ckv); /* can make ckv static and reuse it all the time */
-
/* redirect stdout and stderr to a new pair of fds for
* logging help */
close(pfdo[0]);
@@ -390,10 +388,25 @@ forkMserver(char *database, sabdb** stat
if (readonly != NULL) {
argv[c++] = readonly;
}
+ /* get the rest (non-default) mserver props set in the conf
file */
+ list = ckv;
+ while (list->key != NULL) {
+ if (list->val != NULL && !defaultProperty(list->key)) {
+ argv[c++] = "--set";
+ snprintf(property_other,
sizeof(property_other), "%s=%s", list->key, list->val);
+ argv[c++] = property_other;
+ }
+ list++;
+ }
+
/* keep this one last for easy copy/paste with gdb */
argv[c++] = "--set"; argv[c++] = "monet_daemon=yes";
+
argv[c++] = NULL;
+ freeConfFile(ckv);
+ free(ckv); /* can make ckv static and reuse it all the time */
+
fprintf(stdout, "arguments:");
for (c = 0; argv[c] != NULL; c++) {
/* very stupid heuristic to make copy/paste easier from
diff --git a/tools/merovingian/utils/properties.c
b/tools/merovingian/utils/properties.c
--- a/tools/merovingian/utils/properties.c
+++ b/tools/merovingian/utils/properties.c
@@ -34,7 +34,7 @@
"# This file is used by monetdbd\n\n"
/* these are the properties used for starting an mserver */
-static confkeyval _internal_prop_keys[] = {
+static confkeyval _internal_prop_keys[50] = {
{"type", NULL, 0, STR},
{"shared", NULL, 0, STR},
{"nthreads", NULL, 0, INT},
@@ -62,7 +62,7 @@ getDefaultProps(void)
/**
* Writes the given key-value list to MEROPROPFILE in the given path.
- * Returns 0 when the properties could be written to the file.
+ * Returns 0 when the properties could be successfully written to the file.
*/
inline int
writeProps(confkeyval *ckv, const char *path)
@@ -88,6 +88,30 @@ writeProps(confkeyval *ckv, const char *
}
/**
+ * Appends additional (non-default) property MEROPROPFILE in the given path.
+ * Returns 0 when the property could be successfully appended to the file.
+ */
+static inline int
+appendProp(confkeyval *ckv, const char *path)
+{
+ char file[1024];
+ FILE *cnf;
+
+ snprintf(file, 1024, "%s/" MEROPROPFILE, path);
+ if ((cnf = fopen(file, "a")) == NULL)
+ return(1);
+
+ if (ckv->key != NULL && ckv->val != NULL) {
+ fprintf(cnf, "%s=%s\n", ckv->key, ckv->val);
+ }
+
+ fflush(cnf);
+ fclose(cnf);
+
+ return(0);
+}
+
+/**
* Writes the given key-value list to a buffer and sets its pointer to
* buf. This function deals with the allocation of the buffer, hence
* the caller should free it.
@@ -137,6 +161,25 @@ readProps(confkeyval *ckv, const char *p
}
/**
+ * Read all properties from a property file.
+ * Returns 0 when reading the property file succeeded.
+ */
+inline int
+readAllProps(confkeyval *ckv, const char *path)
+{
+ char file[1024];
+ FILE *cnf;
+
+ snprintf(file, 1024, "%s/" MEROPROPFILE, path);
+ if ((cnf = fopen(file, "r")) != NULL) {
+ readConfFileFull(ckv, cnf);
+ fclose(cnf);
+ return(0);
+ }
+ return(1);
+}
+
+/**
* Read properties from buf, filling in the requested key-values.
*/
inline void
@@ -174,15 +217,8 @@ setProp(char *path, char *key, char *val
readProps(props, path);
kv = findConfKey(props, key);
- if (kv == NULL) {
- snprintf(buf, sizeof(buf), "no such property: %s", key);
- freeConfFile(props);
- free(props);
- return(strdup(buf));
- }
-
- /* first just attempt to set the value (type-check) in memory */
- if ((err = setConfVal(kv, val)) != NULL) {
+ if (kv != NULL && (err = setConfVal(kv, val)) != NULL) {
+ /* first just attempt to set the value (type-check) in memory */
freeConfFile(props);
free(props);
return(err);
@@ -225,10 +261,24 @@ setProp(char *path, char *key, char *val
value++;
}
}
+
+ /* ok, if we've reached this point we can write this stuff out!
*/
+ /* Let's check if this was a default property of an additional
one.
+ * Non-default properties will have a NULL kv */
+ if (kv == NULL) {
+ confkeyval *addProperty = (struct _confkeyval *)
malloc(sizeof(struct _confkeyval));
+ addProperty->key = strdup(key);
+ addProperty->val = strdup(val);
+ addProperty->ival = 0;
+ addProperty->type = STR;
+
+ appendProp(addProperty, path);
+ free(addProperty);
+ } else {
+ writeProps(props, path);
+ }
}
- /* ok, if we've reached this point we can write this stuff out! */
- writeProps(props, path);
freeConfFile(props);
free(props);
diff --git a/tools/merovingian/utils/properties.h
b/tools/merovingian/utils/properties.h
--- a/tools/merovingian/utils/properties.h
+++ b/tools/merovingian/utils/properties.h
@@ -28,6 +28,7 @@ confkeyval *getDefaultProps(void);
int writeProps(confkeyval *ckv, const char *path);
void writePropsBuf(confkeyval *ckv, char **buf);
int readProps(confkeyval *ckv, const char *path);
+int readAllProps(confkeyval *ckv, const char *path);
void readPropsBuf(confkeyval *ckv, char *buf);
char *setProp(char *path, char *key, char *val);
diff --git a/tools/merovingian/utils/utils.c b/tools/merovingian/utils/utils.c
--- a/tools/merovingian/utils/utils.c
+++ b/tools/merovingian/utils/utils.c
@@ -72,6 +72,45 @@ readConfFile(confkeyval *list, FILE *cnf
}
/**
+ * Parses the given file stream matching the and writes all values to the list.
+ */
+void
+readConfFileFull(confkeyval *list, FILE *cnf) {
+ char buf[1024];
+ char *key, *val;
+ char *separator = "=";
+ char *err;
+ confkeyval *t = list;
+
+ /* iterate until the end of the array */
+ while (list->key != NULL) {
+ list++;
+ }
+ /* read the file a line at a time */
+ while (fgets(buf, sizeof(buf), cnf) != NULL) {
+ if (strlen(buf) > 1 && buf[0] != '#') {
+ /* tokenize */
+ key = strtok(buf, separator);
+ val = strtok(NULL, separator);
+ /* strip trailing newline */
+ val = strtok(val, "\n");
+ /* check if it is default property or not. those are
set in a special way */
+ if (defaultProperty(key)) {
+ if ((err = setConfValForKey(t, key, val)) !=
NULL) {
+ free(err); /* ignore, just fall back to
default */
+ }
+ } else {
+ list->key = strdup(key);
+ list->val = strdup(val);
+ list->ival = 0;
+ list->type = STR;
+ list++;
+ }
+ }
+ }
+}
+
+/**
* Frees the values allocated by readConfFile().
*/
inline void
@@ -86,6 +125,27 @@ freeConfFile(confkeyval *list) {
}
/**
+ * True if the key is not a default property.
+ */
+inline int
+defaultProperty(char *property) {
+ if (property != NULL && strcmp(property, "type") == 0) {
+ return 1;
+ } else if (property != NULL && strcmp(property, "shared") == 0) {
+ return 1;
+ } else if (property != NULL && strcmp(property, "nthreads") == 0) {
+ return 1;
+ } else if (property != NULL && strcmp(property, "readonly") == 0) {
+ return 1;
+ } else if (property != NULL && strcmp(property, "nclients") == 0) {
+ return 1;
+ } else if (property != NULL && strcmp(property, "mfunnel") == 0) {
+ return 1;
+ }
+ return 0;
+}
+
+/**
* Returns a pointer to the key-value that has a matching key with the
* given key, or NULL if no key was found.
*/
@@ -218,6 +278,19 @@ setConfVal(confkeyval *ckv, char *val) {
return(NULL);
}
+char *
+setConfValForKey(confkeyval *list, char *key, char *val) {
+ while (list->key != NULL) {
+ if (strcmp(list->key, key) == 0) {
+ return setConfVal(list, val);
+ }
+ list++;
+ }
+ char buf[256];
+ snprintf(buf, sizeof(buf), "key '%s' is not recognized, internal
error", key);
+ return(strdup(buf));
+}
+
/**
* Fills the array pointed to by buf with a human representation of t.
* The argument longness represents the number of units to print
diff --git a/tools/merovingian/utils/utils.h b/tools/merovingian/utils/utils.h
--- a/tools/merovingian/utils/utils.h
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list