-
Notifications
You must be signed in to change notification settings - Fork 12
/
mvcc_dbssn4.c
93 lines (70 loc) · 2.12 KB
/
mvcc_dbssn4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// scan txn steps
// implement transactions
#include "mvcc.h"
DbStatus mvcc_scan4(Txn *txn) {
DbAddr *slot, addr, next, finalAddr;
Ver *ver, *prevVer;
bool result = true;
DbMap *docMap = NULL;
Handle *docHndl = NULL;
uint64_t verNo;
ObjId objId;
Frame *frame;
Doc *doc;
int idx;
// finally, commit wrt set version
if ((next.bits = txn->wrtFirst->bits))
finalAddr.bits = txn->wrtFrame->bits;
else {
next.bits = txn->wrtFrame->bits;
finalAddr.bits = 0;
}
// pre-commit
// Scan transaction reads
while ((addr.bits = next.bits)) {
frame = getObj(txnMap, addr);
for (idx = 0; idx < addr.nslot; idx++) {
objId.bits = frame->slots[idx];
switch (objId.step) {
case TxnRaw:
continue;
case TxnMap:
if (docHndl) releaseHandle(docHndl);
docHndl = fetchIdSlot(hndlMap, objId);
docMap = MapAddr(docHndl);
continue;
default:
continue;
case TxnWrt:
verNo = frame->slots[idx];
slot = fetchIdSlot(docMap, objId);
lockLatch(slot->latch);
doc = getObj(docMap, *slot);
if (doc->verNo == verNo) break;
if (doc->op & OpCommit) break;
unlockLatch(slot->latch);
continue;
}
// find previous version
prevVer = (Ver *)(doc->dbDoc->base + doc->commitVer);
ver = (Ver *)(doc->dbDoc->base + doc->pendingVer);
if (doc->commitVer) timestampInstall(prevVer->sstamp, txn->commit, 'd', 'd');
timestampInstall(ver->commit, txn->commit, 'd', 'd');
timestampInstall(ver->pstamp, txn->commit, 'd', 'd');
ver->sstamp->lowHi[0] = 0;
ver->sstamp->lowHi[1] = ~0ULL;
doc->txnId.bits = 0;
doc->op = TxnDone;
unlockLatch(slot->latch);
continue;
}
if (!(next.bits = frame->prev.bits)) {
next.bits = finalAddr.bits;
finalAddr.bits = 0;
}
returnFreeFrame(txnMap, addr);
}
if (docHndl)
releaseHandle(docHndl);
return DB_OK;
}