LCOV - code coverage report
Current view: top level - monetdb5/modules/mal - transaction.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 38 0.0 %
Date: 2021-01-13 20:07:21 Functions: 0 7 0.0 %

          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             :  * @a M.L. Kersten, P. Boncz
      11             :  * @+ Transaction management
      12             :  * In the philosophy of Monet, transaction management overhead should only
      13             :  * be paid when necessary. Transaction management is for this purpose
      14             :  * implemented as a module.
      15             :  * This code base is largely absolute and should be re-considered when
      16             :  * serious OLTP is being supported.
      17             :  * Note, however, the SQL front-end obeys transaction semantics.
      18             :  *
      19             :  */
      20             : #include "monetdb_config.h"
      21             : #include "gdk.h"
      22             : #include "mal.h"
      23             : #include "mal_interpreter.h"
      24             : #include "bat5.h"
      25             : 
      26             : mal_export str TRNglobal_sync(bit *ret);
      27             : mal_export str TRNglobal_abort(bit *ret);
      28             : mal_export str TRNglobal_commit(bit *ret);
      29             : mal_export str TRNtrans_clean(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
      30             : mal_export str TRNtrans_abort(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
      31             : mal_export str TRNtrans_commit(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
      32             : mal_export str TRNsubcommit(bit *ret, bat *bid);
      33             : 
      34             : #include "mal_exception.h"
      35             : str
      36           0 : TRNglobal_sync(bit *ret)
      37             : {
      38           0 :         *ret = BBPsync(getBBPsize(), NULL) == GDK_SUCCEED;
      39           0 :         return MAL_SUCCEED;
      40             : }
      41             : 
      42             : str
      43           0 : TRNglobal_abort(bit *ret)
      44             : {
      45           0 :         TMabort();
      46           0 :         *ret = TRUE;
      47           0 :         return MAL_SUCCEED;
      48             : }
      49             : 
      50             : str
      51           0 : TRNglobal_commit(bit *ret)
      52             : {
      53           0 :         *ret = TMcommit()?FALSE:TRUE;
      54           0 :         return MAL_SUCCEED;
      55             : }
      56             : str
      57           0 : TRNsubcommit(bit *ret, bat *bid)
      58             : {
      59             :         BAT *b;
      60           0 :         b= BATdescriptor(*bid);
      61           0 :         if( b == NULL)
      62           0 :                 throw(MAL, "transaction.subcommit", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      63           0 :         *ret = TMsubcommit(b) == GDK_SUCCEED;
      64           0 :         BBPunfix(b->batCacheid);
      65           0 :         return MAL_SUCCEED;
      66             : }
      67             : 
      68             : str
      69           0 : TRNtrans_clean(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
      70             : {
      71             :         int i;
      72             :         bat *bid;
      73             :         BAT *b;
      74             : 
      75             :         (void) cntxt;
      76             :         (void) mb;
      77           0 :         for (i = p->retc; i < p->argc; i++) {
      78           0 :                 bid = getArgReference_bat(stk, p, i);
      79           0 :                 if ((b = BATdescriptor(*bid)) == NULL) {
      80           0 :                         throw(MAL, "transaction.commit", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      81             :                 }
      82             : 
      83           0 :                 BATfakeCommit(b);
      84           0 :                 BBPunfix(b->batCacheid);
      85             :         }
      86             :         return MAL_SUCCEED;
      87             : }
      88             : 
      89             : str
      90           0 : TRNtrans_abort(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
      91             : {
      92             :         int i;
      93             :         bat *bid;
      94             :         BAT *b;
      95             : 
      96             :         (void) cntxt;
      97             :         (void) mb;
      98           0 :         for (i = p->retc; i < p->argc; i++) {
      99           0 :                 bid = getArgReference_bat(stk, p, i);
     100           0 :                 if ((b = BATdescriptor(*bid)) == NULL) {
     101           0 :                         throw(MAL, "transaction.abort", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
     102             :                 }
     103           0 :                 BATundo(b);
     104           0 :                 BBPunfix(b->batCacheid);
     105             :         }
     106             :         return MAL_SUCCEED;
     107             : }
     108             : 
     109             : str
     110           0 : TRNtrans_commit(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
     111             : {
     112             :         int i;
     113             :         bat *bid;
     114             :         BAT *b;
     115             : 
     116             :         (void) cntxt;
     117             :         (void) mb;
     118           0 :         for (i = p->retc; i < p->argc; i++) {
     119           0 :                 bid = getArgReference_bat(stk, p, i);
     120           0 :                 if ((b = BATdescriptor(*bid)) == NULL) {
     121           0 :                         throw(MAL, "transaction.commit", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
     122             :                 }
     123           0 :                 BATcommit(b);
     124           0 :                 BBPunfix(b->batCacheid);
     125             :         }
     126             :         return MAL_SUCCEED;
     127             : }
     128             : 
     129             : #if 0
     130             : 
     131             : #include "mel.h"
     132             : mel_func transaction_init_funcs[] = {
     133             :  command("transaction", "sync", TRNglobal_sync, false, "Save all persistent BATs", args(1,1, arg("",bit))),
     134             :  command("transaction", "commit", TRNglobal_commit, false, "Global commit on all BATs", args(1,1, arg("",bit))),
     135             :  command("transaction", "abort", TRNglobal_abort, false, "Global abort on all BATs", args(1,1, arg("",bit))),
     136             :  command("transaction", "subcommit", TRNsubcommit, false, "commit only a set of BATnames, passed in the tail\n(to which you must have exclusive access!)", args(1,2, arg("",bit),batarg("b",str))),
     137             :  pattern("transaction", "commit", TRNtrans_commit, false, "Commit changes in certain BATs.", args(0,1, varargany("c",0))),
     138             :  pattern("transaction", "abort", TRNtrans_abort, false, "Abort changes in certain BATs.", args(0,1, varargany("c",0))),
     139             :  pattern("transaction", "clean", TRNtrans_clean, false, "Declare a BAT clean without flushing to disk.", args(0,1, varargany("c",0))),
     140             :  { .imp=NULL }
     141             : };
     142             : #include "mal_import.h"
     143             : #ifdef _MSC_VER
     144             : #undef read
     145             : #pragma section(".CRT$XCU",read)
     146             : #endif
     147             : LIB_STARTUP_FUNC(init_transaction_mal)
     148             : { mal_module("transaction", NULL, transaction_init_funcs); }
     149             : 
     150             : #endif

Generated by: LCOV version 1.14