-
Notifications
You must be signed in to change notification settings - Fork 2
/
fai.diff
117 lines (105 loc) · 2.82 KB
/
fai.diff
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
diff --git a/tid/tid.go b/tid/tid.go
index c884924..0aa0674 100644
--- a/tid/tid.go
+++ b/tid/tid.go
@@ -1,11 +1,17 @@
package tid
import (
+ "sync/atomic"
"github.com/goose-lang/std"
"github.com/mit-pdos/gokv/grove_ffi"
"github.com/mit-pdos/vmvcc/config"
)
+func GenTIDWithFAI(gtidref *uint64) uint64 {
+ tid := atomic.AddUint64(gtidref, 1)
+ return tid
+}
+
func GenTID(sid uint64) uint64 {
var tid uint64
diff --git a/txnsite/txnsite.go b/txnsite/txnsite.go
index 91e325d..9c74479 100644
--- a/txnsite/txnsite.go
+++ b/txnsite/txnsite.go
@@ -1,6 +1,7 @@
package txnsite
import (
+ "sync"
"github.com/mit-pdos/vmvcc/tid"
"github.com/mit-pdos/vmvcc/cfmutex"
"github.com/tchajed/goose/machine"
@@ -14,13 +15,17 @@ type TxnSite struct {
// Active transaction IDs.
padding [4]uint64
// TODO: should only need 3, change it once performance is tested.
+ gtidref *uint64
+ gtidlk *sync.Mutex
}
-func MkTxnSite(sid uint64) *TxnSite {
+func MkTxnSite(sid uint64, gtidref *uint64, gtidlk *sync.Mutex) *TxnSite {
site := new(TxnSite)
site.latch = new(cfmutex.CFMutex)
site.tids = make([]uint64, 0, 8)
site.sid = sid
+ site.gtidref = gtidref
+ site.gtidlk = gtidlk
return site
}
@@ -30,7 +35,12 @@ func (site *TxnSite) Activate() uint64 {
site.latch.Lock()
var t uint64
- t = tid.GenTID(site.sid)
+ // t = tid.GenTID(site.sid)
+ t = tid.GenTIDWithFAI(site.gtidref)
+ // site.gtidlk.Lock()
+ // t = *site.gtidref
+ // *site.gtidref++
+ // site.gtidlk.Unlock()
// Assume TID never overflow.
primitive.Assume(t < 18446744073709551615)
@@ -76,7 +86,13 @@ func (site *TxnSite) GetSafeTS() uint64 {
site.latch.Lock()
var tidnew uint64
- tidnew = tid.GenTID(site.sid)
+ // tidnew = tid.GenTID(site.sid)
+ tidnew = tid.GenTIDWithFAI(site.gtidref)
+ // site.gtidlk.Lock()
+ // tidnew = *site.gtidref
+ // *site.gtidref++
+ // site.gtidlk.Unlock()
+
primitive.Assume(tidnew < 18446744073709551615)
var tidmin uint64 = tidnew
diff --git a/vmvcc/db.go b/vmvcc/db.go
index 8da24d6..d2ad962 100644
--- a/vmvcc/db.go
+++ b/vmvcc/db.go
@@ -1,6 +1,7 @@
package vmvcc
import (
+ "sync"
"github.com/mit-pdos/vmvcc/config"
"github.com/mit-pdos/vmvcc/index"
"github.com/mit-pdos/vmvcc/wrbuf"
@@ -15,6 +16,7 @@ type DB struct {
latch *cfmutex.CFMutex
// Next site ID to assign.
sid uint64
+ gtid uint64
// All transaction sites.
sites []*txnsite.TxnSite
// Index.
@@ -28,11 +30,13 @@ func MkDB() *DB {
db := &DB { proph : proph }
db.latch = new(cfmutex.CFMutex)
db.sites = make([]*txnsite.TxnSite, config.N_TXN_SITES)
+ db.gtid = 0
// Call this once to establish invariants.
+ gtidlk := new(sync.Mutex)
tid.GenTID(0)
for i := uint64(0); i < config.N_TXN_SITES; i++ {
- site := txnsite.MkTxnSite(i)
+ site := txnsite.MkTxnSite(i, &db.gtid, gtidlk)
db.sites[i] = site
}
db.idx = index.MkIndex()