Changeset: 627a57e19bb5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=627a57e19bb5
Modified Files:
gdk/gdk.h
gdk/gdk_bat.c
gdk/gdk_bbp.c
monetdb5/mal/mal_authorize.c
monetdb5/modules/kernel/bat5.c
monetdb5/modules/mal/remote.c
Branch: default
Log Message:
Merge with Aug2018 branch.
diffs (truncated from 343 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1550,8 +1550,6 @@ gdk_export void GDKqsort_rev(void *restr
* @tab BBPindex (str nme)
* @item BAT*
* @tab BATdescriptor (bat bi)
- * @item bat
- * @tab BBPcacheid (BAT *b)
* @end multitable
*
* The BAT Buffer Pool module contains the code to manage the storage
@@ -1565,8 +1563,7 @@ gdk_export void GDKqsort_rev(void *restr
*
* BATs loaded into memory are retained in a BAT buffer pool. They
* retain their position within the cache during their life cycle,
- * which make indexing BATs a stable operation. Their descriptor can
- * be obtained using BBPcacheid.
+ * which make indexing BATs a stable operation.
*
* The BBPindex routine checks if a BAT with a certain name is
* registered in the buffer pools. If so, it returns its BAT id. The
@@ -1589,7 +1586,7 @@ typedef struct {
str options; /* A string list of options */
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 */
- volatile int status; /* status mask used for spin locking */
+ volatile unsigned status; /* status mask used for spin locking */
/* MT_Id pid; non-zero thread-id if this BAT is private */
} BBPrec;
@@ -1623,8 +1620,7 @@ gdk_export BBPrec *BBP[N_BBPINIT];
#define BBP_pid(i) BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].pid
/* macros that nicely check parameters */
-#define BBPcacheid(b) ((b)->batCacheid)
-#define BBPstatus(i) (BBPcheck((i),"BBPstatus")?BBP_status(i):-1)
+#define BBPstatus(i) (BBPcheck((i),"BBPstatus")?BBP_status(i):0)
#define BBPrefs(i) (BBPcheck((i),"BBPrefs")?BBP_refs(i):-1)
#define BBPcache(i) (BBPcheck((i),"BBPcache")?BBP_cache(i):(BAT*) NULL)
#define BBPname(i) \
@@ -2394,7 +2390,8 @@ BATdescriptor(bat i)
BAT *b = NULL;
if (BBPcheck(i, "BATdescriptor")) {
- BBPfix(i);
+ if (BBPfix(i) <= 0)
+ return NULL;
b = BBP_cache(i);
if (b == NULL)
b = BBPdescriptor(i);
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -2057,7 +2057,7 @@ BATmode(BAT *b, int mode)
void
BATassertProps(BAT *b)
{
- int bbpstatus;
+ unsigned bbpstatus;
BATiter bi = bat_iterator(b);
BUN p, q;
int (*cmpf)(const void *, const void *);
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -19,7 +19,7 @@
* data-intensive applications. To eliminate all overhead, read-only
* access to the BBP may be done by table-lookups. The integer index
* type for these lookups is @emph{bat}, as retrieved by
- * @emph{BBPcacheid(b)}. The @emph{bat} zero is reserved for the nil
+ * @emph{b->batCacheid}. The @emph{bat} zero is reserved for the nil
* bat.
*
* @item persistence
@@ -111,7 +111,6 @@ struct BBPfarm_t BBPfarms[MAXFARMS];
bat *BBP_hash = NULL; /* BBP logical name hash buckets */
bat BBP_mask = 0; /* number of buckets = & mask */
-static void BBPspin(bat bid, const char *debug, int event);
static gdk_return BBPfree(BAT *b, const char *calledFrom);
static void BBPdestroy(BAT *b);
static void BBPuncacheit(bat bid, bool unloaddesc);
@@ -1538,7 +1537,7 @@ new_bbpentry(FILE *fp, bat i, const char
}
#endif
- if (fprintf(fp, "%s%zd %d %s %s %d " BUNFMT " "
+ if (fprintf(fp, "%s%zd %u %s %s %d " BUNFMT " "
BUNFMT " " OIDFMT, prefix,
/* BAT info */
(ssize_t) i,
@@ -1765,7 +1764,7 @@ BBPdump(void)
continue;
fprintf(stderr,
"# %d[%s]: nme='%s' refs=%d lrefs=%d "
- "status=%d count=" BUNFMT,
+ "status=%u count=" BUNFMT,
i,
ATOMname(b->ttype),
BBP_logical(i) ? BBP_logical(i) : "<NULL>",
@@ -2088,7 +2087,7 @@ gdk_return
BBPcacheit(BAT *bn, bool lock)
{
bat i = bn->batCacheid;
- int mode;
+ unsigned mode;
if (lock)
lock = locked_by == 0 || locked_by != MT_getpid();
@@ -2291,37 +2290,59 @@ BBPrename(bat bid, const char *nme)
* memory references can be unloaded.
*/
static inline void
-BBPspin(bat i, const char *s, int event)
+BBPspin(bat i, const char *s, unsigned event)
{
if (BBPcheck(i, "BBPspin") && (BBP_status(i) & event)) {
lng spin = LL_CONSTANT(0);
- while (BBP_status(i) & event) {
+ do {
MT_sleep_ms(KITTENNAP);
spin++;
- }
- BATDEBUG fprintf(stderr, "#BBPspin(%d,%s,%d): " LLFMT "
loops\n", (int) i, s, event, spin);
+ } while (BBP_status(i) & event);
+ BATDEBUG fprintf(stderr, "#BBPspin(%d,%s,%u): " LLFMT "
loops\n", (int) i, s, event, spin);
}
}
+/* This function can fail if the input parameter (i) is incorrect
+ * (unlikely), of if the bat is a view, this is a physical (not
+ * logical) incref (i.e. called through BBPfix(), and it is the first
+ * reference (refs was 0 and should become 1). It can fail in this
+ * case if the parent bat cannot be loaded.
+ * This means the return value of BBPfix should be checked in these
+ * circumstances, but not necessarily in others. */
static inline int
incref(bat i, bool logical, bool lock)
{
int refs;
bat tp, tvp;
- BAT *b;
+ BAT *b, *pb = NULL, *pvb = NULL;
bool load = false;
- if (is_bat_nil(i)) {
- /* Stefan: May this happen? Or should we better call
- * GDKerror(), here? */
- /* GDKerror("BBPincref() called with bat_nil!\n"); */
- return 0;
- }
-
if (!BBPcheck(i, logical ? "BBPretain" : "BBPfix"))
return 0;
+ /* Before we get the lock and before we do all sorts of
+ * things, make sure we can load the parent bats if there are
+ * any. If we can't load them, we can still easily fail. If
+ * this is indeed a view, but not the first physical
+ * reference, getting the parent BAT descriptor is
+ * superfluous, but not too expensive, so we do it anyway. */
+ if (!logical && (b = BBP_desc(i)) != NULL) {
+ if (b->theap.parentid) {
+ pb = BATdescriptor(b->theap.parentid);
+ if (pb == NULL)
+ return 0;
+ }
+ if (b->tvheap && b->tvheap->parentid != i) {
+ pvb = BATdescriptor(b->tvheap->parentid);
+ if (pvb == NULL) {
+ if (pb)
+ BBPunfix(pb->batCacheid);
+ return 0;
+ }
+ }
+ }
+
if (lock) {
for (;;) {
MT_lock_set(&GDKswapLock(i));
@@ -2371,9 +2392,7 @@ incref(bat i, bool logical, bool lock)
* to the correct values */
assert(!logical);
if (tp) {
- BAT *pb;
- incref(tp, false, lock);
- pb = getBBPdescriptor(tp, lock);
+ assert(pb != NULL);
b->theap.base = pb->theap.base + (size_t) b->theap.base;
/* if we shared the hash before, share it
* again note that if the parent's hash is
@@ -2382,16 +2401,20 @@ incref(bat i, bool logical, bool lock)
if (b->thash == (Hash *) -1)
b->thash = pb->thash;
}
- if (tvp) {
- incref(tvp, false, lock);
- (void) getBBPdescriptor(tvp, lock);
- }
/* done loading, release descriptor */
BBP_status_off(i, BBPLOADING, "BBPfix");
+ } else if (!logical) {
+ /* this wasn't the first physical reference, so undo
+ * the fixes on the parent bats */
+ if (pb)
+ BBPunfix(pb->batCacheid);
+ if (pvb)
+ BBPunfix(pvb->batCacheid);
}
return refs;
}
+/* see comment for incref */
int
BBPfix(bat i)
{
@@ -2698,7 +2721,7 @@ BBPsave(BAT *b)
BBPspin(bid, "BBPsave", BBPSAVING);
} else {
/* save it */
- int flags = BBPSAVING;
+ unsigned flags = BBPSAVING;
if (DELTAdirty(b)) {
flags |= BBPSWAPPED;
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -192,7 +192,7 @@ AUTHinitTables(const char *passwd) {
throw(MAL, "initTables.user", SQLSTATE(HY001)
MAL_MALLOC_FAIL " user table");
if (BATkey(user, true) != GDK_SUCCEED ||
- BBPrename(BBPcacheid(user), "M5system_auth_user") != 0
||
+ BBPrename(user->batCacheid, "M5system_auth_user") != 0
||
BATmode(user, PERSISTENT) != GDK_SUCCEED) {
throw(MAL, "initTables.user", GDK_EXCEPTION);
}
@@ -215,7 +215,7 @@ AUTHinitTables(const char *passwd) {
if (pass == NULL)
throw(MAL, "initTables.passwd", SQLSTATE(HY001)
MAL_MALLOC_FAIL " password table");
- if (BBPrename(BBPcacheid(pass), "M5system_auth_passwd_v2") != 0
||
+ if (BBPrename(pass->batCacheid, "M5system_auth_passwd_v2") != 0
||
BATmode(pass, PERSISTENT) != GDK_SUCCEED) {
throw(MAL, "initTables.user", GDK_EXCEPTION);
}
@@ -238,7 +238,7 @@ AUTHinitTables(const char *passwd) {
if (duser == NULL)
throw(MAL, "initTables.duser", SQLSTATE(HY001)
MAL_MALLOC_FAIL " deleted user table");
- if (BBPrename(BBPcacheid(duser), "M5system_auth_deleted") != 0
||
+ if (BBPrename(duser->batCacheid, "M5system_auth_deleted") != 0
||
BATmode(duser, PERSISTENT) != GDK_SUCCEED) {
throw(MAL, "initTables.user", GDK_EXCEPTION);
}
@@ -262,7 +262,7 @@ AUTHinitTables(const char *passwd) {
if (rt_key == NULL)
throw(MAL, "initTables.rt_key", SQLSTATE(HY001)
MAL_MALLOC_FAIL " remote table key bat");
- if (BBPrename(BBPcacheid(rt_key), "M5system_auth_rt_key") != 0
||
+ if (BBPrename(rt_key->batCacheid, "M5system_auth_rt_key") != 0
||
BATmode(rt_key, PERSISTENT) != GDK_SUCCEED)
throw(MAL, "initTables.rt_key", GDK_EXCEPTION);
}
@@ -286,7 +286,7 @@ AUTHinitTables(const char *passwd) {
if (rt_uri == NULL)
throw(MAL, "initTables.rt_uri", SQLSTATE(HY001)
MAL_MALLOC_FAIL " remote table uri bat");
- if (BBPrename(BBPcacheid(rt_uri), "M5system_auth_rt_uri") != 0
||
+ if (BBPrename(rt_uri->batCacheid, "M5system_auth_rt_uri") != 0
||
BATmode(rt_uri, PERSISTENT) != GDK_SUCCEED)
throw(MAL, "initTables.rt_uri", GDK_EXCEPTION);
}
@@ -310,7 +310,7 @@ AUTHinitTables(const char *passwd) {
if (rt_remoteuser == NULL)
throw(MAL, "initTables.rt_remoteuser", SQLSTATE(HY001)
MAL_MALLOC_FAIL " remote table local user bat");
- if (BBPrename(BBPcacheid(rt_remoteuser),
"M5system_auth_rt_remoteuser") != 0 ||
+ if (BBPrename(rt_remoteuser->batCacheid,
"M5system_auth_rt_remoteuser") != 0 ||
BATmode(rt_remoteuser, PERSISTENT) != GDK_SUCCEED)
throw(MAL, "initTables.rt_remoteuser", GDK_EXCEPTION);
}
@@ -334,7 +334,7 @@ AUTHinitTables(const char *passwd) {
if (rt_hashedpwd == NULL)
throw(MAL, "initTables.rt_hashedpwd", SQLSTATE(HY001)
MAL_MALLOC_FAIL " remote table local user bat");
- if (BBPrename(BBPcacheid(rt_hashedpwd),
"M5system_auth_rt_hashedpwd") != 0 ||
+ if (BBPrename(rt_hashedpwd->batCacheid,
"M5system_auth_rt_hashedpwd") != 0 ||
BATmode(rt_hashedpwd, PERSISTENT) != GDK_SUCCEED)
throw(MAL, "initTables.rt_hashedpwd", GDK_EXCEPTION);
}
@@ -358,7 +358,7 @@ AUTHinitTables(const char *passwd) {
if (rt_deleted == NULL)
throw(MAL, "initTables.rt_deleted", SQLSTATE(HY001)
MAL_MALLOC_FAIL " remote table local user bat");
- if (BBPrename(BBPcacheid(rt_deleted),
"M5system_auth_rt_deleted") != 0 ||
+ if (BBPrename(rt_deleted->batCacheid,
"M5system_auth_rt_deleted") != 0 ||
BATmode(rt_deleted, PERSISTENT) != GDK_SUCCEED)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list