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 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; }
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; }
/* * 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; }
str CMDgetBATrefcnt(int *res, bat *bid) { BAT *b; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bbp.getRefCount", INTERNAL_BAT_ACCESS); } *res = BBP_refs(b->batCacheid); BBPunfix(b->batCacheid); return MAL_SUCCEED; }
str CMDbbpRefCount(bat *ret) { BAT *b; int i; b = BATnew(TYPE_void, TYPE_int, getBBPsize(), TRANSIENT); if (b == 0) throw(MAL, "catalog.bbpRefCount", MAL_MALLOC_FAIL); BATseqbase(b,0); BBPlock("CMDbbpRefCount"); for (i = 1; i < getBBPsize(); i++) if (i != b->batCacheid && BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) { int refs = BBP_refs(i); BUNappend(b, &refs, FALSE); } BBPunlock("CMDbbpRefCount"); if (!(b->batDirty&2)) BATsetaccess(b, BAT_READ); pseudo(ret,b,"bbp","refcnt"); return MAL_SUCCEED; }
/* in the commit epilogue, the BBP-status of the bats is changed to * reflect their presence in the succeeded checkpoint. Also bats from * the previous checkpoint that were deleted now are physically * destroyed. */ static void epilogue(int cnt, bat *subcommit) { int i = 0; while (++i < cnt) { bat bid = subcommit ? subcommit[i] : i; if (BBP_status(bid) & BBPPERSISTENT) { BBP_status_on(bid, BBPEXISTING, subcommit ? "TMsubcommit" : "TMcommit"); } else if (BBP_status(bid) & BBPDELETED) { /* check mmap modes of bats that are now * transient. this has to be done after the * commit succeeded, because the mmap modes * allowed on transient bats would be * dangerous on persistent bats. If the commit * failed, the already processed bats that * would become transient after the commit, * but didn't due to the failure, would be a * consistency risk. */ BAT *b = BBP_cache(bid); if (b) { /* check mmap modes */ if (BATcheckmodes(b, true) != GDK_SUCCEED) fprintf(stderr, "#epilogue: BATcheckmodes failed\n"); } } if ((BBP_status(bid) & BBPDELETED) && BBP_refs(bid) <= 0 && BBP_lrefs(bid) <= 0) { BAT *b = BBPquickdesc(bid, TRUE); /* the unloaded ones are deleted without * loading deleted disk images */ if (b) { BATdelete(b); if (BBP_cache(bid)) { /* those that quickdesc * decides to load => free * memory */ BATfree(b); } } BBPclear(bid); /* clear with locking */ } BBP_status_off(bid, BBPDELETED | BBPSWAPPED | BBPNEW, subcommit ? "TMsubcommit" : "TMcommit"); } GDKclrerr(); }
str CMDbbpbind(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { str name; ValPtr lhs; bat i; int ht,tt; BAT *b; (void) cntxt; (void) mb; /* fool compiler */ lhs = &stk->stk[pci->argv[0]]; name = *getArgReference_str(stk, pci, 1); if (isIdentifier(name) < 0) throw(MAL, "bbp.bind", IDENTIFIER_EXPECTED); i = BBPindex(name); if (i == 0) throw(MAL, "bbp.bind", RUNTIME_OBJECT_MISSING); /* make sure you load the descriptors and heaps */ b = (BAT *) BATdescriptor(i); if (b == 0) /* Simple ignore the binding if you can't find the bat */ throw(MAL, "bbp.bind", RUNTIME_OBJECT_MISSING); /* check conformity of the actual type and the one requested */ ht= getHeadType(getArgType(mb,pci,0)); tt= getColumnType(getArgType(mb,pci,0)); if( b->htype == TYPE_void && ht== TYPE_oid) ht= TYPE_void; if( b->ttype == TYPE_void && tt== TYPE_oid) tt= TYPE_void; if( ht != b->htype || tt != b->ttype){ BBPunfix(i); throw(MAL, "bbp.bind", SEMANTIC_TYPE_MISMATCH ); } /* make sure we are not dealing with an about to be deleted bat */ if( BBP_refs(b->batCacheid) == 1 && BBP_lrefs(b->batCacheid) == 0){ BBPunfix(i); throw(MAL, "bbp.bind", RUNTIME_OBJECT_MISSING); } BBPkeepref(b->batCacheid); lhs->vtype = TYPE_bat; lhs->val.bval = i; 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 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; }
static gdk_return CMDinfo(BAT **ret1, BAT **ret2, BAT *b) { BAT *bk, *bv; const char *mode, *accessmode; if (!(bk = BATnew(TYPE_void, TYPE_str, 128, TRANSIENT))) return GDK_FAIL; if (!(bv = BATnew(TYPE_void, TYPE_str, 128, TRANSIENT))) { BBPreclaim(bk); return GDK_FAIL; } BATseqbase(bk,0); BATseqbase(bv,0); *ret1 = bk; *ret2 = bv; if (b->batPersistence == PERSISTENT) { mode = "persistent"; } else if (b->batPersistence == TRANSIENT) { mode = "transient"; } else { mode ="unknown"; } switch (b->batRestricted) { case BAT_READ: accessmode = "read-only"; break; case BAT_WRITE: accessmode = "updatable"; break; case BAT_APPEND: accessmode = "append-only"; break; default: accessmode = "unknown"; } BUNappend(bk, "batId", FALSE); BUNappend(bv, BATgetId(b),FALSE); BUNappend(bk, "batCacheid", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->batCacheid)),FALSE); BUNappend(bk, "hparentid", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->H->heap.parentid)),FALSE); BUNappend(bk, "tparentid", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->T->heap.parentid)),FALSE); BUNappend(bk, "batSharecnt", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->batSharecnt)),FALSE); BUNappend(bk, "batCount", FALSE); BUNappend(bv, local_utoa((size_t)b->batCount),FALSE); BUNappend(bk, "batCapacity", FALSE); BUNappend(bv, local_utoa((size_t)b->batCapacity),FALSE); BUNappend(bk, "head", FALSE); BUNappend(bv, ATOMname(b->htype),FALSE); BUNappend(bk, "tail", FALSE); BUNappend(bv, ATOMname(b->ttype),FALSE); BUNappend(bk, "batPersistence", FALSE); BUNappend(bv, mode,FALSE); BUNappend(bk, "batRestricted", FALSE); BUNappend(bv, accessmode,FALSE); BUNappend(bk, "batRefcnt", FALSE); BUNappend(bv, local_itoa((ssize_t)(BBP_refs(b->batCacheid))),FALSE); BUNappend(bk, "batLRefcnt", FALSE); BUNappend(bv, local_itoa((ssize_t)(BBP_lrefs(b->batCacheid))),FALSE); BUNappend(bk, "batDirty", FALSE); BUNappend(bv, BATdirty(b) ? "dirty" : "clean",FALSE); BUNappend(bk, "hsorted", FALSE); BUNappend(bv, local_itoa((ssize_t)BAThordered(b)),FALSE); BUNappend(bk, "hrevsorted", FALSE); BUNappend(bv, local_itoa((ssize_t)BAThrevordered(b)),FALSE); BUNappend(bk, "hident", FALSE); BUNappend(bv, b->hident,FALSE); BUNappend(bk, "hdense", FALSE); BUNappend(bv, local_itoa((ssize_t)(BAThdense(b))),FALSE); BUNappend(bk, "hseqbase", FALSE); BUNappend(bv, oidtostr(b->hseqbase),FALSE); BUNappend(bk, "hkey", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->hkey)),FALSE); BUNappend(bk, "hvarsized", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->hvarsized)),FALSE); BUNappend(bk, "halign", FALSE); BUNappend(bv, local_utoa(b->halign),FALSE); BUNappend(bk, "hnosorted", FALSE); BUNappend(bv, local_utoa(b->H->nosorted),FALSE); BUNappend(bk, "hnorevsorted", FALSE); BUNappend(bv, local_utoa(b->H->norevsorted),FALSE); BUNappend(bk, "hnodense", FALSE); BUNappend(bv, local_utoa(b->H->nodense),FALSE); BUNappend(bk, "hnokey[0]", FALSE); BUNappend(bv, local_utoa(b->H->nokey[0]),FALSE); BUNappend(bk, "hnokey[1]", FALSE); BUNappend(bv, local_utoa(b->H->nokey[1]),FALSE); BUNappend(bk, "hnonil", FALSE); BUNappend(bv, local_utoa(b->H->nonil),FALSE); BUNappend(bk, "hnil", FALSE); BUNappend(bv, local_utoa(b->H->nil),FALSE); BUNappend(bk, "tident", FALSE); BUNappend(bv, b->tident,FALSE); BUNappend(bk, "tdense", FALSE); BUNappend(bv, local_itoa((ssize_t)(BATtdense(b))), FALSE); BUNappend(bk, "tseqbase", FALSE); BUNappend(bv, oidtostr(b->tseqbase), FALSE); BUNappend(bk, "tsorted", FALSE); BUNappend(bv, local_itoa((ssize_t)BATtordered(b)), FALSE); BUNappend(bk, "trevsorted", FALSE); BUNappend(bv, local_itoa((ssize_t)BATtrevordered(b)), FALSE); BUNappend(bk, "tkey", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->tkey)), FALSE); BUNappend(bk, "tvarsized", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->tvarsized)), FALSE); BUNappend(bk, "talign", FALSE); BUNappend(bv, local_utoa(b->talign), FALSE); BUNappend(bk, "tnosorted", FALSE); BUNappend(bv, local_utoa(b->T->nosorted), FALSE); BUNappend(bk, "tnorevsorted", FALSE); BUNappend(bv, local_utoa(b->T->norevsorted), FALSE); BUNappend(bk, "tnodense", FALSE); BUNappend(bv, local_utoa(b->T->nodense), FALSE); BUNappend(bk, "tnokey[0]", FALSE); BUNappend(bv, local_utoa(b->T->nokey[0]), FALSE); BUNappend(bk, "tnokey[1]", FALSE); BUNappend(bv, local_utoa(b->T->nokey[1]), FALSE); BUNappend(bk, "tnonil", FALSE); BUNappend(bv, local_utoa(b->T->nonil), FALSE); BUNappend(bk, "tnil", FALSE); BUNappend(bv, local_utoa(b->T->nil), FALSE); BUNappend(bk, "batInserted", FALSE); BUNappend(bv, local_utoa(b->batInserted), FALSE); BUNappend(bk, "batDeleted", FALSE); BUNappend(bv, local_utoa(b->batDeleted), FALSE); BUNappend(bk, "batFirst", FALSE); BUNappend(bv, local_utoa(b->batFirst), FALSE); BUNappend(bk, "htop", FALSE); BUNappend(bv, local_utoa(b->H->heap.free), FALSE); BUNappend(bk, "ttop", FALSE); BUNappend(bv, local_utoa(b->T->heap.free), FALSE); BUNappend(bk, "batStamp", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->batStamp)), FALSE); BUNappend(bk, "lastUsed", FALSE); BUNappend(bv, local_itoa((ssize_t)(BBP_lastused(b->batCacheid))), FALSE); BUNappend(bk, "curStamp", FALSE); BUNappend(bv, local_itoa((ssize_t)(BBPcurstamp())), FALSE); BUNappend(bk, "batCopiedtodisk", FALSE); BUNappend(bv, local_itoa((ssize_t)(b->batCopiedtodisk)), FALSE); BUNappend(bk, "batDirtydesc", FALSE); BUNappend(bv, b->batDirtydesc ? "dirty" : "clean", FALSE); BUNappend(bk, "H->heap.dirty", FALSE); BUNappend(bv, b->H->heap.dirty ? "dirty" : "clean", FALSE); BUNappend(bk, "T->heap.dirty", FALSE); BUNappend(bv, b->T->heap.dirty ? "dirty" : "clean", FALSE); infoHeap(bk, bv, &b->H->heap, "head."); infoHeap(bk, bv, &b->T->heap, "tail."); BUNappend(bk, "H->vheap->dirty", FALSE); BUNappend(bv, (b->H->vheap && b->H->vheap->dirty) ? "dirty" : "clean", FALSE); infoHeap(bk, bv, b->H->vheap, "hheap."); BUNappend(bk, "T->vheap->dirty", FALSE); BUNappend(bv, (b->T->vheap && b->T->vheap->dirty) ? "dirty" : "clean", FALSE); infoHeap(bk, bv, b->T->vheap, "theap."); /* dump index information */ if (b->H->hash) { HASHinfo(bk, bv, b->H->hash, "hhash->"); } if (b->T->hash) { HASHinfo(bk, bv, b->T->hash, "thash->"); } assert(BATcount(bk) == BATcount(bv)); return GDK_SUCCEED; }