@cryptotaxi247 / kubo / commits / 27f34b431

renamed {R,}Lock -> {Pin,GC}Lock

License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>

Juan Batiz-Benet committed Jul 9, 2015 at 05:57 UTC 27f34b4311e2a53e3e52c3a6dbc8b29def4539b9
7 files changed +27 -33
blocks/blockstore/blockstore.go
+12 -4
@@ -39,8 +39,16 @@ type Blockstore interface {
39 type GCBlockstore interface {
40 Blockstore
41
42 - Lock() func()
43 - RLock() func()
42 + // GCLock locks the blockstore for garbage collection. No operations
43 + // that expect to finish with a pin should ocurr simultaneously.
44 + // Reading during GC is safe, and requires no lock.
45 + GCLock() func()
46 +
47 + // PinLock locks the blockstore for sequences of puts expected to finish
48 + // with a pin (before GC). Multiple put->pin sequences can write through
49 + // at the same time, but no GC should not happen simulatenously.
50 + // Reading during Pinning is safe, and requires no lock.
51 + PinLock() func()
52 }
53
54 func NewBlockstore(d ds.ThreadSafeDatastore) *blockstore {
@@ -183,12 +191,12 @@ func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan key.Key, error) {
191 return output, nil
192 }
193
186 -func (bs *blockstore) Lock() func() {
194 +func (bs *blockstore) GCLock() func() {
195 bs.lk.Lock()
196 return bs.lk.Unlock
197 }
198
191 -func (bs *blockstore) RLock() func() {
199 +func (bs *blockstore) PinLock() func() {
200 bs.lk.RLock()
201 return bs.lk.RUnlock
202 }
blocks/blockstore/write_cache.go
+4 -4
@@ -59,10 +59,10 @@ func (w *writecache) AllKeysChan(ctx context.Context) (<-chan key.Key, error) {
59 return w.blockstore.AllKeysChan(ctx)
60 }
61
62 -func (w *writecache) Lock() func() {
63 - return w.blockstore.(GCBlockstore).Lock()
62 +func (w *writecache) GCLock() func() {
63 + return w.blockstore.(GCBlockstore).GCLock()
64 }
65
66 -func (w *writecache) RLock() func() {
67 - return w.blockstore.(GCBlockstore).RLock()
66 +func (w *writecache) PinLock() func() {
67 + return w.blockstore.(GCBlockstore).PinLock()
68 }
core/commands/pin.go
+1 -1
@@ -50,7 +50,7 @@ on disk.
50 return
51 }
52
53 - unlock := n.Blockstore.RLock()
53 + unlock := n.Blockstore.PinLock()
54 defer unlock()
55
56 // set recursive flag
core/coreunix/add.go
+3 -3
@@ -23,7 +23,7 @@ var log = logging.Logger("coreunix")
23 // Add builds a merkledag from the a reader, pinning all objects to the local
24 // datastore. Returns a key representing the root node.
25 func Add(n *core.IpfsNode, r io.Reader) (string, error) {
26 - unlock := n.Blockstore.RLock()
26 + unlock := n.Blockstore.PinLock()
27 defer unlock()
28
29 // TODO more attractive function signature importer.BuildDagFromReader
@@ -46,7 +46,7 @@ func Add(n *core.IpfsNode, r io.Reader) (string, error) {
46
47 // AddR recursively adds files in |path|.
48 func AddR(n *core.IpfsNode, root string) (key string, err error) {
49 - unlock := n.Blockstore.RLock()
49 + unlock := n.Blockstore.PinLock()
50 defer unlock()
51
52 stat, err := os.Lstat(root)
@@ -86,7 +86,7 @@ func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, *merkle
86 file := files.NewReaderFile(filename, filename, ioutil.NopCloser(r), nil)
87 dir := files.NewSliceFile("", "", []files.File{file})
88
89 - unlock := n.Blockstore.RLock()
89 + unlock := n.Blockstore.PinLock()
90 defer unlock()
91 dagnode, err := addDir(n, dir)
92 if err != nil {
merkledag/merkledag_test.go
+5 -13
@@ -300,15 +300,13 @@ func TestCantGet(t *testing.T) {
300
301 func TestFetchGraph(t *testing.T) {
302 var dservs []DAGService
303 - bsis := bstest.Mocks(t, 2)
303 + bsis := bstest.Mocks(2)
304 for _, bsi := range bsis {
305 dservs = append(dservs, NewDAGService(bsi))
306 }
307
308 read := io.LimitReader(u.NewTimeSeededRand(), 1024*32)
309 - spl := &chunk.SizeSplitter{512}
310 -
311 - root, err := imp.BuildDagFromReader(read, dservs[0], spl, nil)
309 + root, err := imp.BuildDagFromReader(dservs[0], chunk.NewSizeSplitter(read, 512), nil)
310 if err != nil {
311 t.Fatal(err)
312 }
@@ -319,10 +317,7 @@ func TestFetchGraph(t *testing.T) {
317 }
318
319 // create an offline dagstore and ensure all blocks were fetched
322 - bs, err := bserv.New(bsis[1].Blockstore, offline.Exchange(bsis[1].Blockstore))
323 - if err != nil {
324 - t.Fatal(err)
325 - }
320 + bs := bserv.New(bsis[1].Blockstore, offline.Exchange(bsis[1].Blockstore))
321
322 offline_ds := NewDAGService(bs)
323 ks := key.NewKeySet()
@@ -334,14 +329,11 @@ func TestFetchGraph(t *testing.T) {
329 }
330
331 func TestEnumerateChildren(t *testing.T) {
337 - bsi := bstest.Mocks(t, 1)
332 + bsi := bstest.Mocks(1)
333 ds := NewDAGService(bsi[0])
334
340 - spl := &chunk.SizeSplitter{512}
341 -
335 read := io.LimitReader(u.NewTimeSeededRand(), 1024*1024)
343 -
344 - root, err := imp.BuildDagFromReader(read, ds, spl, nil)
336 + root, err := imp.BuildDagFromReader(ds, chunk.NewSizeSplitter(read, 512), nil)
337 if err != nil {
338 t.Fatal(err)
339 }
pin/pin_test.go
+1 -4
@@ -195,10 +195,7 @@ func TestDuplicateSemantics(t *testing.T) {
195 func TestFlush(t *testing.T) {
196 dstore := dssync.MutexWrap(ds.NewMapDatastore())
197 bstore := blockstore.NewBlockstore(dstore)
198 - bserv, err := bs.New(bstore, offline.Exchange(bstore))
199 - if err != nil {
200 - t.Fatal(err)
201 - }
198 + bserv := bs.New(bstore, offline.Exchange(bstore))
199
200 dserv := mdag.NewDAGService(bserv)
201 p := NewPinner(dstore, dserv)
pin/set_test.go
+1 -4
@@ -27,10 +27,7 @@ func copyMap(m map[key.Key]uint16) map[key.Key]uint64 {
27 func TestMultisetRoundtrip(t *testing.T) {
28 dstore := dssync.MutexWrap(datastore.NewMapDatastore())
29 bstore := blockstore.NewBlockstore(dstore)
30 - bserv, err := blockservice.New(bstore, offline.Exchange(bstore))
31 - if err != nil {
32 - t.Fatal(err)
33 - }
30 + bserv := blockservice.New(bstore, offline.Exchange(bstore))
31 dag := merkledag.NewDAGService(bserv)
32
33 fn := func(m map[key.Key]uint16) bool {