Changeset: 9b7173a810ed for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9b7173a810ed
Modified Files:
gdk/gdk.h
gdk/gdk_bbp.c
gdk/gdk_logger.c
gdk/gdk_utils.c
monetdb5/modules/atoms/str.c
sql/storage/bat/bat_utils.c
Branch: Jul2021
Log Message:
Record "owner" of bat; bat becomes ownerless when its logical ref count is
incremented.
diffs (151 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1528,7 +1528,7 @@ typedef struct {
int refs; /* in-memory references on which the loaded
status of a BAT relies */
int lrefs; /* logical references on which the existence of
a BAT relies */
ATOMIC_TYPE status; /* status mask used for spin locking */
- /* MT_Id pid; non-zero thread-id if this BAT is private */
+ MT_Id pid; /* creator of this bat while "private" */
} BBPrec;
gdk_export bat BBPlimit;
@@ -1919,6 +1919,7 @@ BBPcheck(bat x)
if (x < 0 || x >= getBBPsize() || BBP_logical(x) == NULL) {
TRC_DEBUG(CHECK_, "range error %d\n", (int) x);
} else {
+ assert(BBP_pid(x) == 0 || BBP_pid(x) == MT_getpid());
return x;
}
}
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -365,8 +365,10 @@ BBPextend(int idx, bool buildhash)
GDKerror("failed to extend BAT pool\n");
return GDK_FAIL;
}
- for (BUN i = 0; i < BBPINIT; i++)
+ for (BUN i = 0; i < BBPINIT; i++) {
ATOMIC_INIT(&BBP[limit][i].status, 0);
+ BBP[limit][i].pid = ~(MT_Id)0;
+ }
BBPlimit += BBPINIT;
}
@@ -721,6 +723,7 @@ BBPreadEntries(FILE *fp, unsigned bbpver
BBP_refs(bid) = 0;
BBP_lrefs(bid) = 1; /* any BAT we encounter here is
persistent, so has a logical reference */
BBP_desc(bid) = bn;
+ BBP_pid(bid) = 0;
BBP_status_set(bid, BBPEXISTING); /* do we need other
status bits? */
}
return GDK_SUCCEED;
@@ -1921,6 +1924,7 @@ BBPinsert(BAT *bn)
BBP_desc(i) = NULL;
BBP_refs(i) = 1; /* new bats have 1 pin */
BBP_lrefs(i) = 0; /* ie. no logical refs */
+ BBP_pid(i) = MT_getpid();
#ifdef HAVE_HGE
if (bn->ttype == TYPE_hge)
@@ -2051,6 +2055,7 @@ bbpclear(bat i, int idx, bool lock)
BBP_logical(i) = NULL;
BBP_next(i) = BBP_free(idx);
BBP_free(idx) = i;
+ BBP_pid(i) = ~(MT_Id)0; /* not zero, not a valid thread id */
if (lock)
MT_lock_unset(&GDKcacheLock(idx));
}
@@ -2268,6 +2273,7 @@ incref(bat i, bool logical, bool lock)
/* parent BATs are not relevant for logical refs */
tp = tvp = 0;
refs = ++BBP_lrefs(i);
+ BBP_pid(i) = 0;
} else {
tp = b->theap == NULL || b->theap->parentid == i ? 0 :
b->theap->parentid;
assert(tp >= 0);
@@ -2353,7 +2359,12 @@ decref(bat i, bool logical, bool release
bat tp = 0, tvp = 0;
BAT *b;
+ if (is_bat_nil(i))
+ return -1;
assert(i > 0);
+ if (BBPcheck(i) == 0)
+ return -1;
+
if (lock)
MT_lock_set(&GDKswapLock(i));
if (releaseShare) {
@@ -2462,18 +2473,12 @@ decref(bat i, bool logical, bool release
int
BBPunfix(bat i)
{
- if (BBPcheck(i) == 0) {
- return -1;
- }
return decref(i, false, false, true, "BBPunfix");
}
int
BBPrelease(bat i)
{
- if (BBPcheck(i) == 0) {
- return -1;
- }
return decref(i, true, false, true, "BBPrelease");
}
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -211,6 +211,7 @@ logbat_new(int tt, BUN size, role_t role
BAT *nb = COLnew(0, tt, size, role);
if (nb) {
+ BBP_pid(nb->batCacheid) = 0;
if (role == PERSISTENT)
BATmode(nb, false);
} else {
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1055,6 +1055,8 @@ GDKinit(opt *set, int setlen, bool embed
TRC_CRITICAL(GDK, "BBPrename of environment BATs failed");
return GDK_FAIL;
}
+ BBP_pid(GDKkey->batCacheid) = 0;
+ BBP_pid(GDKval->batCacheid) = 0;
/* store options into environment BATs */
for (i = 0; i < nlen; i++)
diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -2937,6 +2937,10 @@ STRprelude(void *ret)
BBPrename(UTF8_toLowerTo->batCacheid,
"monet_unicode_lower_to") != 0) {
goto bailout;
}
+ BBP_pid(UTF8_toUpperFrom->batCacheid) = 0;
+ BBP_pid(UTF8_toUpperTo->batCacheid) = 0;
+ BBP_pid(UTF8_toLowerFrom->batCacheid) = 0;
+ BBP_pid(UTF8_toLowerTo->batCacheid) = 0;
}
return MAL_SUCCEED;
diff --git a/sql/storage/bat/bat_utils.c b/sql/storage/bat/bat_utils.c
--- a/sql/storage/bat/bat_utils.c
+++ b/sql/storage/bat/bat_utils.c
@@ -19,7 +19,10 @@ bat_destroy(BAT *b)
BAT *
bat_new(int tt, BUN size, role_t role)
{
- return COLnew(0, tt, size, role);
+ BAT *bn = COLnew(0, tt, size, role);
+ if (bn)
+ BBP_pid(bn->batCacheid) = 0;
+ return bn;
}
void
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list