@cryptotaxi247 / kubo / commits / 16690d4af

race fix: pinner loads with a threadsafe datastore

All the datastores used by pinners and so on should be mutex wrapped. One issue with changing all of them from ds.Datastore -> ds.ThreadSafeDatastore is that we wrap the incoming ds.ThreadSafeDatastore with other datastores, which do not implement the interface. Re-wrapping again causes double locking. (which may be ok..., but...) any ideas?

Juan Batiz-Benet committed Jan 11, 2015 at 21:31 UTC 16690d4af2d8eb420b049d634e205c8ed3efb647
4 files changed +9 -9
importer/importer_test.go
+2 -2
@@ -137,8 +137,8 @@ type dagservAndPinner struct {
137 }
138
139 func getDagservAndPinner(t *testing.T) dagservAndPinner {
140 - db := ds.NewMapDatastore()
141 - bs := bstore.NewBlockstore(dssync.MutexWrap(db))
140 + db := dssync.MutexWrap(ds.NewMapDatastore())
141 + bs := bstore.NewBlockstore(db)
142 blockserv, err := bserv.New(bs, offline.Exchange(bs))
143 if err != nil {
144 t.Fatal(err)
merkledag/merkledag_test.go
+2 -2
@@ -28,8 +28,8 @@ type dagservAndPinner struct {
28 }
29
30 func getDagservAndPinner(t *testing.T) dagservAndPinner {
31 - db := ds.NewMapDatastore()
32 - bs := bstore.NewBlockstore(dssync.MutexWrap(db))
31 + db := dssync.MutexWrap(ds.NewMapDatastore())
32 + bs := bstore.NewBlockstore(db)
33 blockserv, err := bserv.New(bs, offline.Exchange(bs))
34 if err != nil {
35 t.Fatal(err)
pin/pin.go
+3 -3
@@ -53,11 +53,11 @@ type pinner struct {
53 directPin set.BlockSet
54 indirPin *indirectPin
55 dserv mdag.DAGService
56 - dstore ds.Datastore
56 + dstore ds.ThreadSafeDatastore
57 }
58
59 // NewPinner creates a new pinner using the given datastore as a backend
60 -func NewPinner(dstore ds.Datastore, serv mdag.DAGService) Pinner {
60 +func NewPinner(dstore ds.ThreadSafeDatastore, serv mdag.DAGService) Pinner {
61
62 // Load set from given datastore...
63 rcds := nsds.Wrap(dstore, recursePinDatastoreKey)
@@ -176,7 +176,7 @@ func (p *pinner) IsPinned(key util.Key) bool {
176 }
177
178 // LoadPinner loads a pinner and its keysets from the given datastore
179 -func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) {
179 +func LoadPinner(d ds.ThreadSafeDatastore, dserv mdag.DAGService) (Pinner, error) {
180 p := new(pinner)
181
182 { // load recursive set
pin/pin_test.go
+2 -2
@@ -21,8 +21,8 @@ func randNode() (*mdag.Node, util.Key) {
21 }
22
23 func TestPinnerBasic(t *testing.T) {
24 - dstore := ds.NewMapDatastore()
25 - bstore := blockstore.NewBlockstore(dssync.MutexWrap(dstore))
24 + dstore := dssync.MutexWrap(ds.NewMapDatastore())
25 + bstore := blockstore.NewBlockstore(dstore)
26 bserv, err := bs.New(bstore, offline.Exchange(bstore))
27 if err != nil {
28 t.Fatal(err)