Changeset: 3dcc8168dda2 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3dcc8168dda2 Branch: unlock Log Message:
merged diffs (truncated from 2092 to 300 lines): diff --git a/gdk/gdk.h b/gdk/gdk.h --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -1407,6 +1407,7 @@ gdk_export BBPrec *BBP[N_BBPINIT]; #define BBPRENAME_ALREADY (-1) #define BBPRENAME_ILLEGAL (-2) #define BBPRENAME_LONG (-3) +#define BBPRENAME_MEMORY (-4) gdk_export void BBPlock(void); diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -677,24 +677,29 @@ BBPreadEntries(FILE *fp, unsigned bbpver if (buf[nread] == ' ') options = buf + nread + 1; + if (snprintf(BBP_bak(bid), sizeof(BBP_bak(bid)), "tmp_%o", (unsigned) bid) >= (int) sizeof(BBP_bak(bid))) { + BATdestroy(bn); + TRC_CRITICAL(GDK, "BBP logical filename directory is too large, on line %d\n", lineno); + return GDK_FAIL; + } if ((s = strchr(headname, '~')) != NULL && s == headname) { - int len = snprintf(logical, sizeof(logical), "tmp_%o", (unsigned) bid); - if (len == -1 || len >= (int) sizeof(logical)) { - BATdestroy(bn); - TRC_CRITICAL(GDK, "BBP logical filename directory is too large, on line %d\n", lineno); - return GDK_FAIL; - } + /* sizeof(logical) > sizeof(BBP_bak(bid)), so + * this fits */ + strcpy(logical, BBP_bak(bid)); } else { if (s) *s = 0; strcpy_len(logical, headname, sizeof(logical)); } - s = logical; - BBP_logical(bid) = GDKstrdup(s); - if (BBP_logical(bid) == NULL) { - BATdestroy(bn); - TRC_CRITICAL(GDK, "GDKstrdup failed\n"); - return GDK_FAIL; + if (strcmp(logical, BBP_bak(bid)) == 0) { + BBP_logical(bid) = BBP_bak(bid); + } else { + BBP_logical(bid) = GDKstrdup(logical); + if (BBP_logical(bid) == NULL) { + BATdestroy(bn); + TRC_CRITICAL(GDK, "GDKstrdup failed\n"); + return GDK_FAIL; + } } /* tailname is ignored */ strcpy_len(BBP_physical(bid), filename, sizeof(BBP_physical(bid))); @@ -1924,9 +1929,8 @@ BBPclear(bat i) /* * @- BBP rename * - * Each BAT has a logical name that is globally unique. Its reverse - * view can also be assigned a name, that also has to be globally - * unique. The batId is the same as the logical BAT name. + * Each BAT has a logical name that is globally unique. + * The batId is the same as the logical BAT name. * * The default logical name of a BAT is tmp_X, where X is the * batCacheid. Apart from being globally unique, new logical bat @@ -1954,6 +1958,16 @@ BBPrename(bat bid, const char *nme) if (b == NULL) return 0; + if (nme == NULL) { + if (BBP_bak(bid)[0] == 0 && + snprintf(BBP_bak(bid), sizeof(BBP_bak(bid)), "tmp_%o", (unsigned) bid) >= (int) sizeof(BBP_bak(bid))) { + /* cannot happen */ + TRC_CRITICAL(GDK, "BBP default filename too long\n"); + return BBPRENAME_LONG; + } + nme = BBP_bak(bid); + } + /* If name stays same, do nothing */ if (BBP_logical(bid) && strcmp(BBP_logical(bid), nme) == 0) return 0; @@ -1968,6 +1982,7 @@ BBPrename(bat bid, const char *nme) GDKerror("illegal temporary name: '%s'\n", nme); return BBPRENAME_LONG; } + idx = threadmask(MT_getpid()); MT_lock_set(&GDKtrimLock(idx)); MT_lock_set(&GDKnameLock); @@ -1979,13 +1994,25 @@ BBPrename(bat bid, const char *nme) return BBPRENAME_ALREADY; } + char *nnme; + if (nme == BBP_bak(bid) || strcmp(nme, BBP_bak(bid)) == 0) { + nnme = BBP_bak(bid); + } else { + nnme = GDKstrdup(nme); + if (nnme == NULL) { + MT_lock_unset(&GDKnameLock); + MT_lock_unset(&GDKtrimLock(idx)); + return BBPRENAME_MEMORY; + } + } + /* carry through the name change */ if (BBP_logical(bid) && BBPtmpcheck(BBP_logical(bid)) == 0) { BBP_delete(bid); } if (BBP_logical(bid) != BBP_bak(bid)) GDKfree(BBP_logical(bid)); - BBP_logical(bid) = GDKstrdup(nme); + BBP_logical(bid) = nnme; if (tmpid == 0) { BBP_insert(bid); } diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -95,13 +95,13 @@ typedef enum {LOG_OK, LOG_EOF, LOG_ERR} static gdk_return bm_commit(logger *lg); static gdk_return tr_grow(trans *tr); -static void +static inline void logger_lock(logger *lg) { MT_lock_set(&lg->lock); } -static void +static inline void logger_unlock(logger *lg) { MT_lock_unset(&lg->lock); @@ -897,8 +897,7 @@ logger_create_types_file(logger *lg, con static gdk_return logger_open_output(logger *lg) { - int len; - char id[BUFSIZ]; + char id[32]; char *filename; if (LOG_DISABLED(lg)) { @@ -907,8 +906,7 @@ logger_open_output(logger *lg) lg->id--; return GDK_SUCCEED; } - len = snprintf(id, sizeof(id), LLFMT, lg->id); - if (len == -1 || len >= BUFSIZ) { + if (snprintf(id, sizeof(id), LLFMT, lg->id) >= (int) sizeof(id)) { TRC_CRITICAL(GDK, "filename is too large\n"); return GDK_FAIL; } @@ -1207,6 +1205,13 @@ check_version(logger *lg, FILE *fp, cons } if (version < 52300) { /* first CATALOG_VERSION for "new" log format */ fclose(fp); + lg->catalog_bid = logbat_new(TYPE_int, BATSIZE, PERSISTENT); + lg->catalog_id = logbat_new(TYPE_int, BATSIZE, PERSISTENT); + lg->dcatalog = logbat_new(TYPE_oid, BATSIZE, PERSISTENT); + if (lg->catalog_bid == NULL || lg->catalog_id == NULL || lg->dcatalog == NULL) { + GDKerror("cannot create catalog bats"); + return GDK_FAIL; + } if (old_logger_load(lg, fn, logdir) != GDK_SUCCEED) { //loads drop no longer needed catalog, snapshots bats //convert catalog_oid -> catalog_id (lng->int) @@ -1216,6 +1221,18 @@ check_version(logger *lg, FILE *fp, cons version < lg->version ? "Maybe you need to upgrade to an intermediate release first.\n" : ""); return GDK_FAIL; } + /* give the catalog bats names so we can find them + * next time */ + char bak[IDLENGTH]; + if (strconcat_len(bak, sizeof(bak), fn, "_catalog_bid", NULL) >= sizeof(bak) || + BBPrename(lg->catalog_bid->batCacheid, bak) < 0 || + strconcat_len(bak, sizeof(bak), fn, "_catalog_id", NULL) >= sizeof(bak) || + BBPrename(lg->catalog_id->batCacheid, bak) < 0 || + strconcat_len(bak, sizeof(bak), fn, "_dcatalog", NULL) >= sizeof(bak) || + BBPrename(lg->dcatalog->batCacheid, bak) < 0) { + return GDK_FAIL; + } + if (logger_create_types_file(lg, filename) != GDK_SUCCEED) return GDK_FAIL; return GDK_SUCCEED; @@ -1258,23 +1275,18 @@ bm_tids(BAT *b, BAT *d) static gdk_return logger_switch_bat(BAT *old, BAT *new, const char *fn, const char *name) { - int len; - char bak[BUFSIZ]; + char bak[IDLENGTH]; if (BATmode(old, true) != GDK_SUCCEED) { - GDKerror("Logger_new: cannot convert old %s to transient", name); + GDKerror("cannot convert old %s to transient", name); return GDK_FAIL; } - len = snprintf(bak, sizeof(bak), "tmp_%o", (unsigned) old->batCacheid); - if (len == -1 || len >= BUFSIZ) { - GDKerror("Logger_new: filename is too large"); + if (strconcat_len(bak, sizeof(bak), fn, "_", name, NULL) >= sizeof(bak)) { + GDKerror("name %s_%s too long\n", fn, name); return GDK_FAIL; } - if (BBPrename(old->batCacheid, bak) != 0) { - return GDK_FAIL; - } - strconcat_len(bak, sizeof(bak), fn, "_", name, NULL); - if (BBPrename(new->batCacheid, bak) != 0) { + if (BBPrename(old->batCacheid, NULL) != 0 || + BBPrename(new->batCacheid, bak) != 0) { return GDK_FAIL; } return GDK_SUCCEED; @@ -1721,7 +1733,9 @@ logger_load(int debug, const char *fn, c * require a logical reference we also add a logical * reference for the persistent bats */ BUN p, q; - BAT *b = BATdescriptor(catalog_bid), *o, *d; + BAT *b, *o, *d; + + assert(!lg->inmemory); /* the catalog exists, and so should the log file */ if (fp == NULL && !LOG_DISABLED(lg)) { @@ -1735,46 +1749,48 @@ logger_load(int debug, const char *fn, c fn, fn, lg->dir); goto error; } - if (check_version(lg, fp, fn, logdir, filename) != GDK_SUCCEED) { /* closes the file */ + if (fp != NULL && check_version(lg, fp, fn, logdir, filename) != GDK_SUCCEED) { /* closes the file */ fp = NULL; goto error; } readlogs = 1; fp = NULL; - assert(!lg->inmemory); - if (b == NULL) { - GDKerror("inconsistent database, catalog does not exist"); - goto error; - } + if (lg->catalog_bid == NULL && lg->catalog_id == NULL && lg->dcatalog == NULL) { + b = BATdescriptor(catalog_bid); + if (b == NULL) { + GDKerror("inconsistent database, catalog does not exist"); + goto error; + } - strconcat_len(bak, sizeof(bak), fn, "_catalog_id", NULL); - catalog_id = BBPindex(bak); - o = BATdescriptor(catalog_id); - if (o == NULL) { - BBPunfix(b->batCacheid); - GDKerror("inconsistent database, catalog_id does not exist"); - goto error; + strconcat_len(bak, sizeof(bak), fn, "_catalog_id", NULL); + catalog_id = BBPindex(bak); + o = BATdescriptor(catalog_id); + if (o == NULL) { + BBPunfix(b->batCacheid); + GDKerror("inconsistent database, catalog_id does not exist"); + goto error; + } + + strconcat_len(bak, sizeof(bak), fn, "_dcatalog", NULL); + dcatalog = BBPindex(bak); + d = BATdescriptor(dcatalog); + if (d == NULL) { + GDKerror("cannot create dcatalog bat"); + BBPunfix(b->batCacheid); + BBPunfix(o->batCacheid); + goto error; + } + + lg->catalog_bid = b; + lg->catalog_id = o; + lg->dcatalog = d; } - - strconcat_len(bak, sizeof(bak), fn, "_dcatalog", NULL); - dcatalog = BBPindex(bak); - d = BATdescriptor(dcatalog); - if (d == NULL) { - GDKerror("cannot create dcatalog bat"); - BBPunfix(b->batCacheid); - BBPunfix(o->batCacheid); - goto error; - } - - lg->catalog_bid = b; - lg->catalog_id = o; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list