LCOV - code coverage report
Current view: top level - monetdb5/modules/mal - bbp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 108 321 33.6 %
Date: 2024-04-25 20:03:45 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->vtype = TYPE_bat;
      73           3 :         lhs->val.bval = i;
      74           3 :         return MAL_SUCCEED;
      75             : }
      76             : 
      77             : /*
      78             :  * BBP status
      79             :  * The BAT buffer pool datastructures describe the memory resident information
      80             :  * on the whereabouts of the BATs. The three predominant tables are made accessible
      81             :  * for inspection.
      82             :  *
      83             :  * The most interesting system bat for end-users is the BID-> NAME mapping,
      84             :  * because it provides access to the system guaranteed persistent BAT identifier.
      85             :  * It may be the case that the user already introduced a BAT with this name,
      86             :  * it is simply removed first
      87             :  */
      88             : 
      89             : static str
      90           0 : CMDbbpNames(bat *ret)
      91             : {
      92           0 :         BAT *b;
      93           0 :         int i;
      94             : 
      95           0 :         b = COLnew(0, TYPE_str, getBBPsize(), TRANSIENT);
      96           0 :         if (b == 0)
      97           0 :                 throw(MAL, "catalog.bbpNames", SQLSTATE(HY013) MAL_MALLOC_FAIL);
      98             : 
      99           0 :         BBPlock();
     100           0 :         for (i = 1; i < getBBPsize(); i++)
     101           0 :                 if (i != b->batCacheid) {
     102           0 :                         if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     103           0 :                                 if (BUNappend(b, BBP_logical(i), false) != GDK_SUCCEED) {
     104           0 :                                         BBPunlock();
     105           0 :                                         BBPreclaim(b);
     106           0 :                                         throw(MAL, "catalog.bbpNames",
     107             :                                                   SQLSTATE(HY013) MAL_MALLOC_FAIL);
     108             :                                 }
     109             :                         }
     110             :                 }
     111           0 :         BBPunlock();
     112           0 :         *ret = b->batCacheid;
     113           0 :         BBPkeepref(b);
     114           0 :         return MAL_SUCCEED;
     115             : }
     116             : 
     117             : static str
     118           0 : CMDbbpDiskSpace(lng *ret)
     119             : {
     120           0 :         *ret = getDiskSpace();
     121           0 :         return MAL_SUCCEED;
     122             : }
     123             : 
     124             : static str
     125           0 : CMDgetPageSize(int *ret)
     126             : {
     127           0 :         *ret = (int) MT_pagesize();
     128           0 :         return MAL_SUCCEED;
     129             : }
     130             : 
     131             : static str
     132           0 : CMDbbpName(str *ret, bat *bid)
     133             : {
     134           0 :         *ret = (str) GDKstrdup(BBP_logical(*bid));
     135           0 :         if (*ret == NULL)
     136           0 :                 throw(MAL, "catalog.bbpName", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     137             :         return MAL_SUCCEED;
     138             : }
     139             : 
     140             : static str
     141           0 : CMDbbpCount(bat *ret)
     142             : {
     143           0 :         BAT *b, *bn;
     144           0 :         int i;
     145           0 :         lng l;
     146             : 
     147           0 :         b = COLnew(0, TYPE_lng, getBBPsize(), TRANSIENT);
     148           0 :         if (b == 0)
     149           0 :                 throw(MAL, "catalog.bbpCount", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     150             : 
     151           0 :         for (i = 1; i < getBBPsize(); i++)
     152           0 :                 if (i != b->batCacheid) {
     153           0 :                         if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     154           0 :                                 bn = BATdescriptor(i);
     155           0 :                                 if (bn) {
     156           0 :                                         l = BATcount(bn);
     157           0 :                                         BBPunfix(bn->batCacheid);
     158           0 :                                         if (BUNappend(b, &l, false) != GDK_SUCCEED) {
     159           0 :                                                 BBPreclaim(b);
     160           0 :                                                 throw(MAL, "catalog.bbpCount",
     161             :                                                           SQLSTATE(HY013) MAL_MALLOC_FAIL);
     162             :                                         }
     163             :                                 }
     164             :                         }
     165             :                 }
     166           0 :         *ret = b->batCacheid;
     167           0 :         BBPkeepref(b);
     168           0 :         return MAL_SUCCEED;
     169             : }
     170             : 
     171             : /*
     172             :  * The BAT status is redundantly stored in CMDbat_info.
     173             :  */
     174             : static str
     175           0 : CMDbbpLocation(bat *ret)
     176             : {
     177           0 :         BAT *b;
     178           0 :         int i;
     179           0 :         char buf[FILENAME_MAX];
     180           0 :         char cwd[FILENAME_MAX];
     181             : 
     182           0 :         if (MT_getcwd(cwd, FILENAME_MAX) == NULL)
     183           0 :                 throw(MAL, "catalog.bbpLocation", RUNTIME_DIR_ERROR);
     184             : 
     185           0 :         b = COLnew(0, TYPE_str, getBBPsize(), TRANSIENT);
     186           0 :         if (b == 0)
     187           0 :                 throw(MAL, "catalog.bbpLocation", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     188             : 
     189           0 :         BBPlock();
     190           0 :         for (i = 1; i < getBBPsize(); i++)
     191           0 :                 if (i != b->batCacheid) {
     192           0 :                         if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     193           0 :                                 int len = snprintf(buf, FILENAME_MAX, "%s/bat/%s", cwd,
     194           0 :                                                                    BBP_physical(i));
     195           0 :                                 if (len == -1 || len >= FILENAME_MAX) {
     196           0 :                                         BBPunlock();
     197           0 :                                         BBPreclaim(b);
     198           0 :                                         throw(MAL, "catalog.bbpLocation",
     199             :                                                   SQLSTATE(HY013)
     200             :                                                   "Could not write bpp filename path is too large");
     201             :                                 }
     202           0 :                                 if (BUNappend(b, buf, false) != GDK_SUCCEED) {
     203           0 :                                         BBPunlock();
     204           0 :                                         BBPreclaim(b);
     205           0 :                                         throw(MAL, "catalog.bbpLocation",
     206             :                                                   SQLSTATE(HY013) MAL_MALLOC_FAIL);
     207             :                                 }
     208             :                         }
     209             :                 }
     210           0 :         BBPunlock();
     211           0 :         *ret = b->batCacheid;
     212           0 :         BBPkeepref(b);
     213           0 :         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           0 :         BAT *b;
     223           0 :         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",
     239             :                                                   SQLSTATE(HY013) MAL_MALLOC_FAIL);
     240             :                                 }
     241             :                         }
     242           0 :         BBPunlock();
     243           0 :         *ret = b->batCacheid;
     244           0 :         BBPkeepref(b);
     245           0 :         return MAL_SUCCEED;
     246             : }
     247             : 
     248             : /*
     249             :  * The BAT status is redundantly stored in CMDbat_info.
     250             :  */
     251             : static str
     252           0 : CMDbbpStatus(bat *ret)
     253             : {
     254           0 :         BAT *b;
     255           0 :         int i;
     256             : 
     257           0 :         b = COLnew(0, TYPE_str, getBBPsize(), TRANSIENT);
     258           0 :         if (b == 0)
     259           0 :                 throw(MAL, "catalog.bbpStatus", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     260             : 
     261           0 :         BBPlock();
     262           0 :         for (i = 1; i < getBBPsize(); i++)
     263           0 :                 if (i != b->batCacheid)
     264           0 :                         if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     265           0 :                                 char *loc = BBP_cache(i) ? "load" : "disk";
     266             : 
     267           0 :                                 if (BUNappend(b, loc, false) != GDK_SUCCEED) {
     268           0 :                                         BBPunlock();
     269           0 :                                         BBPreclaim(b);
     270           0 :                                         throw(MAL, "catalog.bbpStatus",
     271             :                                                   SQLSTATE(HY013) MAL_MALLOC_FAIL);
     272             :                                 }
     273             :                         }
     274           0 :         BBPunlock();
     275           0 :         *ret = b->batCacheid;
     276           0 :         BBPkeepref(b);
     277           0 :         return MAL_SUCCEED;
     278             : }
     279             : 
     280             : static str
     281           0 : CMDbbpKind(bat *ret)
     282             : {
     283           0 :         BAT *b;
     284           0 :         int i;
     285             : 
     286           0 :         b = COLnew(0, TYPE_str, getBBPsize(), TRANSIENT);
     287           0 :         if (b == 0)
     288           0 :                 throw(MAL, "catalog.bbpKind", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     289             : 
     290           0 :         BBPlock();
     291           0 :         for (i = 1; i < getBBPsize(); i++)
     292           0 :                 if (i != b->batCacheid && BBP_logical(i)
     293           0 :                         && (BBP_refs(i) || BBP_lrefs(i))) {
     294           0 :                         const char *mode;
     295             : 
     296           0 :                         if ((BBP_status(i) & BBPDELETED)
     297           0 :                                 || !(BBP_status(i) & BBPPERSISTENT))
     298             :                                 mode = "transient";
     299             :                         else
     300             :                                 mode = "persistent";
     301           0 :                         if (BUNappend(b, mode, false) != GDK_SUCCEED) {
     302           0 :                                 BBPunlock();
     303           0 :                                 BBPreclaim(b);
     304           0 :                                 throw(MAL, "catalog.bbpKind", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     305             :                         }
     306             :                 }
     307           0 :         BBPunlock();
     308           0 :         *ret = b->batCacheid;
     309           0 :         BBPkeepref(b);
     310           0 :         return MAL_SUCCEED;
     311             : }
     312             : 
     313             : static str
     314           0 : CMDbbpRefCount(bat *ret)
     315             : {
     316           0 :         BAT *b;
     317           0 :         int i;
     318             : 
     319           0 :         b = COLnew(0, TYPE_int, getBBPsize(), TRANSIENT);
     320           0 :         if (b == 0)
     321           0 :                 throw(MAL, "catalog.bbpRefCount", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     322             : 
     323           0 :         BBPlock();
     324           0 :         for (i = 1; i < getBBPsize(); i++)
     325           0 :                 if (i != b->batCacheid && BBP_logical(i)
     326           0 :                         && (BBP_refs(i) || BBP_lrefs(i))) {
     327           0 :                         int refs = BBP_refs(i);
     328             : 
     329           0 :                         if (BUNappend(b, &refs, false) != GDK_SUCCEED) {
     330           0 :                                 BBPunlock();
     331           0 :                                 BBPreclaim(b);
     332           0 :                                 throw(MAL, "catalog.bbpRefCount",
     333             :                                           SQLSTATE(HY013) MAL_MALLOC_FAIL);
     334             :                         }
     335             :                 }
     336           0 :         BBPunlock();
     337           0 :         *ret = b->batCacheid;
     338           0 :         BBPkeepref(b);
     339           0 :         return MAL_SUCCEED;
     340             : }
     341             : 
     342             : static str
     343           0 : CMDbbpLRefCount(bat *ret)
     344             : {
     345           0 :         BAT *b;
     346           0 :         int i;
     347             : 
     348           0 :         b = COLnew(0, TYPE_int, getBBPsize(), TRANSIENT);
     349           0 :         if (b == 0)
     350           0 :                 throw(MAL, "catalog.bbpLRefCount", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     351             : 
     352           0 :         BBPlock();
     353           0 :         for (i = 1; i < getBBPsize(); i++)
     354           0 :                 if (i != b->batCacheid && BBP_logical(i)
     355           0 :                         && (BBP_refs(i) || BBP_lrefs(i))) {
     356           0 :                         int refs = BBP_lrefs(i);
     357             : 
     358           0 :                         if (BUNappend(b, &refs, false) != GDK_SUCCEED) {
     359           0 :                                 BBPunlock();
     360           0 :                                 BBPreclaim(b);
     361           0 :                                 throw(MAL, "catalog.bbpLRefCount",
     362             :                                           SQLSTATE(HY013) MAL_MALLOC_FAIL);
     363             :                         }
     364             :                 }
     365           0 :         BBPunlock();
     366           0 :         *ret = b->batCacheid;
     367           0 :         BBPkeepref(b);
     368           0 :         return MAL_SUCCEED;
     369             : }
     370             : 
     371             : static str
     372           0 : CMDbbpgetIndex(int *res, bat *bid)
     373             : {
     374           0 :         *res = *bid;
     375           0 :         return MAL_SUCCEED;
     376             : }
     377             : 
     378             : static str
     379           7 : CMDgetBATrefcnt(int *res, bat *bid)
     380             : {
     381           7 :         BAT *b;
     382             : 
     383           7 :         if ((b = BATdescriptor(*bid)) == NULL) {
     384           0 :                 throw(MAL, "bbp.getRefCount", INTERNAL_BAT_ACCESS);
     385             :         }
     386           7 :         *res = BBP_refs(b->batCacheid);
     387           7 :         BBPunfix(b->batCacheid);
     388           7 :         return MAL_SUCCEED;
     389             : }
     390             : 
     391             : static str
     392          35 : CMDgetBATlrefcnt(int *res, bat *bid)
     393             : {
     394          35 :         BAT *b;
     395             : 
     396          35 :         if ((b = BATdescriptor(*bid)) == NULL) {
     397           0 :                 throw(MAL, "bbp.getLRefCount", INTERNAL_BAT_ACCESS);
     398             :         }
     399          35 :         *res = BBP_lrefs(b->batCacheid);
     400          35 :         BBPunfix(b->batCacheid);
     401          35 :         return MAL_SUCCEED;
     402             : }
     403             : 
     404             : static str
     405         114 : CMDbbp(bat *ID, bat *NS, bat *TT, bat *CNT, bat *REFCNT, bat *LREFCNT,
     406             :            bat *LOCATION, bat *HEAT, bat *DIRTY, bat *STATUS, bat *KIND)
     407             : {
     408         114 :         BAT *id, *ns, *tt, *cnt, *refcnt, *lrefcnt, *location, *heat, *dirty,
     409             :                         *status, *kind, *bn;
     410         114 :         bat i;
     411         114 :         char buf[FILENAME_MAX];
     412         114 :         bat sz = getBBPsize();
     413         114 :         str msg = MAL_SUCCEED;
     414             : 
     415         114 :         id = COLnew(0, TYPE_int, (BUN) sz, TRANSIENT);
     416         114 :         ns = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     417         114 :         tt = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     418         114 :         cnt = COLnew(0, TYPE_lng, (BUN) sz, TRANSIENT);
     419         114 :         refcnt = COLnew(0, TYPE_int, (BUN) sz, TRANSIENT);
     420         114 :         lrefcnt = COLnew(0, TYPE_int, (BUN) sz, TRANSIENT);
     421         114 :         location = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     422         114 :         heat = COLnew(0, TYPE_int, (BUN) sz, TRANSIENT);
     423         114 :         dirty = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     424         114 :         status = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     425         114 :         kind = COLnew(0, TYPE_str, (BUN) sz, TRANSIENT);
     426             : 
     427         114 :         if (!id ||!ns || !tt || !cnt || !refcnt || !lrefcnt || !location || !heat
     428         114 :                 || !dirty || !status || !kind) {
     429           0 :                 goto bailout;
     430             :         }
     431      351024 :         for (i = 1; i < sz; i++) {
     432      350910 :                 if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
     433      312539 :                         bn = BBP_desc(i);
     434      312539 :                         if (bn) {
     435      312539 :                                 lng l = BATcount(bn);
     436      312539 :                                 int heat_ = 0, len;
     437      312539 :                                 char *loc = BBP_cache(i) ? "load" : "disk";
     438      312539 :                                 char *mode = "persistent";
     439      312539 :                                 int refs = BBP_refs(i);
     440      312539 :                                 int lrefs = BBP_lrefs(i);
     441             : 
     442      312539 :                                 if ((BBP_status(i) & BBPDELETED)
     443      312538 :                                         || !(BBP_status(i) & BBPPERSISTENT))
     444             :                                         mode = "transient";
     445      312539 :                                 len = snprintf(buf, FILENAME_MAX, "%s", BBP_physical(i));
     446      312539 :                                 if (len == -1 || len >= FILENAME_MAX) {
     447           0 :                                         msg = createException(MAL, "catalog.bbp",
     448             :                                                                                   SQLSTATE(HY013)
     449             :                                                                                   "Could not bpp filename path is too large");
     450           0 :                                         goto bailout;
     451             :                                 }
     452      625078 :                                 if (BUNappend(id, &i, false) != GDK_SUCCEED ||
     453      625078 :                                         BUNappend(ns, BBP_logical(i), false) != GDK_SUCCEED ||
     454      312539 :                                         BUNappend(tt, BATatoms[bn->ttype].name,
     455             :                                                           false) != GDK_SUCCEED
     456      312539 :                                         || BUNappend(cnt, &l, false) != GDK_SUCCEED
     457      312539 :                                         || BUNappend(refcnt, &refs, false) != GDK_SUCCEED
     458      312539 :                                         || BUNappend(lrefcnt, &lrefs, false) != GDK_SUCCEED
     459      312539 :                                         || BUNappend(location, buf, false) != GDK_SUCCEED
     460      312539 :                                         || BUNappend(heat, &heat_, false) != GDK_SUCCEED
     461      312539 :                                         || BUNappend(dirty,
     462      312539 :                                                                  BBP_cache(i) ? BATdirty(bn) ? "dirty" :
     463       42229 :                                                                  DELTAdirty(bn) ? "diffs" : "clean"
     464        2564 :                                                                  : (BBP_status(i) & BBPSWAPPED) ? "diffs" :
     465             :                                                                  "clean", false) != GDK_SUCCEED
     466      312539 :                                         || BUNappend(status, loc, false) != GDK_SUCCEED
     467      312539 :                                         || BUNappend(kind, mode, false) != GDK_SUCCEED) {
     468           0 :                                         msg = createException(MAL, "catalog.bbp",
     469             :                                                                                   SQLSTATE(HY013) MAL_MALLOC_FAIL);
     470           0 :                                         goto bailout;
     471             :                                 }
     472             :                         }
     473             :                 }
     474             :         }
     475         114 :         *ID = id->batCacheid;
     476         114 :         BBPkeepref(id);
     477         114 :         *NS = ns->batCacheid;
     478         114 :         BBPkeepref(ns);
     479         114 :         *TT = tt->batCacheid;
     480         114 :         BBPkeepref(tt);
     481         114 :         *CNT = cnt->batCacheid;
     482         114 :         BBPkeepref(cnt);
     483         114 :         *REFCNT = refcnt->batCacheid;
     484         114 :         BBPkeepref(refcnt);
     485         114 :         *LREFCNT = lrefcnt->batCacheid;
     486         114 :         BBPkeepref(lrefcnt);
     487         114 :         *LOCATION = location->batCacheid;
     488         114 :         BBPkeepref(location);
     489         114 :         *HEAT = heat->batCacheid;
     490         114 :         BBPkeepref(heat);
     491         114 :         *DIRTY = dirty->batCacheid;
     492         114 :         BBPkeepref(dirty);
     493         114 :         *STATUS = status->batCacheid;
     494         114 :         BBPkeepref(status);
     495         114 :         *KIND = kind->batCacheid;
     496         114 :         BBPkeepref(kind);
     497         114 :         return MAL_SUCCEED;
     498             : 
     499           0 :   bailout:
     500           0 :         BBPreclaim(id);
     501           0 :         BBPreclaim(ns);
     502           0 :         BBPreclaim(tt);
     503           0 :         BBPreclaim(cnt);
     504           0 :         BBPreclaim(refcnt);
     505           0 :         BBPreclaim(lrefcnt);
     506           0 :         BBPreclaim(location);
     507           0 :         BBPreclaim(heat);
     508           0 :         BBPreclaim(dirty);
     509           0 :         BBPreclaim(status);
     510           0 :         BBPreclaim(kind);
     511             :         return msg;
     512             : }
     513             : 
     514             : static str
     515           0 : CMDsetName(str *rname, const bat *bid, str *name)
     516             : {
     517           0 :         BAT *b;
     518           0 :         if ((b = BATdescriptor(*bid)) == NULL) {
     519           0 :                 throw(MAL, "bbp.setName", INTERNAL_BAT_ACCESS);
     520             :         }
     521           0 :         if (BBPrename(b, *name) != 0) {
     522           0 :                 BBPunfix(b->batCacheid);
     523           0 :                 throw(MAL, "bbp.setName", GDK_EXCEPTION);
     524             :         }
     525           0 :         *rname = GDKstrdup(*name);
     526           0 :         BBPunfix(b->batCacheid);
     527           0 :         if (*rname == NULL)
     528           0 :                 throw(MAL, "bbp.setName", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     529             :         return MAL_SUCCEED;
     530             : }
     531             : 
     532             : #include "mel.h"
     533             : mel_func bbp_init_funcs[] = {
     534             :  pattern("bbp", "bind", CMDbbpbind, false, "Locate the BAT using its logical name", args(1,2, batargany("",2),arg("name",str))),
     535             :  command("bbp", "getIndex", CMDbbpgetIndex, false, "Retrieve the index in the BBP", args(1,2, arg("",int),batargany("b",2))),
     536             :  command("bbp", "getNames", CMDbbpNames, false, "Map BAT into its bbp name", args(1,1, batarg("",str))),
     537             :  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))),
     538             :  command("bbp", "getName", CMDbbpName, false, "Map a BAT into its internal name", args(1,2, arg("",str),batargany("b",1))),
     539             :  command("bbp", "setName", CMDsetName, false, "Rename a BAT", args(1,3, arg("",str),batargany("b",1),arg("n",str))),
     540             :  command("bbp", "getCount", CMDbbpCount, false, "Create a BAT with the cardinalities of all known BATs", args(1,1, batarg("",lng))),
     541             :  command("bbp", "getRefCount", CMDbbpRefCount, false, "Create a BAT with the (hard) reference counts", args(1,1, batarg("",int))),
     542             :  command("bbp", "getLRefCount", CMDbbpLRefCount, false, "Create a BAT with the logical reference counts", args(1,1, batarg("",int))),
     543             :  command("bbp", "getLocation", CMDbbpLocation, false, "Create a BAT with their disk locations", args(1,1, batarg("",str))),
     544             :  command("bbp", "getDirty", CMDbbpDirty, false, "Create a BAT with the dirty/ diffs/clean status", args(1,1, batarg("",str))),
     545             :  command("bbp", "getStatus", CMDbbpStatus, false, "Create a BAT with the disk/load status", args(1,1, batarg("",str))),
     546             :  command("bbp", "getKind", CMDbbpKind, false, "Create a BAT with the persistency status", args(1,1, batarg("",str))),
     547             :  command("bbp", "getRefCount", CMDgetBATrefcnt, false, "Utility for debugging MAL interpreter", args(1,2, arg("",int),batargany("b",1))),
     548             :  command("bbp", "getLRefCount", CMDgetBATlrefcnt, false, "Utility for debugging MAL interpreter", args(1,2, arg("",int),batargany("b",1))),
     549             :  command("bbp", "getDiskSpace", CMDbbpDiskSpace, false, "Estimate the amount of disk space occupied by dbpath", args(1,1, arg("",lng))),
     550             :  command("bbp", "getPageSize", CMDgetPageSize, false, "Obtain the memory page size", args(1,1, arg("",int))),
     551             :  { .imp=NULL }
     552             : };
     553             : #include "mal_import.h"
     554             : #ifdef _MSC_VER
     555             : #undef read
     556             : #pragma section(".CRT$XCU",read)
     557             : #endif
     558         329 : LIB_STARTUP_FUNC(init_bbp_mal)
     559         329 : { mal_module("bbp", NULL, bbp_init_funcs); }

Generated by: LCOV version 1.14