Changeset: 60c436e54d46 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/60c436e54d46
Modified Files:
gdk/gdk_bat.c
gdk/gdk_bbp.c
gdk/gdk_select.c
sql/backends/monet5/sql.c
Branch: default
Log Message:
Merged with Jul2021
diffs (truncated from 646 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
@@ -1090,12 +1090,13 @@ BUNappendmulti(BAT *b, const void *value
b->tsorted = true;
b->trevsorted = true;
b->tkey = true;
- b->tseqbase = ((oid *) values)[0];
+ b->tseqbase = count == 1 ? ((oid *) values)[0]
: oid_nil;
b->tnil = false;
b->tnonil = true;
} else {
if (!is_oid_nil(b->tseqbase) &&
- b->tseqbase + b->batCount + 1 != ((oid *)
values)[0])
+ (count > 1 ||
+ b->tseqbase + b->batCount != ((oid *)
values)[0]))
b->tseqbase = oid_nil;
if (b->tsorted && ((oid *)
b->theap->base)[b->batCount - 1] > ((oid *) values)[0]) {
b->tsorted = false;
@@ -2295,11 +2296,11 @@ BATmode(BAT *b, bool transient)
}
MT_lock_set(&GDKswapLock(bid));
if (!transient) {
- if (!(BBP_status(bid) & BBPDELETED))
+ if (BBP_status(bid) & BBPDELETED) {
+ BBP_status_on(bid, BBPEXISTING);
+ BBP_status_off(bid, BBPDELETED);
+ } else
BBP_status_on(bid, BBPNEW);
- else
- BBP_status_on(bid, BBPEXISTING);
- BBP_status_off(bid, BBPDELETED);
} else if (!b->batTransient) {
if (!(BBP_status(bid) & BBPNEW))
BBP_status_on(bid, BBPDELETED);
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -2258,12 +2258,13 @@ BBPcacheit(BAT *bn, bool lock)
if (lock)
MT_lock_set(&GDKswapLock(i));
mode = (BBP_status(i) | BBPLOADED) & ~(BBPLOADING | BBPDELETING |
BBPSWAPPED);
- BBP_status_set(i, mode);
BBP_desc(i) = bn;
/* cache it! */
BBP_cache(i) = bn;
+ BBP_status_set(i, mode);
+
if (lock)
MT_lock_unset(&GDKswapLock(i));
return GDK_SUCCEED;
@@ -2289,10 +2290,10 @@ BBPuncacheit(bat i, bool unloaddesc)
if (BBP_cache(i)) {
TRC_DEBUG(BAT_, "uncache %d (%s)\n", (int) i,
BBP_logical(i));
- BBP_cache(i) = NULL;
-
/* clearing bits can be done without the lock */
BBP_status_off(i, BBPLOADED);
+
+ BBP_cache(i) = NULL;
}
if (unloaddesc) {
BBP_desc(i) = NULL;
@@ -2527,7 +2528,7 @@ incref(bat i, bool logical, bool lock)
break;
/* the BATs is "unstable", try again */
MT_lock_unset(&GDKswapLock(i));
- MT_sleep_ms(KITTENNAP);
+ BBPspin(i, __func__, BBPUNSTABLE|BBPLOADING);
}
}
/* we have the lock */
@@ -2843,7 +2844,7 @@ getBBPdescriptor(bat i, bool lock)
while (BBP_status(i) & BBPWAITING) { /* wait for bat to be
loaded by other thread */
if (lock)
MT_lock_unset(&GDKswapLock(i));
- MT_sleep_ms(KITTENNAP);
+ BBPspin(i, __func__, BBPWAITING);
if (lock)
MT_lock_set(&GDKswapLock(i));
}
@@ -2907,7 +2908,7 @@ BBPsave(BAT *b)
/* wait until save in other thread completes */
if (lock)
MT_lock_unset(&GDKswapLock(bid));
- BBPspin(bid, "BBPsave", BBPSAVING);
+ BBPspin(bid, __func__, BBPSAVING);
} else {
/* save it */
unsigned flags = BBPSAVING;
@@ -3060,7 +3061,7 @@ dirty_bat(bat *i, bool subcommit)
{
if (BBPvalid(*i)) {
BAT *b;
- BBPspin(*i, "dirty_bat", BBPSAVING);
+ BBPspin(*i, __func__, BBPSAVING);
b = BBP_cache(*i);
if (b != NULL) {
if ((BBP_status(*i) & BBPNEW) &&
diff --git a/gdk/gdk_firstn.c b/gdk/gdk_firstn.c
--- a/gdk/gdk_firstn.c
+++ b/gdk/gdk_firstn.c
@@ -1127,7 +1127,7 @@ BATfirstn_grouped_with_groups(BAT **topn
MT_thread_setalgorithm(__func__);
if (distinct) {
- BAT *bn1, *bn2, *bn3, *bn4, *bn5, *bn6, *bn7, *bn8;
+ BAT *bn1, *bn2, *bn3, *bn4, *bn5, *bn6, *bn7;
if (BATgroup(&bn1, &bn2, NULL, b, s, g, NULL, NULL) !=
GDK_SUCCEED)
return GDK_FAIL;
bn3 = BATproject(bn2, b);
@@ -1155,13 +1155,12 @@ BATfirstn_grouped_with_groups(BAT **topn
BBPunfix(bn1->batCacheid);
return GDK_FAIL;
}
- rc = BATleftjoin(&bn8, &bn7, bn1, bn6, NULL, NULL, false,
BUN_NONE);
+ rc = BATleftjoin(&bn7, NULL, bn1, bn6, NULL, NULL, false,
BUN_NONE);
BBPunfix(bn6->batCacheid);
if (rc != GDK_SUCCEED)
return GDK_FAIL;
+ bn = BATproject(bn7, s);
BBPunfix(bn7->batCacheid);
- bn = BATproject(bn8, s);
- BBPunfix(bn8->batCacheid);
if (bn == NULL)
return GDK_FAIL;
} else {
diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -151,8 +151,8 @@
const TYPE *restrict bins = (TYPE *) inbins; \
const BUN page = IMPS_PAGE / sizeof(TYPE); \
prvmask = 0; \
- for (i = 0; i < b->batCount; ) { \
- const BUN lim = MIN(i + page, b->batCount); \
+ for (i = 0; i < bi->count; ) { \
+ const BUN lim = MIN(i + page, bi->count); \
/* new mask */ \
mask = 0; \
/* build mask for all BUNs in one PAGE */ \
@@ -355,7 +355,7 @@ BATcheckimprints(BAT *b)
imprints->imprints.parentid =
b->batCacheid;
ATOMIC_INIT(&imprints->imprints.refs, 1);
b->timprints = imprints;
- TRC_DEBUG(ACCELERATOR,
"BATcheckimprints(" ALGOBATFMT "): reusing persisted imprints\n",
ALGOBATPAR(b));
+ TRC_DEBUG(ACCELERATOR,
ALGOBATFMT " reusing persisted imprints\n", ALGOBATPAR(b));
MT_lock_unset(&b->batIdxLock);
bat_iterator_end(&bi);
return true;
@@ -373,7 +373,7 @@ BATcheckimprints(BAT *b)
bat_iterator_end(&bi);
ret = b->timprints != NULL;
if( ret)
- TRC_DEBUG(ACCELERATOR, "BATcheckimprints(" ALGOBATFMT "):
already has imprints\n", ALGOBATPAR(b));
+ TRC_DEBUG(ACCELERATOR, ALGOBATFMT " already has imprints\n",
ALGOBATPAR(b));
return ret;
}
@@ -428,8 +428,7 @@ BATimpsync(void *arg)
failed = ""; /* not failed */
}
}
- TRC_DEBUG(ACCELERATOR, "BATimpsync(" ALGOBATFMT "): "
- "imprints persisted "
+ TRC_DEBUG(ACCELERATOR, ALGOBATFMT " imprints persisted "
"(" LLFMT " usec)%s\n", ALGOBATPAR(b),
GDKusec() - t0, failed);
}
@@ -479,13 +478,13 @@ BATimprints(BAT *b)
MT_thread_setalgorithm("create imprints");
if (s2)
- TRC_DEBUG(ACCELERATOR, "BATimprints(b=" ALGOBATFMT
- "): creating imprints on parent "
+ TRC_DEBUG(ACCELERATOR, ALGOBATFMT
+ " creating imprints on parent "
ALGOBATFMT "\n",
ALGOBATPAR(s2), ALGOBATPAR(b));
else
- TRC_DEBUG(ACCELERATOR, "BATimprints(b=" ALGOBATFMT
- "): creating imprints\n",
+ TRC_DEBUG(ACCELERATOR, ALGOBATFMT
+ " creating imprints\n",
ALGOBATPAR(b));
s2 = NULL;
@@ -629,8 +628,25 @@ BATimprints(BAT *b)
((size_t *) imprints->imprints.base)[2] = (size_t)
imprints->dictcnt;
((size_t *) imprints->imprints.base)[3] = (size_t) bi.count;
imprints->imprints.parentid = b->batCacheid;
+ MT_lock_set(&b->theaplock);
+ if (b->batCount != bi.count) {
+ /* bat changed under our feet, can't use imprints */
+ MT_lock_unset(&b->theaplock);
+ MT_lock_unset(&b->batIdxLock);
+ bat_iterator_end(&bi);
+ HEAPfree(&imprints->imprints, true);
+ GDKfree(imprints);
+ BBPunfix(s1->batCacheid);
+ BBPunfix(s2->batCacheid);
+ BBPunfix(s3->batCacheid);
+ BBPunfix(s4->batCacheid);
+ GDKerror("Imprints creation aborted due to concurrent
change to bat\n");
+ TRC_DEBUG(ACCELERATOR, "failed imprints construction:
bat %s changed, " LLFMT " usec\n", BATgetId(b), GDKusec() - t0);
+ return GDK_FAIL;
+ }
ATOMIC_INIT(&imprints->imprints.refs, 1);
b->timprints = imprints;
+ MT_lock_unset(&b->theaplock);
if (BBP_status(b->batCacheid) & BBPEXISTING &&
!b->theap->dirty &&
!GDKinmemory(bi.h->farmid) &&
@@ -645,7 +661,8 @@ BATimprints(BAT *b)
}
}
- TRC_DEBUG(ACCELERATOR, "BATimprints(%s): imprints construction " LLFMT
" usec\n", BATgetId(b), GDKusec() - t0);
+ TRC_DEBUG(ACCELERATOR, "%s: imprints construction " LLFMT " usec\n",
+ BATgetId(b), GDKusec() - t0);
MT_lock_unset(&b->batIdxLock);
bat_iterator_end(&bi);
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -1940,7 +1940,7 @@ BATselect(BAT *b, BAT *s, const void *tl
/* use imprints if
* i) bat is persistent, or parent is persistent
* ii) it is not an equi-select, and
- * iii) is not var-sized.
+ * iii) imprints are supported.
*/
tmp = NULL;
Imprints *imprints = NULL;
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -2052,7 +2052,7 @@ DELTAbat(bat *result, const bat *col, co
throw(MAL, "sql.delta", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
if ((res = COLcopy(c, c->ttype, true, TRANSIENT)) == NULL) {
BBPunfix(c->batCacheid);
- throw(MAL, "sql.delta", SQLSTATE(45002) "Cannot create copy of
delta structure");
+ throw(MAL, "sql.delta", GDK_EXCEPTION);
}
BBPunfix(c->batCacheid);
@@ -2071,7 +2071,7 @@ DELTAbat(bat *result, const bat *col, co
BBPunfix(u_id->batCacheid);
BBPunfix(u_val->batCacheid);
BBPunfix(res->batCacheid);
- throw(MAL, "sql.delta", SQLSTATE(45002) "Cannot access delta
structure");
+ throw(MAL, "sql.delta", GDK_EXCEPTION);
}
BBPunfix(u_id->batCacheid);
BBPunfix(u_val->batCacheid);
@@ -2109,7 +2109,7 @@ DELTAsub(bat *result, const bat *col, co
if (!cminu) {
BBPunfix(c->batCacheid);
BBPunfix(u_id->batCacheid);
- throw(MAL, "sql.delta", SQLSTATE(HY013) MAL_MALLOC_FAIL
" intermediate");
+ throw(MAL, "sql.delta", GDK_EXCEPTION);
}
res = BATproject(cminu, c);
BBPunfix(c->batCacheid);
@@ -2117,7 +2117,7 @@ DELTAsub(bat *result, const bat *col, co
cminu = NULL;
if (!res) {
BBPunfix(u_id->batCacheid);
- throw(MAL, "sql.delta", SQLSTATE(HY013) MAL_MALLOC_FAIL
" intermediate" );
+ throw(MAL, "sql.delta", GDK_EXCEPTION);
}
c = res;
@@ -2132,7 +2132,7 @@ DELTAsub(bat *result, const bat *col, co
BBPunfix(u_id->batCacheid);
if (!u) {
BBPunfix(c->batCacheid);
- throw(MAL, "sql.delta", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ throw(MAL, "sql.delta", GDK_EXCEPTION);
}
/* check selected updated values against candidates */
@@ -2148,12 +2148,20 @@ DELTAsub(bat *result, const bat *col, co
if (cminu == NULL) {
BBPunfix(c->batCacheid);
BBPunfix(u->batCacheid);
- throw(MAL, "sql.delta", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ throw(MAL, "sql.delta", GDK_EXCEPTION);
}
+ BAT *nres;
+ if ((nres = COLcopy(res, res->ttype, true, TRANSIENT))
== NULL) {
+ BBPunfix(res->batCacheid);
+ BBPunfix(u->batCacheid);
+ BBPunfix(cminu->batCacheid);
+ throw(MAL, "sql.delta", GDK_EXCEPTION);
+ }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list