Changeset: 034226e67101 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/034226e67101
Modified Files:
gdk/gdk_bbp.c
gdk/gdk_logger.c
monetdb5/modules/atoms/json.c
Branch: Dec2023
Log Message:
Upgrade json values in the WAL
diffs (136 lines):
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1709,7 +1709,6 @@ BBPjson_upgrade(json_storage_conversion
return GDK_FAIL;
}
GDKfree(upd);
- GDKunlink(0, BATDIR, "jsonupgradeneeded", NULL);
return GDK_SUCCEED;
}
#endif
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1894,6 +1894,21 @@ log_cleanup(logger *lg, lng id)
return GDK_SUCCEED;
}
+#ifdef GDKLIBRARY_JSON
+static gdk_return
+log_json_upgrade_finalize(void)
+{
+ int json_tpe = ATOMindex("json");
+ if (GDKunlink(0, BATDIR, "jsonupgradeneeded", NULL) == GDK_FAIL) {
+ TRC_CRITICAL(GDK, "Failed to remove json upgrade signal file");
+ return GDK_FAIL;
+ }
+ BATatoms[json_tpe].atomRead = (void *(*)(void *, size_t *, stream *,
size_t))strRead;
+
+ return GDK_SUCCEED;
+}
+#endif
+
/* Load data from the logger logdir
* Initialize new directories and catalog files if none are present,
* unless running in read-only mode
@@ -2200,6 +2215,10 @@ log_load(const char *fn, const char *log
} else {
lg->id = lg->saved_id + 1;
}
+#ifdef GDKLIBRARY_JSON
+ if (log_json_upgrade_finalize() == GDK_FAIL)
+ goto error;
+#endif
return GDK_SUCCEED;
error:
if (fp)
@@ -2221,6 +2240,10 @@ log_load(const char *fn, const char *log
GDKfree(lg->wbuf);
GDKfree(lg);
ATOMIC_SET(&GDKdebug, dbg);
+ /* We do not call log_json_upgrade_finalize here because we want
+ * the upgrade to run again next time we try, so we do not want
+ * to remove the signal file just yet.
+ */
return GDK_FAIL;
}
diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -582,16 +582,38 @@ JSONisarray(bit *ret, json *js)
}
#ifdef GDKLIBRARY_JSON
-static
-gdk_return upgradeJSONStorage(char **out, const char **in) {
+static gdk_return
+upgradeJSONStorage(char **out, const char **in)
+{
if (JSONstr2json(out, in) != MAL_SUCCEED) {
return GDK_FAIL;
}
return GDK_SUCCEED;
}
+static str
+jsonRead(str a, size_t *dstlen, stream *s, size_t cnt)
+{
+ str out = NULL;
+
+ if (BATatoms[TYPE_str].atomRead(a, dstlen, s, cnt) == NULL)
+ return NULL;
+
+ if (upgradeJSONStorage(&out, (const char **) &a) != GDK_SUCCEED) {
+ GDKfree(a);
+ return NULL;
+ }
+ *dstlen = strlen(out) + 1;
+ GDKfree(a);
+
+ a = out;
+
+ return a;
+}
+
#endif
+
static str
JSONprelude(void)
{
@@ -603,15 +625,19 @@ JSONprelude(void)
char *jsonupgrade;
struct stat st;
if ((jsonupgrade = GDKfilepath(0, BATDIR, "jsonupgradeneeded", NULL))
== NULL) {
- throw(MAL, "json.prelude", SQLSTATE(HY013) MAL_MALLOC_FAIL); //
Fix exception reason
+ throw(MAL, "json.prelude", "cannot allocate filename for json
upgrade signal file");
}
int r = stat(jsonupgrade, &st);
if (r == 0) {
/* The file exists so we need to run the upgrade code */
if (BBPjson_upgrade(upgradeJSONStorage) != GDK_SUCCEED) {
GDKfree(jsonupgrade);
- throw(MAL, "json.prelude", "JSON storage upgrade
failed"); // Fix exception reason
+ throw(MAL, "json.prelude", "JSON storage upgrade
failed");
}
+ /* Change the read function of the json atom so that any values
in the WAL
+ * will also be upgraded.
+ */
+ BATatoms[TYPE_json].atomRead = (void *(*)(void *, size_t *,
stream *, size_t)) jsonRead;
}
GDKfree(jsonupgrade);
#endif
@@ -3164,9 +3190,10 @@ JSONsubjson(bat *retval, bat *bid, bat *
return JSONsubjsoncand(retval, bid, gid, eid, NULL, skip_nils);
}
+
#include "mel.h"
static mel_atom json_init_atoms[] = {
- { .name="json", .basetype="str", .fromstr=JSONfromString,
.tostr=JSONtoString, }, { .cmp=NULL }
+ { .name="json", .basetype="str", .fromstr=JSONfromString,
.tostr=JSONtoString }, { .cmp=NULL },
};
static mel_func json_init_funcs[] = {
command("json", "new", JSONstr2json, false, "Convert string to its JSON.
Dealing with escape characters", args(1,2, arg("",json),arg("j",str))),
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]