Changeset: dea28f85232a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/dea28f85232a
Modified Files:
gdk/gdk_bat.c
gdk/gdk_bbp.c
gdk/gdk_calc.c
gdk/gdk_delta.c
gdk/gdk_hash.c
gdk/gdk_heap.c
gdk/gdk_imprints.c
gdk/gdk_orderidx.c
gdk/gdk_project.c
monetdb5/modules/kernel/batstr.c
monetdb5/modules/mal/tablet.c
Branch: Jan2022
Log Message:
Merge with Jul2021 branch.
diffs (truncated from 1011 to 300 lines):
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -899,8 +899,7 @@ COLcopy(BAT *b, int tt, bool writable, r
/* convert number of bits to number of bytes,
* and round the latter up to a multiple of
* 4 (copy in units of 4 bytes) */
- bn->theap->free = (bi.count + 7) / 8;
- bn->theap->free = (bn->theap->free + 3) & ~(size_t)3;
+ bn->theap->free = ((bi.count + 31) / 32) * 4;
bn->theap->dirty |= bi.count > 0;
memcpy(Tloc(bn, 0), bi.base, bn->theap->free);
} else {
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -433,7 +433,7 @@ heapinit(BAT *b, const char *buf,
#ifdef GDKLIBRARY_HASHASH
int *hashash,
#endif
- unsigned bbpversion, bat bid, const char *filename, int lineno)
+ unsigned bbpversion, const char *filename, int lineno)
{
int t;
char type[33];
@@ -495,7 +495,7 @@ heapinit(BAT *b, const char *buf,
return -1;
}
} else if (var != (t == TYPE_void || BATatoms[t].atomPut != NULL)) {
- TRC_CRITICAL(GDK, "inconsistent entry in BBP.dir: tvarsized
mismatch for BAT %d on line %d\n", (int) bid, lineno);
+ TRC_CRITICAL(GDK, "inconsistent entry in BBP.dir: tvarsized
mismatch for BAT %d on line %d\n", (int) b->batCacheid, lineno);
return -1;
} else if (var && t != 0 ?
ATOMsize(t) < width ||
@@ -505,7 +505,7 @@ heapinit(BAT *b, const char *buf,
#endif
) :
ATOMsize(t) != width) {
- TRC_CRITICAL(GDK, "inconsistent entry in BBP.dir: tsize
mismatch for BAT %d on line %d\n", (int) bid, lineno);
+ TRC_CRITICAL(GDK, "inconsistent entry in BBP.dir: tsize
mismatch for BAT %d on line %d\n", (int) b->batCacheid, lineno);
return -1;
}
b->ttype = t;
@@ -553,7 +553,7 @@ heapinit(BAT *b, const char *buf,
}
static int
-vheapinit(BAT *b, const char *buf, bat bid, const char *filename, int lineno)
+vheapinit(BAT *b, const char *buf, const char *filename, int lineno)
{
int n = 0;
uint64_t free, size;
@@ -567,11 +567,6 @@ vheapinit(BAT *b, const char *buf, bat b
TRC_CRITICAL(GDK, "invalid format for BBP.dir on line
%d", lineno);
return -1;
}
- b->tvheap = GDKmalloc(sizeof(Heap));
- if (b->tvheap == NULL) {
- TRC_CRITICAL(GDK, "cannot allocate memory for heap.");
- return -1;
- }
if (b->batCount == 0)
free = 0;
if (b->ttype >= 0 &&
@@ -590,16 +585,134 @@ vheapinit(BAT *b, const char *buf, bat b
.cleanhash = true,
.newstorage = STORE_INVALID,
.dirty = false,
- .parentid = bid,
+ .parentid = b->batCacheid,
.farmid = BBPselectfarm(PERSISTENT, b->ttype, varheap),
};
strconcat_len(b->tvheap->filename, sizeof(b->tvheap->filename),
filename, ".theap", NULL);
- ATOMIC_INIT(&b->tvheap->refs, 1);
+ } else {
+ b->tvheap = NULL;
}
return n;
}
+/* read a single line from the BBP.dir file (file pointer fp) and fill
+ * in the structure pointed to by bn and extra information through the
+ * other pointers; this function does not allocate any memory; return 0
+ * on end of file, 1 on success, and -1 on failure */
+static int
+BBPreadBBPline(FILE *fp, unsigned bbpversion, int *lineno, BAT *bn,
+#ifdef GDKLIBRARY_HASHASH
+ int *hashash,
+#endif
+ char *batname, char *filename, char **options)
+{
+ char buf[4096];
+ uint64_t batid;
+ uint16_t status;
+ unsigned int properties;
+ int nread, n;
+ char *s;
+ uint64_t count, capacity = 0, base = 0;
+
+ if (fgets(buf, sizeof(buf), fp) == NULL) {
+ if (ferror(fp)) {
+ TRC_CRITICAL(GDK, "error reading BBP.dir on line %d\n",
*lineno);
+ return -1;
+ }
+ return 0; /* end of file */
+ }
+ (*lineno)++;
+ if ((s = strchr(buf, '\r')) != NULL) {
+ /* convert \r\n into just \n */
+ if (s[1] != '\n') {
+ TRC_CRITICAL(GDK, "invalid format for BBP.dir on line
%d", *lineno);
+ return -1;
+ }
+ *s++ = '\n';
+ *s = 0;
+ }
+
+ if (sscanf(buf,
+ "%" SCNu64 " %" SCNu16 " %128s %19s %u %" SCNu64
+ " %" SCNu64 " %" SCNu64
+ "%n",
+ &batid, &status, batname, filename,
+ &properties,
+ &count, &capacity, &base,
+ &nread) < 8) {
+ TRC_CRITICAL(GDK, "invalid format for BBP.dir on line %d",
*lineno);
+ return -1;
+ }
+
+ if (batid >= N_BBPINIT * BBPINIT) {
+ TRC_CRITICAL(GDK, "bat ID (%" PRIu64 ") too large to accomodate
(max %d), on line %d.", batid, N_BBPINIT * BBPINIT - 1, *lineno);
+ return -1;
+ }
+
+ /* convert both / and \ path separators to our own DIR_SEP */
+#if DIR_SEP != '/'
+ s = filename;
+ while ((s = strchr(s, '/')) != NULL)
+ *s++ = DIR_SEP;
+#endif
+#if DIR_SEP != '\\'
+ s = filename;
+ while ((s = strchr(s, '\\')) != NULL)
+ *s++ = DIR_SEP;
+#endif
+
+ bn->batCacheid = (bat) batid;
+ BATinit_idents(bn);
+ bn->batTransient = false;
+ bn->batCopiedtodisk = true;
+ switch ((properties & 0x06) >> 1) {
+ case 0:
+ bn->batRestricted = BAT_WRITE;
+ break;
+ case 1:
+ bn->batRestricted = BAT_READ;
+ break;
+ case 2:
+ bn->batRestricted = BAT_APPEND;
+ break;
+ default:
+ TRC_CRITICAL(GDK, "incorrect batRestricted value");
+ return -1;
+ }
+ bn->batCount = (BUN) count;
+ bn->batInserted = bn->batCount;
+ /* set capacity to at least count */
+ bn->batCapacity = (BUN) count <= BATTINY ? BATTINY : (BUN) count;
+
+ if (base > (uint64_t) GDK_oid_max) {
+ TRC_CRITICAL(GDK, "head seqbase out of range (ID = %" PRIu64 ",
seq = %" PRIu64 ") on line %d.", batid, base, *lineno);
+ return -1;
+ }
+ bn->hseqbase = (oid) base;
+ n = heapinit(bn, buf + nread,
+#ifdef GDKLIBRARY_HASHASH
+ hashash,
+#endif
+ bbpversion, filename, *lineno);
+ if (n < 0) {
+ return -1;
+ }
+ nread += n;
+ n = vheapinit(bn, buf + nread, filename, *lineno);
+ if (n < 0) {
+ return -1;
+ }
+ nread += n;
+
+ if (buf[nread] != '\n' && buf[nread] != ' ') {
+ TRC_CRITICAL(GDK, "invalid format for BBP.dir on line %d",
*lineno);
+ return -1;
+ }
+ *options = (buf[nread] == ' ') ? buf + nread + 1 : NULL;
+ return 1;
+}
+
static gdk_return
BBPreadEntries(FILE *fp, unsigned bbpversion, int lineno
#ifdef GDKLIBRARY_HASHASH
@@ -607,101 +720,114 @@ BBPreadEntries(FILE *fp, unsigned bbpver
#endif
)
{
- bat bid = 0;
- char buf[4096];
#ifdef GDKLIBRARY_HASHASH
bat *hbats = NULL;
bat nhbats = 0;
#endif
/* read the BBP.dir and insert the BATs into the BBP */
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- BAT *bn;
- uint64_t batid;
- uint16_t status;
+ for (;;) {
+ BAT b;
+ Heap h;
+ Heap vh;
+ vh = h = (Heap) {
+ .free = 0,
+ };
+ b = (BAT) {
+ .theap = &h,
+ .tvheap = &vh,
+ };
+ char *options;
char headname[129];
char filename[sizeof(BBP_physical(0))];
- unsigned int properties;
- int nread, n;
- char *s, *options = NULL;
char logical[1024];
- uint64_t count, capacity, base = 0;
#ifdef GDKLIBRARY_HASHASH
int Thashash;
#endif
- lineno++;
- if ((s = strchr(buf, '\r')) != NULL) {
- /* convert \r\n into just \n */
- if (s[1] != '\n') {
- TRC_CRITICAL(GDK, "invalid format for BBP.dir
on line %d", lineno);
- goto bailout;
- }
- *s++ = '\n';
- *s = 0;
- }
-
- if (sscanf(buf,
- "%" SCNu64 " %" SCNu16 " %128s %19s %u %" SCNu64
- " %" SCNu64 " %" SCNu64
- "%n",
- &batid, &status, headname, filename,
- &properties,
- &count, &capacity, &base,
- &nread) < 8) {
- TRC_CRITICAL(GDK, "invalid format for BBP.dir on line
%d", lineno);
+ switch (BBPreadBBPline(fp, bbpversion, &lineno, &b,
+#ifdef GDKLIBRARY_HASHASH
+ &Thashash,
+#endif
+ headname, filename, &options)) {
+ case 0:
+ /* end of file */
+#ifdef GDKLIBRARY_HASHASH
+ *hashbats = hbats;
+ *nhashbats = nhbats;
+#endif
+ return GDK_SUCCEED;
+ case 1:
+ /* successfully read an entry */
+ break;
+ default:
+ /* error */
goto bailout;
}
- if (batid >= N_BBPINIT * BBPINIT) {
- TRC_CRITICAL(GDK, "bat ID (%" PRIu64 ") too large to
accomodate (max %d), on line %d.", batid, N_BBPINIT * BBPINIT - 1, lineno);
+ if (b.batCacheid >= N_BBPINIT * BBPINIT) {
+ TRC_CRITICAL(GDK, "bat ID (%d) too large to accommodate
(max %d), on line %d.", b.batCacheid, N_BBPINIT * BBPINIT - 1, lineno);
goto bailout;
}
- /* convert both / and \ path separators to our own DIR_SEP */
-#if DIR_SEP != '/'
- s = filename;
- while ((s = strchr(s, '/')) != NULL)
- *s++ = DIR_SEP;
-#endif
-#if DIR_SEP != '\\'
- s = filename;
- while ((s = strchr(s, '\\')) != NULL)
- *s++ = DIR_SEP;
-#endif
-
- bid = (bat) batid;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]