Changeset: 6d7c262d201c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6d7c262d201c
Modified Files:
        gdk/gdk.h
        gdk/gdk_bbp.c
Branch: int128
Log Message:

increase GDKLIBRARY: 128-bit database is incompatible with 64-bit server and v.v

Databases that do (might) contain 128-bit integers (hge/HUGEINT)
cannot be opened with a server that does not support 128-bit integers;
hence, we now record in the BBP.dir header, whether the database was
created with largest (supported) integer being 64-bit or 128-bit,
increase GDKLIBRARY, and check compatibility when opening BBP.dir.

For now, this is strict conservative check, mutually excluding
64-bit and 128-bit databases.

In fact, a server with 128-bit integer support could easily and
safely open and read a database that was created without 128-bit
integer support, upgrading it on-the-fly. However, this would also
require a proper upgrade of the SQL catalog (if applicable).
For now, we have neither the check nor the upgrade implemented;
hence, we refrain from opening such "incompatible" databases.

Likewise, a server without 128-bit integer support could open
and read a database that was created with 128-bit integer support,
provided it does neither contain 128-bit integer data (BATs),
nor a SQL catalog (with, e.g., function signatures that require
type HUGEINT). Without having the respective checks implemented,
and considering it a rather rare case, we also disallow this
combination.


diffs (93 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -989,7 +989,8 @@ typedef struct {
 #define GDKLIBRARY_PRE_VARWIDTH 061023  /* backward compatible version */
 #define GDKLIBRARY_CHR         061024  /* version that still had chr type */
 #define GDKLIBRARY_SORTED_BYTE 061025  /* version that still had byte-sized 
sorted flag */
-#define GDKLIBRARY             061026
+#define GDKLIBRARY_64_BIT_INT  061026  /* version that had no 128-bit integer 
option, yet */
+#define GDKLIBRARY             061027
 
 typedef struct BAT {
        /* static bat properties */
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -908,11 +908,17 @@ BBPreadEntries(FILE *fp, int *min_stamp,
        }
 }
 
+#ifdef HAVE_HGE
+#define SIZEOF_MAX_INT SIZEOF_HGE
+#else
+#define SIZEOF_MAX_INT SIZEOF_LNG
+#endif
+
 static int
 BBPheader(FILE *fp, oid *BBPoid, int *OIDsize)
 {
        char buf[BUFSIZ];
-       int sz, bbpversion, ptrsize, oidsize;
+       int sz, bbpversion, ptrsize, oidsize, intsize;
        char *s;
 
        if (fgets(buf, sizeof(buf), fp) == NULL) {
@@ -925,6 +931,7 @@ BBPheader(FILE *fp, oid *BBPoid, int *OI
                exit(1);
        }
        if (bbpversion != GDKLIBRARY &&
+           bbpversion != GDKLIBRARY_64_BIT_INT &&
            bbpversion != GDKLIBRARY_SORTED_BYTE &&
            bbpversion != GDKLIBRARY_CHR &&
            bbpversion != GDKLIBRARY_PRE_VARWIDTH) {
@@ -933,8 +940,15 @@ BBPheader(FILE *fp, oid *BBPoid, int *OI
        if (fgets(buf, sizeof(buf), fp) == NULL) {
                GDKfatal("BBPinit: short BBP");
        }
-       if (sscanf(buf, "%d %d", &ptrsize, &oidsize) != 2) {
-               GDKfatal("BBPinit: BBP.dir has incompatible format: pointer and 
OID sizes are missing");
+       if (bbpversion <= GDKLIBRARY_64_BIT_INT) {
+               if (sscanf(buf, "%d %d", &ptrsize, &oidsize) != 2) {
+                       GDKfatal("BBPinit: BBP.dir has incompatible format: 
pointer and OID sizes are missing");
+               }
+               intsize = SIZEOF_LNG;
+       } else {
+               if (sscanf(buf, "%d %d %d", &ptrsize, &oidsize, &intsize) != 3) 
{
+                       GDKfatal("BBPinit: BBP.dir has incompatible format: 
pointer, OID, and max. integer sizes are missing");
+               }
        }
        if (ptrsize != SIZEOF_SIZE_T || oidsize != SIZEOF_OID) {
 #if SIZEOF_SIZE_T == 8 && SIZEOF_OID == 8
@@ -942,7 +956,12 @@ BBPheader(FILE *fp, oid *BBPoid, int *OI
 #endif
                GDKfatal("BBPinit: database created with incompatible server:\n"
                         "expected pointer size %d, got %d, expected OID size 
%d, got %d.",
-                        (int) SIZEOF_SIZE_T, ptrsize, (int) SIZEOF_OID, 
oidsize);
+                        SIZEOF_SIZE_T, ptrsize, SIZEOF_OID, oidsize);
+       }
+       if (intsize != SIZEOF_MAX_INT) {
+               GDKfatal("BBPinit: database created with incompatible server:\n"
+                        "expected max. integer size %d, got %d.",
+                        SIZEOF_MAX_INT, intsize);
        }
        if (OIDsize)
                *OIDsize = oidsize;
@@ -1226,7 +1245,7 @@ static int
 BBPdir_header(stream *s, int n)
 {
        if (mnstr_printf(s, "BBP.dir, GDKversion %d\n", GDKLIBRARY) < 0 ||
-           mnstr_printf(s, "%d %d\n", SIZEOF_SIZE_T, SIZEOF_OID) < 0 ||
+           mnstr_printf(s, "%d %d %d\n", SIZEOF_SIZE_T, SIZEOF_OID, 
SIZEOF_MAX_INT) < 0 ||
            OIDwrite(s) != 0 ||
            mnstr_printf(s, " BBPsize=%d\n", n) < 0)
                return -1;
@@ -1263,7 +1282,7 @@ BBPdir_subcommit(int cnt, bat *subcommit
        }
        /* read first three lines */
        if (fgets(buf, sizeof(buf), fp) == NULL || /* BBP.dir, GDKversion %d */
-           fgets(buf, sizeof(buf), fp) == NULL || /* SIZEOF_SIZE_T SIZEOF_OID 
*/
+           fgets(buf, sizeof(buf), fp) == NULL || /* SIZEOF_SIZE_T SIZEOF_OID 
SIZEOF_MAX_INT */
            fgets(buf, sizeof(buf), fp) == NULL) /* BBPsize=%d */
                GDKfatal("BBPdir: subcommit attempted with invalid backup 
BBP.dir.");
        /* third line contains BBPsize */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to