-
Notifications
You must be signed in to change notification settings - Fork 12
/
mvcc_dbssn2.c
101 lines (77 loc) · 2.17 KB
/
mvcc_dbssn2.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
94
95
96
97
98
99
100
101
// scan txn steps
// implement transactions
#include "mvcc.h"
DbStatus mvcc_scan2(Txn *txn) {
DbAddr next, addr, finalAddr;
DbAddr *docSlot;
Ver *ver;
bool result = true;
DbMap *docMap = NULL;
Handle *docHndl = NULL;
uint64_t verNo = 0;
ObjId docId;
ObjId objId;
Frame *frame;
Doc *doc;
int idx;
// evaluate writes by this txn
// to finalize eta(tn)
if ((next.bits = txn->wrtFirst->bits))
finalAddr.bits = txn->wrtFrame->bits;
else {
next.bits = txn->wrtFrame->bits;
finalAddr.bits = 0;
}
while ((addr.bits = next.bits))
{
frame = getObj(txnMap, addr);
for (idx = 0; idx < addr.nslot; idx++)
{
objId.bits = frame->slots[idx];
switch (objId.step) {
default:
continue;
case TxnMap:
if (docHndl)
releaseHandle(docHndl);
if(docHndl = fetchIdSlot(hndlMap, objId)) {
docMap = MapAddr(docHndl);
continue;
}
return DB_ERROR_badtxnstep;
case TxnVer:
verNo = objId.verNo;
continue;
case TxnWrt:
docId.bits = objId.bits;
docSlot = fetchIdSlot(docMap, docId);
doc = getObj(docMap, *docSlot);
break;
}
// is this a read of our own new version?
if (doc->op == OpWrt)
if (doc->txnId.bits == txn->txnId.bits)
continue;
// is there another committed version
// after our version? Was there another
// version committed after our read?
if (verNo + 1 < doc->verNo)
ver = mvcc_getVersion(docMap, doc, verNo + 1);
else
continue;
// is our read version overwritten yet? check
// if it was committed with higher timestamp
waitNonZero64(ver->commit->lowHi + 1);
if (timestampCmp(txn->commit, ver->commit, 0, 0) > 0)
timestampCAX(txn->sstamp, ver->sstamp, 1, 'r', 'b');
continue;
}
if (!(next.bits = frame->prev.bits)) {
next.bits = finalAddr.bits;
finalAddr.bits = 0;
}
}
if (docHndl)
releaseHandle(docHndl);
return DB_OK;
}