📄 transaction.mx
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f transaction@a M.L. Kersten, P. Boncz@+ Transaction managementIn the philosophy of Monet, transaction management overhead should onlybe paid when necessary. Transaction management is for this purpose implemented as a module.This code base is largely absolute and should be re-considered whenserious OLTP is being supported.Note, however, the SQL front-end obeys transaction semantics.@malmodule transaction;command sync() :bitaddress TRNglobal_synccomment "Save all persistent BATs";command commit() :bitaddress TRNglobal_commitcomment "Global commit on all BATs";command abort() :bitaddress TRNglobal_abortcomment "Global abort on all BATs";command subcommit(b:bat[:any_1,:str]):bitaddress TRNsubcommitcomment "commit only a set of BATnames, passed in the tail (to which you must have exclusive access!)";pattern commit(c:any...) address TRNtrans_commitcomment "Commit changes in certain BATs.";pattern abort(c:any...) address TRNtrans_abortcomment "Abort changes in certain BATs.";pattern clean(c:any...) address TRNtrans_cleancomment "Declare a BAT clean without flushing to disk.";command prev(b:bat[:any_1,:any_2]):bat[:any_1,:any_2]address TRNtrans_prevcomment "The previous stae of this BAT";command alpha(b:bat[:any_1,:any_2]) :bat[:any_1,:any_2] address TRNtrans_alphacomment "List insertions since last commit.";command delta(b:bat[:any_1,:any_2]) :bat[:any_1,:any_2] address TRNtrans_deltacomment "List deletions since last commit.";@{@+ Implementation Code @c#include "mal_config.h"#include "gdk.h"#include "mal.h"#include "mal_interpreter.h"#include "bat5.h"#ifdef WIN32#ifndef LIBTRANSACTION#define transaction_export extern __declspec(dllimport)#else#define transaction_export extern __declspec(dllexport)#endif#else#define transaction_export extern#endiftransaction_export str TRNglobal_sync(int *ret);transaction_export str TRNglobal_abort(int *ret);transaction_export str TRNglobal_commit(int *ret);transaction_export str TRNsub_commit(int *ret, int *bid);transaction_export str TRNtrans_clean(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);transaction_export str TRNtrans_abort(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);transaction_export str TRNtrans_commit(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);transaction_export str TRNsubcommit(int *ret, int *bid);transaction_export str TRNtrans_prev(int *ret, int *bid);transaction_export str TRNtrans_alpha(int *ret, int *bid);transaction_export str TRNtrans_delta(int *ret, int *bid);@@include prelude.mx@- WrappersThe remainder contains the Monet 5 wrapper code to make this all work@c#include "mal_exception.h"strTRNglobal_sync(int *ret){ *ret = BBPsync(BBPsize,NULL)?FALSE:TRUE; return MAL_SUCCEED;}strTRNglobal_abort(int *ret){ *ret = TMabort()?FALSE:TRUE; return MAL_SUCCEED;}strTRNglobal_commit(int *ret){ *ret = TMcommit()?FALSE:TRUE; return MAL_SUCCEED;}strTRNsubcommit(int *ret, int *bid){ BAT *b; b= BATdescriptor(*bid); if( b == NULL) throw(MAL, "transaction.subcommit","BAT with commit list missing"); *ret = TMsubcommit(b)?FALSE:TRUE; BBPunfix(b->batCacheid); return MAL_SUCCEED;}strTRNtrans_clean(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ int i, *bid; BAT *b; (void) mb; for (i = p->retc; i < p->argc; i++) { bid = (int *) getArgReference(stk, p, i); if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "transaction.commit", "Cannot access descriptor"); } if (b) BATfakeCommit(b); else throw(MAL, "trans_commit", "BAT not accessible"); BBPunfix(b->batCacheid); } return MAL_SUCCEED;}strTRNtrans_abort(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ int i, *bid; BAT *b; (void) mb; for (i = p->retc; i < p->argc; i++) { bid = (int *) getArgReference(stk, p, i); if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "transaction.abort", "Cannot access descriptor"); } if (b) BATundo(b); else throw(MAL, "transaction.abort", "BAT not accessible"); BBPunfix(b->batCacheid); } return MAL_SUCCEED;}strTRNtrans_commit(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ int i, *bid; BAT *b; (void) mb; for (i = p->retc; i < p->argc; i++) { bid = (int *) getArgReference(stk, p, i); if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "transaction.commit", "Cannot access descriptor"); } if (b) BATcommit(b); else throw(MAL, "transaction.commit", "BAT not accessible"); BBPunfix(b->batCacheid); } return MAL_SUCCEED;}strTRNtrans_prev(int *ret, int *bid){ BAT *b,*bn= NULL; b= BATdescriptor(*bid); if (b == NULL) throw(MAL, "transaction.prev", "Cannot access descriptor"); bn = BATprev(b); BBPkeepref(*ret = bn->batCacheid); BBPunfix(b->batCacheid); return MAL_SUCCEED;}strTRNtrans_alpha(int *ret, int *bid){ return BKCgetAlpha(ret, bid);}strTRNtrans_delta(int *ret, int *bid){ return BKCgetDelta(ret, bid);}@}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -