LCOV - code coverage report
Current view: top level - monetdb5/modules/mal - bbp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 107 320 33.4 %
Date: 2024-04-26 00:35:57 Functions: 5 18 27.8 %

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

Generated by: LCOV version 1.14