Changeset: e51de744e5da for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/e51de744e5da Modified Files: clients/Tests/exports.stable.out gdk/ChangeLog gdk/gdk_bbp.c gdk/gdk_bbp.h gdk/gdk_private.h gdk/gdk_utils.c sql/storage/bat/bat_logger.c sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py sql/test/emptydb-previous-upgrade/Tests/upgrade.py sql/test/emptydb-upgrade-chain/Tests/upgrade.py sql/test/emptydb-upgrade/Tests/upgrade.py sql/test/testdb-previous-upgrade-chain/Tests/upgrade.py sql/test/testdb-previous-upgrade/Tests/upgrade.py sql/test/testdb-upgrade-chain/Tests/upgrade.py sql/test/testdb-upgrade/Tests/upgrade.py tools/mserver/mserver5.1.in Branch: default Log Message:
Prevent accidental upgrade from no-128 bits to 128-bit integer. diffs (255 lines): diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -212,7 +212,7 @@ BBPrec *BBP[N_BBPINIT]; gdk_return BBPaddfarm(const char *dirname, uint32_t rolemask, bool logerror); void BBPcold(bat i); int BBPfix(bat b); -unsigned BBPheader(FILE *fp, int *lineno, bat *bbpsize, lng *logno, lng *transid); +unsigned BBPheader(FILE *fp, int *lineno, bat *bbpsize, lng *logno, lng *transid, bool allow_hge_upgrade); bat BBPindex(const char *nme); void BBPkeepref(BAT *b) __attribute__((__nonnull__(1))); bat BBPlimit; diff --git a/gdk/ChangeLog b/gdk/ChangeLog --- a/gdk/ChangeLog +++ b/gdk/ChangeLog @@ -1,3 +1,9 @@ # ChangeLog file for GDK # This file is updated with Maddlog +* Thu Sep 28 2023 Sjoerd Mullender <sjo...@acm.org> +- We now prevent accidental upgrades from a database without 128 bit + integers to one with 128 bit integers (also known as HUGEINT) from + happening. Upgrades will only be done if the server is started with + the option --set allow_hge_upgrade=yes. + diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -985,7 +985,7 @@ BBPcheckbats(unsigned bbpversion) #endif unsigned -BBPheader(FILE *fp, int *lineno, bat *bbpsize, lng *logno, lng *transid) +BBPheader(FILE *fp, int *lineno, bat *bbpsize, lng *logno, lng *transid, bool allow_hge_upgrade) { char buf[BUFSIZ]; int sz, ptrsize, oidsize, intsize; @@ -1034,6 +1034,13 @@ BBPheader(FILE *fp, int *lineno, bat *bb SIZEOF_MAX_INT, intsize); return 0; } + if (intsize < SIZEOF_MAX_INT && !allow_hge_upgrade) { + TRC_CRITICAL(GDK, "database created with incompatible server: " + "expected max. integer size %d, got %d; " + "use --set allow_hge_upgrade=yes to upgrade.", + SIZEOF_MAX_INT, intsize); + return 0; + } if (fgets(buf, sizeof(buf), fp) == NULL) { TRC_CRITICAL(GDK, "short BBP"); return 0; @@ -1548,7 +1555,7 @@ BBPmanager(void *dummy) static MT_Id manager; gdk_return -BBPinit(void) +BBPinit(bool allow_hge_upgrade) { FILE *fp = NULL; struct stat st; @@ -1678,7 +1685,7 @@ BBPinit(void) bbpversion = GDKLIBRARY; } else { lng logno, transid; - bbpversion = BBPheader(fp, &lineno, &bbpsize, &logno, &transid); + bbpversion = BBPheader(fp, &lineno, &bbpsize, &logno, &transid, allow_hge_upgrade); if (bbpversion == 0) { ATOMIC_SET(&GDKdebug, dbg); return GDK_FAIL; @@ -3692,7 +3699,7 @@ BBPcheckBBPdir(void) if (fp == NULL) return; } - bbpversion = BBPheader(fp, &lineno, &bbpsize, &logno, &transid); + bbpversion = BBPheader(fp, &lineno, &bbpsize, &logno, &transid, false); if (bbpversion == 0) { fclose(fp); return; /* error reading file */ diff --git a/gdk/gdk_bbp.h b/gdk/gdk_bbp.h --- a/gdk/gdk_bbp.h +++ b/gdk/gdk_bbp.h @@ -59,7 +59,7 @@ #define BBPTRIM_ALL (((size_t)1) << (sizeof(size_t)*8 - 2)) /* very large positive size_t */ gdk_export bat getBBPsize(void); /* current occupied size of BBP array */ -gdk_export unsigned BBPheader(FILE *fp, int *lineno, bat *bbpsize, lng *logno, lng *transid); +gdk_export unsigned BBPheader(FILE *fp, int *lineno, bat *bbpsize, lng *logno, lng *transid, bool allow_hge_upgrade); gdk_export int BBPreadBBPline(FILE *fp, unsigned bbpversion, int *lineno, BAT *bn, #ifdef GDKLIBRARY_HASHASH int *hashash, diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h --- a/gdk/gdk_private.h +++ b/gdk/gdk_private.h @@ -110,7 +110,7 @@ void BBPdump(void) /* never called: for __attribute__((__cold__)); void BBPexit(void) __attribute__((__visibility__("hidden"))); -gdk_return BBPinit(void) +gdk_return BBPinit(bool allow_hge_upgrade) __attribute__((__visibility__("hidden"))); bat BBPinsert(BAT *bn) __attribute__((__warn_unused_result__)) diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c --- a/gdk/gdk_utils.c +++ b/gdk/gdk_utils.c @@ -1068,7 +1068,8 @@ GDKinit(opt *set, int setlen, bool embed else #endif GDK_mem_maxsize = (size_t) ((double) MT_npages() * (double) MT_pagesize() * 0.815); - if (BBPinit() != GDK_SUCCEED) + const char *allow = mo_find_option(set, setlen, "allow_hge_upgrade"); + if (BBPinit(allow && strcmp(allow, "yes") == 0) != GDK_SUCCEED) return GDK_FAIL; first = false; diff --git a/sql/storage/bat/bat_logger.c b/sql/storage/bat/bat_logger.c --- a/sql/storage/bat/bat_logger.c +++ b/sql/storage/bat/bat_logger.c @@ -3501,7 +3501,7 @@ snapshot_bats(stream *plan, const char * GDKerror("Could not open %s for reading: %s", bbpdir, mnstr_peek_error(NULL)); return GDK_FAIL; } - bbpversion = BBPheader(fp, &lineno, &bbpsize, &logno, &transid); + bbpversion = BBPheader(fp, &lineno, &bbpsize, &logno, &transid, false); if (bbpversion == 0) goto end; assert(bbpversion == GDKLIBRARY); diff --git a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py --- a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py +++ b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py @@ -30,7 +30,8 @@ with zipfile.ZipFile(archive) as z: z.extractall(path=db) # start server and dump database -with process.server(mapiport='0', +with process.server(args=['--set', 'allow_hge_upgrade=yes'], + mapiport='0', stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE) as srv: diff --git a/sql/test/emptydb-previous-upgrade/Tests/upgrade.py b/sql/test/emptydb-previous-upgrade/Tests/upgrade.py --- a/sql/test/emptydb-previous-upgrade/Tests/upgrade.py +++ b/sql/test/emptydb-previous-upgrade/Tests/upgrade.py @@ -30,7 +30,8 @@ with zipfile.ZipFile(archive) as z: z.extractall(path=db) # start server and dump database -with process.server(mapiport='0', +with process.server(args=['--set', 'allow_hge_upgrade=yes'], + mapiport='0', stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE) as srv: diff --git a/sql/test/emptydb-upgrade-chain/Tests/upgrade.py b/sql/test/emptydb-upgrade-chain/Tests/upgrade.py --- a/sql/test/emptydb-upgrade-chain/Tests/upgrade.py +++ b/sql/test/emptydb-upgrade-chain/Tests/upgrade.py @@ -30,7 +30,8 @@ with zipfile.ZipFile(archive) as z: z.extractall(path=db) # start server and dump database -with process.server(mapiport='0', +with process.server(args=['--set', 'allow_hge_upgrade=yes'], + mapiport='0', stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE) as srv: diff --git a/sql/test/emptydb-upgrade/Tests/upgrade.py b/sql/test/emptydb-upgrade/Tests/upgrade.py --- a/sql/test/emptydb-upgrade/Tests/upgrade.py +++ b/sql/test/emptydb-upgrade/Tests/upgrade.py @@ -30,7 +30,8 @@ with zipfile.ZipFile(archive) as z: z.extractall(path=db) # start server and dump database -with process.server(mapiport='0', +with process.server(args=['--set', 'allow_hge_upgrade=yes'], + mapiport='0', stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE) as srv: diff --git a/sql/test/testdb-previous-upgrade-chain/Tests/upgrade.py b/sql/test/testdb-previous-upgrade-chain/Tests/upgrade.py --- a/sql/test/testdb-previous-upgrade-chain/Tests/upgrade.py +++ b/sql/test/testdb-previous-upgrade-chain/Tests/upgrade.py @@ -30,7 +30,8 @@ with zipfile.ZipFile(archive) as z: z.extractall(path=db) # start server and dump database -with process.server(mapiport='0', +with process.server(args=['--set', 'allow_hge_upgrade=yes'], + mapiport='0', stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE) as srv: diff --git a/sql/test/testdb-previous-upgrade/Tests/upgrade.py b/sql/test/testdb-previous-upgrade/Tests/upgrade.py --- a/sql/test/testdb-previous-upgrade/Tests/upgrade.py +++ b/sql/test/testdb-previous-upgrade/Tests/upgrade.py @@ -30,7 +30,8 @@ with zipfile.ZipFile(archive) as z: z.extractall(path=db) # start server and dump database -with process.server(mapiport='0', +with process.server(args=['--set', 'allow_hge_upgrade=yes'], + mapiport='0', stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE) as srv: diff --git a/sql/test/testdb-upgrade-chain/Tests/upgrade.py b/sql/test/testdb-upgrade-chain/Tests/upgrade.py --- a/sql/test/testdb-upgrade-chain/Tests/upgrade.py +++ b/sql/test/testdb-upgrade-chain/Tests/upgrade.py @@ -30,7 +30,8 @@ with zipfile.ZipFile(archive) as z: z.extractall(path=db) # start server and dump database -with process.server(mapiport='0', +with process.server(args=['--set', 'allow_hge_upgrade=yes'], + mapiport='0', stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE) as srv: diff --git a/sql/test/testdb-upgrade/Tests/upgrade.py b/sql/test/testdb-upgrade/Tests/upgrade.py --- a/sql/test/testdb-upgrade/Tests/upgrade.py +++ b/sql/test/testdb-upgrade/Tests/upgrade.py @@ -30,7 +30,8 @@ with zipfile.ZipFile(archive) as z: z.extractall(path=db) # start server and dump database -with process.server(mapiport='0', +with process.server(args=['--set', 'allow_hge_upgrade=yes'], + mapiport='0', stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE) as srv: diff --git a/tools/mserver/mserver5.1.in b/tools/mserver/mserver5.1.in --- a/tools/mserver/mserver5.1.in +++ b/tools/mserver/mserver5.1.in @@ -380,6 +380,20 @@ The server will listen on the interface .I hostname which is looked up using the normal hostname lookup facilities. .RE +.TP +.B allow_hge_upgrade +Set this parameter to +.B yes +to allow the server to upgrade the database from one without 128 bit +integer support to one with 128 bit integer (also known as HUGEINT) support. +Note, the upgrade will only happen if the server does indeed support 128 +bit integers. +Also note that there is no going back from a database with 128 bit +integer support to one without. +This option does nothing if no upgrade is required. +128 bit integers requires support from the C compiler and is therefore +not available on all platforms. It can also be turned off at compile +time. .SH SQL PARAMETERS The SQL component of MonetDB 5 runs on top of the MAL environment. It has its own SQL-level specific settings. _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org