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 - 2019 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 | TRNglobal_sync(bit *ret) |
37 | { |
38 | *ret = BBPsync(getBBPsize(), NULL) == GDK_SUCCEED; |
39 | return MAL_SUCCEED; |
40 | } |
41 | |
42 | str |
43 | TRNglobal_abort(bit *ret) |
44 | { |
45 | TMabort(); |
46 | *ret = TRUE; |
47 | return MAL_SUCCEED; |
48 | } |
49 | |
50 | str |
51 | TRNglobal_commit(bit *ret) |
52 | { |
53 | *ret = TMcommit()?FALSE:TRUE; |
54 | return MAL_SUCCEED; |
55 | } |
56 | str |
57 | TRNsubcommit(bit *ret, bat *bid) |
58 | { |
59 | BAT *b; |
60 | b= BATdescriptor(*bid); |
61 | if( b == NULL) |
62 | throw(MAL, "transaction.subcommit" , SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); |
63 | *ret = TMsubcommit(b) == GDK_SUCCEED; |
64 | BBPunfix(b->batCacheid); |
65 | return MAL_SUCCEED; |
66 | } |
67 | |
68 | str |
69 | 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 | for (i = p->retc; i < p->argc; i++) { |
78 | bid = getArgReference_bat(stk, p, i); |
79 | if ((b = BATdescriptor(*bid)) == NULL) { |
80 | throw(MAL, "transaction.commit" , SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); |
81 | } |
82 | |
83 | BATfakeCommit(b); |
84 | BBPunfix(b->batCacheid); |
85 | } |
86 | return MAL_SUCCEED; |
87 | } |
88 | |
89 | str |
90 | 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 | for (i = p->retc; i < p->argc; i++) { |
99 | bid = getArgReference_bat(stk, p, i); |
100 | if ((b = BATdescriptor(*bid)) == NULL) { |
101 | throw(MAL, "transaction.abort" , SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); |
102 | } |
103 | BATundo(b); |
104 | BBPunfix(b->batCacheid); |
105 | } |
106 | return MAL_SUCCEED; |
107 | } |
108 | |
109 | str |
110 | 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 | for (i = p->retc; i < p->argc; i++) { |
119 | bid = getArgReference_bat(stk, p, i); |
120 | if ((b = BATdescriptor(*bid)) == NULL) { |
121 | throw(MAL, "transaction.commit" , SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); |
122 | } |
123 | BATcommit(b); |
124 | BBPunfix(b->batCacheid); |
125 | } |
126 | return MAL_SUCCEED; |
127 | } |
128 | |