/* * The @#VIEWunlink@ routine cuts a reference to the parent. Part of the view * destroy sequence. */ static void VIEWunlink(BAT *b) { if (b) { bat hp = VIEWhparent(b), tp = VIEWtparent(b); bat vhp = VIEWvhparent(b), vtp = VIEWvtparent(b); BAT *hpb = NULL, *tpb = NULL; BAT *vhpb = NULL, *vtpb = NULL; if (hp) hpb = BBP_cache(hp); if (tp) tpb = BBP_cache(tp); if (hp && !vhp) vhp = hp; if (vhp) vhpb = BBP_cache(vhp); if (tp && !vtp) vtp = tp; if (vtp) vtpb = BBP_cache(vtp); if (hpb == NULL && tpb == NULL && vhpb == NULL && vtpb == NULL) return; /* unlink heaps shared with parent */ assert(b->H->vheap == NULL || b->H->vheap->parentid > 0); assert(b->T->vheap == NULL || b->T->vheap->parentid > 0); if (b->H->vheap && b->H->vheap->parentid != abs(b->batCacheid)) b->H->vheap = NULL; if (b->T->vheap && b->T->vheap->parentid != abs(b->batCacheid)) b->T->vheap = NULL; /* unlink properties shared with parent */ if (hpb && b->H->props && b->H->props == hpb->H->props) b->H->props = NULL; if (tpb && b->T->props && b->T->props == tpb->H->props) b->T->props = NULL; /* unlink hash accelerators shared with parent */ if (hpb && b->H->hash && b->H->hash == hpb->H->hash) b->H->hash = NULL; if (tpb && b->T->hash && b->T->hash == tpb->H->hash) b->T->hash = NULL; /* unlink imprints shared with parent */ if (hpb && b->H->imprints && b->H->imprints == hpb->H->imprints) b->H->imprints = NULL; if (tpb && b->T->imprints && b->T->imprints == tpb->H->imprints) b->T->imprints = NULL; } }
/* 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(); }
/* in the commit prelude, the delta status in the memory image of all * bats is commited */ static gdk_return prelude(int cnt, bat *subcommit) { int i = 0; while (++i < cnt) { bat bid = subcommit ? subcommit[i] : i; if (BBP_status(bid) & BBPPERSISTENT) { BAT *b = BBP_cache(bid); if (b == NULL && (BBP_status(bid) & BBPSWAPPED)) { b = BBPquickdesc(bid, TRUE); if (b == NULL) return GDK_FAIL; } if (b) { assert(!isVIEW(b)); assert(b->batRole == PERSISTENT); BATcommit(b); } } } return GDK_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; }
static int CMDsave(bit *res, const char *input) { bat bid = BBPindex(input); BAT *b; *res = FALSE; if (bid) { BBPfix(bid); b = BBP_cache(bid); if (b && BATdirty(b)) { if (BBPsave(b) == GDK_SUCCEED) *res = TRUE; } BBPunfix(bid); } return GDK_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; }