str CMDbbpNames(bat *ret) { BAT *b; int i; b = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpNames", MAL_MALLOC_FAIL); BATseqbase(b,0); BBPlock("CMDbbpNames"); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid) { if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i)) ) { BUNappend(b, BBP_logical(i), FALSE); if (BBP_logical(-i) && (BBP_refs(-i) || BBP_lrefs(-i)) && !BBPtmpcheck(BBP_logical(-i))) BUNappend(b, BBP_logical(-i), FALSE); } } BBPunlock("CMDbbpNames"); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","name"); return MAL_SUCCEED; }
str CMDbbpHeat(bat *ret) { BAT *b; int i; b = BATnew(TYPE_void, TYPE_int, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpHeat", MAL_MALLOC_FAIL); BATseqbase(b,0); BBPlock("CMDbbpHeat"); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid) { if (BBP_cache(i) && !monet_modulesilent) { int heat = BBP_lastused(i); BUNins(b, &i, &heat, FALSE); } else if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { int zero = 0; BUNins(b, &i, &zero, FALSE); } } BBPunlock("CMDbbpHeat"); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","heat"); return MAL_SUCCEED; }
str CMDbbpKind(bat *ret) { BAT *b; int i; b = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpKind", MAL_MALLOC_FAIL); BATseqbase(b,0); BBPlock("CMDbbpKind"); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid) if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { char *mode = NULL; if ((BBP_status(i) & BBPDELETED) || !(BBP_status(i) & BBPPERSISTENT)) mode = "transient"; else mode = "persistent"; if (mode) BUNappend(b, mode, FALSE); } BBPunlock("CMDbbpKind"); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","kind"); return MAL_SUCCEED; }
/* * The BAT status is redundantly stored in CMDbat_info. */ str CMDbbpLocation(bat *ret) { BAT *b; int i; char buf[MAXPATHLEN]; char cwd[MAXPATHLEN]; if (getcwd(cwd, MAXPATHLEN) == NULL) throw(MAL, "catalog.bbpLocation", RUNTIME_DIR_ERROR); b = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpLocation", MAL_MALLOC_FAIL); BATseqbase(b,0); BBPlock("CMDbbpLocation"); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid) { if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { snprintf(buf,MAXPATHLEN,"%s/bat/%s",cwd,BBP_physical(i)); BUNappend(b, buf, FALSE); } } BBPunlock("CMDbbpLocation"); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","location"); return MAL_SUCCEED; }
str CMDbbpCount(bat *ret) { BAT *b, *bn; int i; lng l; b = BATnew(TYPE_void, TYPE_lng, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpCount", MAL_MALLOC_FAIL); BATseqbase(b,0); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid) { if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { bn = BATdescriptor(i); if (bn) { l = BATcount(bn); BUNappend(b, &l, FALSE); BBPunfix(bn->batCacheid); } } } if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","count"); return MAL_SUCCEED; }
/* * @- TMcommit * global commit without any multi-threaded access assumptions, thus * taking all BBP locks. It creates a new database checkpoint. */ gdk_return TMcommit(void) { gdk_return ret = GDK_FAIL; /* commit with the BBP globally locked */ BBPlock(); if (prelude(getBBPsize(), NULL) == GDK_SUCCEED && BBPsync(getBBPsize(), NULL) == GDK_SUCCEED) { epilogue(getBBPsize(), NULL); ret = GDK_SUCCEED; } BBPunlock(); return ret; }
str CMDbbpLRefCount(bat *ret) { BAT *b; int i; b = BATnew(TYPE_void, TYPE_int, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpLRefCount", MAL_MALLOC_FAIL); BATseqbase(b,0); BBPlock("CMDbbpLRefCount"); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid && BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { int refs = BBP_lrefs(i); BUNappend(b, &refs, FALSE); } BBPunlock("CMDbbpLRefCount"); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","lrefcnt"); return MAL_SUCCEED; }
/* * The BAT status is redundantly stored in CMDbat_info. */ str CMDbbpStatus(bat *ret) { BAT *b; int i; b = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpStatus", MAL_MALLOC_FAIL); BATseqbase(b,0); BBPlock("CMDbbpStatus"); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid) if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { char *loc = BBP_cache(i) ? "load" : "disk"; BUNappend(b, loc, FALSE); } BBPunlock("CMDbbpStatus"); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","status"); return MAL_SUCCEED; }
/* * The BAT dirty status:dirty => (mem != disk); diffs = not-committed */ str CMDbbpDirty(bat *ret) { BAT *b; int i; b = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpDirty", MAL_MALLOC_FAIL); BATseqbase(b,0); BBPlock("CMDbbpDirty"); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid) if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { BAT *bn = BBP_cache(i); BUNappend(b, bn ? BATdirty(bn) ? "dirty" : DELTAdirty(bn) ? "diffs" : "clean" : (BBP_status(i) & BBPSWAPPED) ? "diffs" : "clean", FALSE); } BBPunlock("CMDbbpDirty"); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","status"); return MAL_SUCCEED; }
str TRNglobal_sync(bit *ret) { *ret = BBPsync(getBBPsize(),NULL)?FALSE:TRUE; return MAL_SUCCEED; }
str CMDbbp(bat *ID, bat *NS, bat *HT, bat *TT, bat *CNT, bat *REFCNT, bat *LREFCNT, bat *LOCATION, bat *HEAT, bat *DIRTY, bat *STATUS, bat *KIND) { BAT *id, *ns, *ht, *tt, *cnt, *refcnt, *lrefcnt, *location, *heat, *dirty, *status, *kind, *bn; int i; char buf[MAXPATHLEN]; id = BATnew(TYPE_void, TYPE_int, getBBPsize(), TRANSIENT); ns = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); ht = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); tt = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); cnt = BATnew(TYPE_void, TYPE_lng, getBBPsize(), TRANSIENT); refcnt = BATnew(TYPE_void, TYPE_int, getBBPsize(), TRANSIENT); lrefcnt = BATnew(TYPE_void, TYPE_int, getBBPsize(), TRANSIENT); location = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); heat = BATnew(TYPE_void, TYPE_int, getBBPsize(), TRANSIENT); dirty = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); status = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); kind = BATnew(TYPE_void, TYPE_str, getBBPsize(), TRANSIENT); if (!id || !ns || !ht || !tt || !cnt || !refcnt || !lrefcnt || !location || !heat || !dirty || !status || !kind) { BBPreclaim(id); BBPreclaim(ns); BBPreclaim(ht); BBPreclaim(tt); BBPreclaim(cnt); BBPreclaim(refcnt); BBPreclaim(lrefcnt); BBPreclaim(location); BBPreclaim(heat); BBPreclaim(dirty); BBPreclaim(status); BBPreclaim(kind); throw(MAL, "catalog.bbp", MAL_MALLOC_FAIL); } BATseqbase(id, 0); BATseqbase(ns, 0); BATseqbase(ht, 0); BATseqbase(tt, 0); BATseqbase(cnt, 0); BATseqbase(refcnt, 0); BATseqbase(lrefcnt, 0); BATseqbase(location, 0); BATseqbase(heat, 0); BATseqbase(dirty, 0); BATseqbase(status, 0); BATseqbase(kind, 0); for (i = 1; i < getBBPsize(); i++) { if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { bn = BATdescriptor(i); if (bn) { lng l = BATcount(bn); int heat_ = BBP_lastused(i); char *loc = BBP_cache(i) ? "load" : "disk"; char *mode = "persistent"; int refs = BBP_refs(i); int lrefs = BBP_lrefs(i); if ((BBP_status(i) & BBPDELETED) || !(BBP_status(i) & BBPPERSISTENT)) mode = "transient"; snprintf(buf, MAXPATHLEN, "%s", BBP_physical(i)); BUNappend(id, &i, FALSE); BUNappend(ns, BBP_logical(i), FALSE); BUNappend(ht, BATatoms[BAThtype(bn)].name, FALSE); BUNappend(tt, BATatoms[BATttype(bn)].name, FALSE); BUNappend(cnt, &l, FALSE); BUNappend(refcnt, &refs, FALSE); BUNappend(lrefcnt, &lrefs, FALSE); BUNappend(location, buf, FALSE); BUNappend(heat, &heat_, FALSE); BUNappend(dirty, bn ? BATdirty(bn) ? "dirty" : DELTAdirty(bn) ? "diffs" : "clean" : (BBP_status(i) & BBPSWAPPED) ? "diffs" : "clean", FALSE); BUNappend(status, loc, FALSE); BUNappend(kind, mode, FALSE); BBPunfix(bn->batCacheid); } } } BBPkeepref(*ID = id->batCacheid); BBPkeepref(*NS = ns->batCacheid); BBPkeepref(*HT = ht->batCacheid); BBPkeepref(*TT = tt->batCacheid); BBPkeepref(*CNT = cnt->batCacheid); BBPkeepref(*REFCNT = refcnt->batCacheid); BBPkeepref(*LREFCNT = lrefcnt->batCacheid); BBPkeepref(*LOCATION = location->batCacheid); BBPkeepref(*HEAT = heat->batCacheid); BBPkeepref(*DIRTY = dirty->batCacheid); BBPkeepref(*STATUS = status->batCacheid); BBPkeepref(*KIND = kind->batCacheid); return MAL_SUCCEED; }
str TRNglobal_sync(bit *ret) { *ret = BBPsync(getBBPsize(), NULL) == GDK_SUCCEED; return MAL_SUCCEED; }