Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate interfaces for blockstore and GCBlockstore
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
whyrusleeping committed Jul 3, 2015
1 parent 0149e9e commit 8f716ae
Showing 5 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion blocks/blockstore/blockstore.go
Original file line number Diff line number Diff line change
@@ -33,12 +33,16 @@ type Blockstore interface {
Put(*blocks.Block) error

AllKeysChan(ctx context.Context) (<-chan key.Key, error)
}

type GCBlockstore interface {
Blockstore

Lock() func()
RLock() func()
}

func NewBlockstore(d ds.ThreadSafeDatastore) Blockstore {
func NewBlockstore(d ds.ThreadSafeDatastore) *blockstore {
dd := dsns.Wrap(d, BlockPrefix)
return &blockstore{
datastore: dd,
6 changes: 3 additions & 3 deletions blocks/blockstore/write_cache.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
)

// WriteCached returns a blockstore that caches up to |size| unique writes (bs.Put).
func WriteCached(bs Blockstore, size int) (Blockstore, error) {
func WriteCached(bs Blockstore, size int) (*writecache, error) {
c, err := lru.New(size)
if err != nil {
return nil, err
@@ -50,9 +50,9 @@ func (w *writecache) AllKeysChan(ctx context.Context) (<-chan key.Key, error) {
}

func (w *writecache) Lock() func() {
return w.blockstore.Lock()
return w.blockstore.(GCBlockstore).Lock()

This comment has been minimized.

Copy link
@whyrusleeping

whyrusleeping Jul 3, 2015

Author Member

YOLO

This comment has been minimized.

Copy link
@jbenet

jbenet Jul 3, 2015

Member

}

func (w *writecache) RLock() func() {
return w.blockstore.RLock()
return w.blockstore.(GCBlockstore).RLock()
}
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ type IpfsNode struct {

// Services
Peerstore peer.Peerstore // storage for other Peer instances
Blockstore bstore.Blockstore // the block store (lower level)
Blockstore bstore.GCBlockstore // the block store (lower level)
Blocks *bserv.BlockService // the block service, get/add blocks.
DAG merkledag.DAGService // the merkle dag service, get/add objects.
Resolver *path.Resolver // the path resolution system
2 changes: 1 addition & 1 deletion pin/gc/gc.go
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ func (gcs *GCSet) AddDag(ds dag.DAGService, root key.Key) error {
//
// The routine then iterates over every block in the blockstore and
// deletes any block that is not found in the marked set.
func GC(ctx context.Context, bs bstore.Blockstore, pn pin.Pinner) (<-chan key.Key, error) {
func GC(ctx context.Context, bs bstore.GCBlockstore, pn pin.Pinner) (<-chan key.Key, error) {
unlock := bs.Lock()
defer unlock()

4 changes: 2 additions & 2 deletions unixfs/mod/dagmodifier_test.go
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ func getMockDagServ(t testing.TB) (mdag.DAGService, pin.Pinner) {
return dserv, pin.NewPinner(tsds, dserv)
}

func getMockDagServAndBstore(t testing.TB) (mdag.DAGService, blockstore.Blockstore, pin.Pinner) {
func getMockDagServAndBstore(t testing.TB) (mdag.DAGService, blockstore.GCBlockstore, pin.Pinner) {
dstore := ds.NewMapDatastore()
tsds := sync.MutexWrap(dstore)
bstore := blockstore.NewBlockstore(tsds)
@@ -470,7 +470,7 @@ func TestSparseWrite(t *testing.T) {
}
}

func basicGC(t *testing.T, bs blockstore.Blockstore, pins pin.Pinner) {
func basicGC(t *testing.T, bs blockstore.GCBlockstore, pins pin.Pinner) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel() // in case error occurs during operation
out, err := gc.GC(ctx, bs, pins)

0 comments on commit 8f716ae

Please sign in to comment.