LCOV - code coverage report
Current view: top level - monetdb5/modules/mal - bbp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 266 10.9 %
Date: 2021-10-27 03:06:47 Functions: 4 19 21.1 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /*
      10             :  * (c) M.L.Kersten, P. Boncz
      11             :  * BAT Buffer Pool
      12             :  * It is primarilly meant to ease inspection of the BAT collection managed
      13             :  * by the server.
      14             :  */
      15             : #include "monetdb_config.h"
      16             : #include "mal.h"
      17             : #include "mal_client.h"
      18             : #include "mal_interpreter.h"
      19             : #include "mal_module.h"
      20             : #include "mal_session.h"
      21             : #include "mal_resolve.h"
      22             : #include "mal_client.h"
      23             : #include "mal_interpreter.h"
      24             : #include "mal_profiler.h"
      25             : #include "bat5.h"
      26             : #include "mutils.h"
      27             : 
      28             : static int
      29           0 : pseudo(bat *ret, BAT *b, str X1,str X2) {
      30             :         char buf[BUFSIZ];
      31           0 :         snprintf(buf,BUFSIZ,"%s_%s", X1,X2);
      32           0 :         if ((BBPindex(buf) <= 0 && BBPrename(b->batCacheid, buf) != 0) || BATroles(b,X2) != GDK_SUCCEED) {
      33           0 :                 BBPunfix(b->batCacheid);
      34           0 :                 return -1;
      35             :         }
      36           0 :         *ret = b->batCacheid;
      37           0 :         BBPkeepref(*ret);
      38           0 :         return -0;
      39             : }
      40             : 
      41             : static str
      42           3 : CMDbbpbind(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      43             : {
      44             :         str name;
      45             :         ValPtr lhs;
      46             :         bat i;
      47             :         int tt;
      48             :         BAT *b;
      49             : 
      50             :         (void) cntxt;
      51             :         (void) mb;              /* fool compiler */
      52           3 :         lhs = &stk->stk[pci->argv[0]];
      53           3 :         name = *getArgReference_str(stk, pci, 1);
      54           3 :         if (name == NULL || isIdentifier(name) < 0)
      55           0 :                 throw(MAL, "bbp.bind", IDENTIFIER_EXPECTED);
      56           3 :         i = BBPindex(name);
      57           3 :         if (i == 0)
      58           0 :                 throw(MAL, "bbp.bind", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      59             :         /* make sure you load the descriptors and heaps */
      60           3 :         b = (BAT *) BATdescriptor(i);
      61           3 :         if (b == 0)
      62             :                 /* Simple ignore the binding if you can't find the bat */
      63           0 :                 throw(MAL, "bbp.bind", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      64             : 
      65             :         /* check conformity of the actual type and the one requested */
      66           3 :         tt= getBatType(getArgType(mb,pci,0));
      67           3 :         if( b->ttype == TYPE_void && tt== TYPE_oid) tt= TYPE_void;
      68             : 
      69           3 :         if( tt != b->ttype){
      70           0 :                 BBPunfix(i);
      71           0 :                 throw(MAL, "bbp.bind", SEMANTIC_TYPE_MISMATCH );
      72             :         }
      73             :         /* make sure we are not dealing with an about to be deleted bat */
      74           3 :         if( BBP_refs(b->batCacheid) == 1 &&
      75           3 :                 BBP_lrefs(b->batCacheid) == 0){
      76           0 :                 BBPunfix(i);
      77           0 :                 throw(MAL, "bbp.bind", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      78             :         }
      79             : 
      80           3 :         BBPkeepref(b->batCacheid);
      81           3 :         lhs->vtype = TYPE_bat;
      82           3 :         lhs->val.bval = i;
      83           3 :         return MAL_SUCCEED;
      84             : }
      85             : /*
      86             :  * BBP status
      87             :  * The BAT buffer pool datastructures describe the memory resident information
      88             :  * on the whereabouts of the BATs. The three predominant tables are made accessible
      89             :  * for inspection.
      90             :  *
      91             :  * The most interesting system bat for end-users is the BID-> NAME mapping,
      92             :  * because it provides access to the system guaranteed persistent BAT identifier.
      93             :  * It may be the case that the user already introduced a BAT with this name,
      94             :  * it is simply removed first
      95             :  */
      96             : 
      97             : static str
      98           0 : CMDbbpNames(bat *ret)
      99             : {
     100             :         BAT *b;
     101             :         int i;
     102             : 
     103           0 :         b = COLnew(0, TYPE_str, getBBPsize(), TRANSIENT);
     104           0 :         if (b == 0)
     105           0 :                 throw(MAL, "catalog.bbpNames", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     106             : 
     107           0 :         BBPlock();
     108           0 :         for (i = 1; i < getBBPsize(); i++)
     109           0 :                 if (i != b->batCacheid) {
     110           0 :                         if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i)) ) {
     111           0 :                                 if (BUNappend(b, BBP_logical(i), false) != GDK_SUCCEED) {
     112           0 :                                         BBPunlock();
     113           0 :                                         BBPreclaim(b);
     114           0 :                                         throw(MAL, "catalog.bbpNames", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     115             :                                 }
     116             :                         }
     117             :                 }
     118           0 :         BBPunlock();
     119           0 :         if (pseudo(ret,b,"bbp","name"))
     120           0 :                 throw(MAL, "catalog.bbpNames", GDK_EXCEPTION);
     121             :         return MAL_SUCCEED;
     122             : }
     123             : static str
     124           0 : CMDbbpDiskSpace(lng *ret)
     125             : {
     126           0 :         *ret=  getDiskSpace();
     127           0 :         return MAL_SUCCEED;
     128             : }
     129             : static str
     130           0 : CMDgetPageSize(int *ret)
     131             : {
     132           0 :         *ret= (int)  MT_pagesize();
     133           0 :         return MAL_SUCCEED;
     134             : }
     135             : 
     136             : static str
     137           0 : CMDbbpName(str *ret, bat *bid)
     138             : {
     139           0 :         *ret = (str) GDKstrdup(BBP_logical(*bid));
     140           0 :         if (*ret == NULL)
     141           0 :                 throw(MAL, "catalog.bbpName", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     142             :         return MAL_SUCCEED;
     143             : }
     144             : 
     145             : static str
     146           0 : CMDbbpCount(bat *ret)
     147             : {
     148             :         BAT *b, *bn;
     149             :         int i;
     150             :         lng l;
     151             : 
     152           0 :         b = COLnew(0, TYPE_lng, getBBPsize(), TRANSIENT);
     153           0 :         if (b == 0)
     154           0 :                 throw(MAL, "catalog.bbpCount", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     155             : 
     156           0 :         for (i = 1; i < getBBPsize(); i++)
     157           0 :                 if (i != b->batCacheid) {
     158           0 :                         if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     159           0 :                                 bn = BATdescriptor(i);
     160           0 :                                 if (bn) {
     161           0 :                                         l = BATcount(bn);
     162           0 :                                         BBPunfix(bn->batCacheid);
     163           0 :                                         if (BUNappend(b,  &l, false) != GDK_SUCCEED) {
     164           0 :                                                 BBPreclaim(b);
     165           0 :                                                 throw(MAL, "catalog.bbpCount", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     166             :                                         }
     167             :                                 }
     168             :                         }
     169             :                 }
     170           0 :         if (pseudo(ret,b,"bbp","count"))
     171           0 :                 throw(MAL, "catalog.bbpCount", GDK_EXCEPTION);
     172             :         return MAL_SUCCEED;
     173             : }
     174             : 
     175             : /*
     176             :  * The BAT status is redundantly stored in CMDbat_info.
     177             :  */
     178             : static str
     179           0 : CMDbbpLocation(bat *ret)
     180             : {
     181             :         BAT *b;
     182             :         int i;
     183             :         char buf[FILENAME_MAX];
     184             :         char cwd[FILENAME_MAX];
     185             : 
     186           0 :         if (MT_getcwd(cwd, FILENAME_MAX) == NULL)
     187           0 :                 throw(MAL, "catalog.bbpLocation", RUNTIME_DIR_ERROR);
     188             : 
     189           0 :         b = COLnew(0, TYPE_str, getBBPsize(), TRANSIENT);
     190           0 :         if (b == 0)
     191           0 :                 throw(MAL, "catalog.bbpLocation", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     192             : 
     193           0 :         BBPlock();
     194           0 :         for (i = 1; i < getBBPsize(); i++)
     195           0 :                 if (i != b->batCacheid) {
     196           0 :                         if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     197           0 :                                 int len = snprintf(buf,FILENAME_MAX,"%s/bat/%s",cwd,BBP_physical(i));
     198           0 :                                 if (len == -1 || len >= FILENAME_MAX) {
     199           0 :                                         BBPunlock();
     200           0 :                                         BBPreclaim(b);
     201           0 :                                         throw(MAL, "catalog.bbpLocation", SQLSTATE(HY013) "Could not write bpp filename path is too large");
     202             :                                 }
     203           0 :                                 if (BUNappend(b, buf, false) != GDK_SUCCEED) {
     204           0 :                                         BBPunlock();
     205           0 :                                         BBPreclaim(b);
     206           0 :                                         throw(MAL, "catalog.bbpLocation", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     207             :                                 }
     208             :                         }
     209             :                 }
     210           0 :         BBPunlock();
     211           0 :         if (pseudo(ret,b,"bbp","location"))
     212           0 :                 throw(MAL, "catalog.bbpLocation", GDK_EXCEPTION);
     213             :         return MAL_SUCCEED;
     214             : }
     215             : 
     216             : /*
     217             :  * The BAT dirty status:dirty => (mem != disk); diffs = not-committed
     218             :  */
     219             : static str
     220           0 : CMDbbpDirty(bat *ret)
     221             : {
     222             :         BAT *b;
     223             :         int i;
     224             : 
     225           0 :         b = COLnew(0, TYPE_str, getBBPsize(), TRANSIENT);
     226           0 :         if (b == 0)
     227           0 :                 throw(MAL, "catalog.bbpDirty", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     228             : 
     229           0 :         BBPlock();
     230           0 :         for (i = 1; i < getBBPsize(); i++)
     231           0 :                 if (i != b->batCacheid)
     232           0 :                         if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     233           0 :                                 BAT *bn = BBP_cache(i);
     234             : 
     235           0 :                                 if (BUNappend(b, bn ? BATdirty(bn) ? "dirty" : DELTAdirty(bn) ? "diffs" : "clean" : (BBP_status(i) & BBPSWAPPED) ? "diffs" : "clean", false) != GDK_SUCCEED) {
     236           0 :                                         BBPunlock();
     237           0 :                                         BBPreclaim(b);
     238           0 :                                         throw(MAL, "catalog.bbpDirty", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     239             :                                 }
     240             :                         }
     241           0 :         BBPunlock();
     242           0 :         if (pseudo(ret,b,"bbp","status"))
     243           0 :                 throw(MAL, "catalog.bbpDirty", GDK_EXCEPTION);
     244             :         return MAL_SUCCEED;
     245             : }
     246             : 
     247             : /*
     248             :  * The BAT status is redundantly stored in CMDbat_info.
     249             :  */
     250             : static str
     251           0 : CMDbbpStatus(bat *ret)
     252             : {
     253             :         BAT *b;
     254             :         int i;
     255             : 
     256           0 :         b = COLnew(0, TYPE_str, getBBPsize(), TRANSIENT);
     257           0 :         if (b == 0)
     258           0 :                 throw(MAL, "catalog.bbpStatus", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     259             : 
     260           0 :         BBPlock();
     261           0 :         for (i = 1; i < getBBPsize(); i++)
     262           0 :                 if (i != b->batCacheid)
     263           0 :                         if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     264           0 :                                 char *loc = BBP_cache(i) ? "load" : "disk";
     265             : 
     266           0 :                                 if (BUNappend(b, loc, false) != GDK_SUCCEED) {
     267           0 :                                         BBPunlock();
     268           0 :                                         BBPreclaim(b);
     269           0 :                                         throw(MAL, "catalog.bbpStatus", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     270             :                                 }
     271             :                         }
     272           0 :         BBPunlock();
     273           0 :         if (pseudo(ret,b,"bbp","status"))
     274           0 :                 throw(MAL, "catalog.bbpStatus", GDK_EXCEPTION);
     275             :         return MAL_SUCCEED;
     276             : }
     277             : 
     278             : static str
     279           0 : CMDbbpKind(bat *ret)
     280             : {
     281             :         BAT *b;
     282             :         int i;
     283             : 
     284           0 :         b = COLnew(0, TYPE_str, getBBPsize(), TRANSIENT);
     285           0 :         if (b == 0)
     286           0 :                 throw(MAL, "catalog.bbpKind", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     287             : 
     288           0 :         BBPlock();
     289           0 :         for (i = 1; i < getBBPsize(); i++)
     290           0 :                 if (i != b->batCacheid && BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     291             :                         const char *mode;
     292             : 
     293           0 :                         if ((BBP_status(i) & BBPDELETED) || !(BBP_status(i) & BBPPERSISTENT))
     294             :                                 mode = "transient";
     295             :                         else
     296             :                                 mode = "persistent";
     297           0 :                         if (BUNappend(b, mode, false) != GDK_SUCCEED) {
     298           0 :                                 BBPunlock();
     299           0 :                                 BBPreclaim(b);
     300           0 :                                         throw(MAL, "catalog.bbpKind", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     301             :                         }
     302             :                 }
     303           0 :         BBPunlock();
     304           0 :         if (pseudo(ret,b,"bbp","kind"))
     305           0 :                 throw(MAL, "catalog.bbpKind", GDK_EXCEPTION);
     306             :         return MAL_SUCCEED;
     307             : }
     308             : 
     309             : static str
     310           0 : CMDbbpRefCount(bat *ret)
     311             : {
     312             :         BAT *b;
     313             :         int i;
     314             : 
     315           0 :         b = COLnew(0, TYPE_int, getBBPsize(), TRANSIENT);
     316           0 :         if (b == 0)
     317           0 :                 throw(MAL, "catalog.bbpRefCount", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     318             : 
     319           0 :         BBPlock();
     320           0 :         for (i = 1; i < getBBPsize(); i++)
     321           0 :                 if (i != b->batCacheid && BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     322           0 :                         int refs = BBP_refs(i);
     323             : 
     324           0 :                         if (BUNappend(b, &refs, false) != GDK_SUCCEED) {
     325           0 :                                 BBPunlock();
     326           0 :                                 BBPreclaim(b);
     327           0 :                                 throw(MAL, "catalog.bbpRefCount", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     328             :                         }
     329             :                 }
     330           0 :         BBPunlock();
     331           0 :         if (pseudo(ret,b,"bbp","refcnt"))
     332           0 :                 throw(MAL, "catalog.bbpRefCount", GDK_EXCEPTION);
     333             :         return MAL_SUCCEED;
     334             : }
     335             : 
     336             : static str
     337           0 : CMDbbpLRefCount(bat *ret)
     338             : {
     339             :         BAT *b;
     340             :         int i;
     341             : 
     342           0 :         b = COLnew(0, TYPE_int, getBBPsize(), TRANSIENT);
     343           0 :         if (b == 0)
     344           0 :                 throw(MAL, "catalog.bbpLRefCount", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     345             : 
     346           0 :         BBPlock();
     347           0 :         for (i = 1; i < getBBPsize(); i++)
     348           0 :                 if (i != b->batCacheid && BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     349           0 :                         int refs = BBP_lrefs(i);
     350             : 
     351           0 :                         if (BUNappend(b, &refs, false) != GDK_SUCCEED) {
     352           0 :                                 BBPunlock();
     353           0 :                                 BBPreclaim(b);
     354           0 :                                 throw(MAL, "catalog.bbpLRefCount", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     355             :                         }
     356             :                 }
     357           0 :         BBPunlock();
     358           0 :         if (pseudo(ret,b,"bbp","lrefcnt"))
     359           0 :                 throw(MAL, "catalog.bbpLRefCount", GDK_EXCEPTION);
     360             :         return MAL_SUCCEED;
     361             : }
     362             : 
     363             : static str
     364           0 : CMDbbpgetIndex(int *res, bat *bid)
     365             : {
     366           0 :         *res= *bid;
     367           0 :         return MAL_SUCCEED;
     368             : }
     369             : 
     370             : static str
     371           7 : CMDgetBATrefcnt(int *res, bat *bid)
     372             : {
     373             :         BAT *b;
     374             : 
     375           7 :         if ((b = BATdescriptor(*bid)) == NULL) {
     376           0 :                 throw(MAL, "bbp.getRefCount", INTERNAL_BAT_ACCESS);
     377             :         }
     378           7 :         *res = BBP_refs(b->batCacheid);
     379           7 :         BBPunfix(b->batCacheid);
     380           7 :         return MAL_SUCCEED;
     381             : }
     382             : 
     383             : static str
     384          35 : CMDgetBATlrefcnt(int *res, bat *bid)
     385             : {
     386             :         BAT *b;
     387             : 
     388          35 :         if ((b = BATdescriptor(*bid)) == NULL) {
     389           0 :                 throw(MAL, "bbp.getLRefCount", INTERNAL_BAT_ACCESS);
     390             :         }
     391          35 :         *res = BBP_lrefs(b->batCacheid);
     392          35 :         BBPunfix(b->batCacheid);
     393          35 :         return MAL_SUCCEED;
     394             : }
     395             : 
     396             : static str
     397           0 : CMDbbp(bat *ID, bat *NS, bat *TT, bat *CNT, bat *REFCNT, bat *LREFCNT, bat *LOCATION, bat *HEAT, bat *DIRTY, bat *STATUS, bat *KIND)
     398             : {
     399             :         BAT *id, *ns, *tt, *cnt, *refcnt, *lrefcnt, *location, *heat, *dirty, *status, *kind, *bn;
     400             :         bat     i;
     401             :         char buf[FILENAME_MAX];
     402           0 :         bat sz = getBBPsize();
     403             :         str msg = MAL_SUCCEED;
     404             : 
     405           0 :         id = COLnew(0, TYPE_int, (BUN) sz, TRANSIENT);
     406           0 :         ns = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     407           0 :         tt = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     408           0 :         cnt = COLnew(0, TYPE_lng, (BUN) sz, TRANSIENT);
     409           0 :         refcnt = COLnew(0, TYPE_int, (BUN) sz, TRANSIENT);
     410           0 :         lrefcnt = COLnew(0, TYPE_int, (BUN) sz, TRANSIENT);
     411           0 :         location = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     412           0 :         heat = COLnew(0, TYPE_int, (BUN) sz, TRANSIENT);
     413           0 :         dirty = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     414           0 :         status = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     415           0 :         kind = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     416             : 
     417           0 :         if (!id || !ns || !tt || !cnt || !refcnt || !lrefcnt || !location || !heat || !dirty || !status || !kind) {
     418           0 :                 goto bailout;
     419             :         }
     420           0 :         for (i = 1; i < sz; i++) {
     421           0 :                 if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     422           0 :                         bn = BBP_desc(i);
     423           0 :                         if (bn) {
     424           0 :                                 lng l = BATcount(bn);
     425           0 :                                 int heat_ = 0, len;
     426           0 :                                 char *loc = BBP_cache(i) ? "load" : "disk";
     427             :                                 char *mode = "persistent";
     428           0 :                                 int refs = BBP_refs(i);
     429           0 :                                 int lrefs = BBP_lrefs(i);
     430             : 
     431           0 :                                 if ((BBP_status(i) & BBPDELETED) || !(BBP_status(i) & BBPPERSISTENT))
     432             :                                         mode = "transient";
     433           0 :                                 len = snprintf(buf, FILENAME_MAX, "%s", BBP_physical(i));
     434           0 :                                 if (len == -1 || len >= FILENAME_MAX) {
     435           0 :                                         msg = createException(MAL, "catalog.bbp", SQLSTATE(HY013) "Could not bpp filename path is too large");
     436           0 :                                         goto bailout;
     437             :                                 }
     438           0 :                                 if (BUNappend(id, &i, false) != GDK_SUCCEED ||
     439           0 :                                         BUNappend(ns, BBP_logical(i), false) != GDK_SUCCEED ||
     440           0 :                                         BUNappend(tt, BATatoms[bn->ttype].name, false) != GDK_SUCCEED ||
     441           0 :                                         BUNappend(cnt, &l, false) != GDK_SUCCEED ||
     442           0 :                                         BUNappend(refcnt, &refs, false) != GDK_SUCCEED ||
     443           0 :                                         BUNappend(lrefcnt, &lrefs, false) != GDK_SUCCEED ||
     444           0 :                                         BUNappend(location, buf, false) != GDK_SUCCEED ||
     445           0 :                                         BUNappend(heat, &heat_, false) != GDK_SUCCEED ||
     446           0 :                                         BUNappend(dirty, BBP_cache(i) ? BATdirty(bn) ? "dirty" : DELTAdirty(bn) ? "diffs" : "clean" : (BBP_status(i) & BBPSWAPPED) ? "diffs" : "clean", false) != GDK_SUCCEED ||
     447           0 :                                         BUNappend(status, loc, false) != GDK_SUCCEED ||
     448           0 :                                         BUNappend(kind, mode, false) != GDK_SUCCEED) {
     449           0 :                                         msg = createException(MAL, "catalog.bbp", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     450           0 :                                         goto bailout;
     451             :                                 }
     452             :                         }
     453             :                 }
     454             :         }
     455           0 :         BBPkeepref(*ID = id->batCacheid);
     456           0 :         BBPkeepref(*NS = ns->batCacheid);
     457           0 :         BBPkeepref(*TT = tt->batCacheid);
     458           0 :         BBPkeepref(*CNT = cnt->batCacheid);
     459           0 :         BBPkeepref(*REFCNT = refcnt->batCacheid);
     460           0 :         BBPkeepref(*LREFCNT = lrefcnt->batCacheid);
     461           0 :         BBPkeepref(*LOCATION = location->batCacheid);
     462           0 :         BBPkeepref(*HEAT = heat->batCacheid);
     463           0 :         BBPkeepref(*DIRTY = dirty->batCacheid);
     464           0 :         BBPkeepref(*STATUS = status->batCacheid);
     465           0 :         BBPkeepref(*KIND = kind->batCacheid);
     466           0 :         return MAL_SUCCEED;
     467             : 
     468           0 :   bailout:
     469           0 :         BBPreclaim(id);
     470           0 :         BBPreclaim(ns);
     471           0 :         BBPreclaim(tt);
     472           0 :         BBPreclaim(cnt);
     473           0 :         BBPreclaim(refcnt);
     474           0 :         BBPreclaim(lrefcnt);
     475           0 :         BBPreclaim(location);
     476           0 :         BBPreclaim(heat);
     477           0 :         BBPreclaim(dirty);
     478           0 :         BBPreclaim(status);
     479           0 :         BBPreclaim(kind);
     480           0 :         return msg;
     481             : }
     482             : 
     483             : static str
     484           0 : CMDsetName(str *rname, const bat *bid, str *name)
     485             : {
     486             :         BAT *b;
     487           0 :         if ((b = BATdescriptor(*bid)) == NULL) {
     488           0 :                 throw(MAL, "bbp.setName", INTERNAL_BAT_ACCESS);
     489             :         }
     490           0 :         if (BBPrename(b->batCacheid, *name) != 0) {
     491           0 :                 BBPunfix(b->batCacheid);
     492           0 :                 throw(MAL, "bbp.setName", GDK_EXCEPTION);
     493             :         }
     494           0 :         *rname = GDKstrdup(*name);
     495           0 :         BBPunfix(b->batCacheid);
     496           0 :         if (*rname == NULL)
     497           0 :                 throw(MAL, "bbp.setName", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     498             :         return MAL_SUCCEED;
     499             : }
     500             : 
     501             : #include "mel.h"
     502             : mel_func bbp_init_funcs[] = {
     503             :  pattern("bbp", "bind", CMDbbpbind, false, "Locate the BAT using its logical name", args(1,2, batargany("",2),arg("name",str))),
     504             :  command("bbp", "getIndex", CMDbbpgetIndex, false, "Retrieve the index in the BBP", args(1,2, arg("",int),batargany("b",2))),
     505             :  command("bbp", "getNames", CMDbbpNames, false, "Map BAT into its bbp name", args(1,1, batarg("",str))),
     506             :  command("bbp", "get", CMDbbp, false, "bpp", args(11,11, batarg("id",int),batarg("ns",str),batarg("tt",str),batarg("cnt",lng),batarg("refcnt",int),batarg("lrefcnt",int),batarg("location",str),batarg("heat",int),batarg("dirty",str),batarg("status",str),batarg("kind",str))),
     507             :  command("bbp", "getName", CMDbbpName, false, "Map a BAT into its internal name", args(1,2, arg("",str),batargany("b",1))),
     508             :  command("bbp", "setName", CMDsetName, false, "Rename a BAT", args(1,3, arg("",str),batargany("b",1),arg("n",str))),
     509             :  command("bbp", "getCount", CMDbbpCount, false, "Create a BAT with the cardinalities of all known BATs", args(1,1, batarg("",lng))),
     510             :  command("bbp", "getRefCount", CMDbbpRefCount, false, "Create a BAT with the (hard) reference counts", args(1,1, batarg("",int))),
     511             :  command("bbp", "getLRefCount", CMDbbpLRefCount, false, "Create a BAT with the logical reference counts", args(1,1, batarg("",int))),
     512             :  command("bbp", "getLocation", CMDbbpLocation, false, "Create a BAT with their disk locations", args(1,1, batarg("",str))),
     513             :  command("bbp", "getDirty", CMDbbpDirty, false, "Create a BAT with the dirty/ diffs/clean status", args(1,1, batarg("",str))),
     514             :  command("bbp", "getStatus", CMDbbpStatus, false, "Create a BAT with the disk/load status", args(1,1, batarg("",str))),
     515             :  command("bbp", "getKind", CMDbbpKind, false, "Create a BAT with the persistency status", args(1,1, batarg("",str))),
     516             :  command("bbp", "getRefCount", CMDgetBATrefcnt, false, "Utility for debugging MAL interpreter", args(1,2, arg("",int),batargany("b",1))),
     517             :  command("bbp", "getLRefCount", CMDgetBATlrefcnt, false, "Utility for debugging MAL interpreter", args(1,2, arg("",int),batargany("b",1))),
     518             :  command("bbp", "getDiskSpace", CMDbbpDiskSpace, false, "Estimate the amount of disk space occupied by dbpath", args(1,1, arg("",lng))),
     519             :  command("bbp", "getPageSize", CMDgetPageSize, false, "Obtain the memory page size", args(1,1, arg("",int))),
     520             :  { .imp=NULL }
     521             : };
     522             : #include "mal_import.h"
     523             : #ifdef _MSC_VER
     524             : #undef read
     525             : #pragma section(".CRT$XCU",read)
     526             : #endif
     527         257 : LIB_STARTUP_FUNC(init_bbp_mal)
     528         257 : { mal_module("bbp", NULL, bbp_init_funcs); }

Generated by: LCOV version 1.14