@cryptotaxi247 / kubo / commits / 45d4b1a8b

fixup datastore interfaces

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jul 16, 2015 at 11:32 UTC 45d4b1a8bcdb99910cfaae12edb9f3228a5c8417
8 files changed +26 -40
Godeps/Godeps.json
+4
@@ -166,7 +166,11 @@
166 },
167 {
168 "ImportPath": "github.com/jbenet/go-datastore",
169 +<<<<<<< HEAD
170 "Rev": "c835c30f206c1e97172e428f052e225adab9abde"
171 +=======
172 + "Rev": "47af23f2ad09237ccc09c586c118048e2b39b358"
173 +>>>>>>> fixup datastore interfaces
174 },
175 {
176 "ImportPath": "github.com/jbenet/go-detect-race",
blocks/blockstore/blockstore.go
+2 -4
@@ -25,7 +25,7 @@ var ValueTypeMismatch = errors.New("The retrieved value is not a Block")
25
26 var ErrNotFound = errors.New("blockstore: block not found")
27
28 -// Blockstore wraps a ThreadSafeDatastore
28 +// Blockstore wraps a Datastore
29 type Blockstore interface {
30 DeleteBlock(key.Key) error
31 Has(key.Key) (bool, error)
@@ -51,7 +51,7 @@ type GCBlockstore interface {
51 PinLock() func()
52 }
53
54 -func NewBlockstore(d ds.Datastore) *blockstore {
54 +func NewBlockstore(d ds.Batching) *blockstore {
55 dd := dsns.Wrap(d, BlockPrefix)
56 return &blockstore{
57 datastore: dd,
@@ -60,8 +60,6 @@ func NewBlockstore(d ds.Datastore) *blockstore {
60
61 type blockstore struct {
62 datastore ds.Batching
63 - // cant be ThreadSafeDatastore cause namespace.Datastore doesnt support it.
64 - // we do check it on `NewBlockstore` though.
63
64 lk sync.RWMutex
65 }
core/core.go
+2 -3
@@ -17,7 +17,6 @@ import (
17 "time"
18
19 b58 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
20 - ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
20 ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
21 goprocess "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
22 mamask "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/multiaddr-filter"
@@ -570,14 +569,14 @@ func startListening(ctx context.Context, host p2phost.Host, cfg *config.Config)
569 return nil
570 }
571
573 -func constructDHTRouting(ctx context.Context, host p2phost.Host, dstore ds.Datastore) (routing.IpfsRouting, error) {
572 +func constructDHTRouting(ctx context.Context, host p2phost.Host, dstore repo.Datastore) (routing.IpfsRouting, error) {
573 dhtRouting := dht.NewDHT(ctx, host, dstore)
574 dhtRouting.Validator[IpnsValidatorTag] = namesys.IpnsRecordValidator
575 dhtRouting.Selector[IpnsValidatorTag] = namesys.IpnsSelectorFunc
576 return dhtRouting, nil
577 }
578
580 -type RoutingOption func(context.Context, p2phost.Host, ds.Datastore) (routing.IpfsRouting, error)
579 +type RoutingOption func(context.Context, p2phost.Host, repo.Datastore) (routing.IpfsRouting, error)
580
581 type DiscoveryOption func(p2phost.Host) (discovery.Service, error)
582
core/corerouting/core.go
+3 -2
@@ -8,6 +8,7 @@ import (
8 core "github.com/ipfs/go-ipfs/core"
9 "github.com/ipfs/go-ipfs/p2p/host"
10 "github.com/ipfs/go-ipfs/p2p/peer"
11 + repo "github.com/ipfs/go-ipfs/repo"
12 routing "github.com/ipfs/go-ipfs/routing"
13 supernode "github.com/ipfs/go-ipfs/routing/supernode"
14 gcproxy "github.com/ipfs/go-ipfs/routing/supernode/proxy"
@@ -28,7 +29,7 @@ var (
29 // routing records to the provided datastore. Only routing records are store in
30 // the datastore.
31 func SupernodeServer(recordSource ds.ThreadSafeDatastore) core.RoutingOption {
31 - return func(ctx context.Context, ph host.Host, dstore ds.Datastore) (routing.IpfsRouting, error) {
32 + return func(ctx context.Context, ph host.Host, dstore repo.Datastore) (routing.IpfsRouting, error) {
33 server, err := supernode.NewServer(recordSource, ph.Peerstore(), ph.ID())
34 if err != nil {
35 return nil, err
@@ -44,7 +45,7 @@ func SupernodeServer(recordSource ds.ThreadSafeDatastore) core.RoutingOption {
45
46 // TODO doc
47 func SupernodeClient(remotes ...peer.PeerInfo) core.RoutingOption {
47 - return func(ctx context.Context, ph host.Host, dstore ds.Datastore) (routing.IpfsRouting, error) {
48 + return func(ctx context.Context, ph host.Host, dstore repo.Datastore) (routing.IpfsRouting, error) {
49 if len(remotes) < 1 {
50 return nil, errServersMissing
51 }
repo/fsrepo/defaultds.go
+8 -27
@@ -8,7 +8,7 @@ import (
8 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/flatfs"
9 levelds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/leveldb"
10 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/measure"
11 - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/mount"
11 + mount "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/syncmount"
12 ldbopts "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt"
13 repo "github.com/ipfs/go-ipfs/repo"
14 config "github.com/ipfs/go-ipfs/repo/config"
@@ -20,22 +20,11 @@ const (
20 flatfsDirectory = "blocks"
21 )
22
23 -type defaultDatastore struct {
24 - repo.Datastore
25 -
26 - // tracked separately for use in Close; do not use directly.
27 - leveldbDS repo.Datastore
28 - metricsBlocks repo.Datastore
29 - metricsLevelDB repo.Datastore
30 -}
31 -
23 func openDefaultDatastore(r *FSRepo) (repo.Datastore, error) {
33 - d := &defaultDatastore{}
34 -
24 leveldbPath := path.Join(r.path, leveldbDirectory)
36 - var err error
25 +
26 // save leveldb reference so it can be neatly closed afterward
38 - d.leveldbDS, err = levelds.NewDatastore(leveldbPath, &levelds.Options{
27 + leveldbDS, err := levelds.NewDatastore(leveldbPath, &levelds.Options{
28 Compression: ldbopts.NoCompression,
29 })
30 if err != nil {
@@ -65,26 +54,20 @@ func openDefaultDatastore(r *FSRepo) (repo.Datastore, error) {
54 id = fmt.Sprintf("uninitialized_%p", r)
55 }
56 prefix := "fsrepo." + id + ".datastore."
68 - d.metricsBlocks = measure.New(prefix+"blocks", blocksDS)
69 - d.metricsLevelDB = measure.New(prefix+"leveldb", d.leveldbDS)
57 + metricsBlocks := measure.New(prefix+"blocks", blocksDS)
58 + metricsLevelDB := measure.New(prefix+"leveldb", leveldbDS)
59 mountDS := mount.New([]mount.Mount{
60 {
61 Prefix: ds.NewKey("/blocks"),
73 - Datastore: d.metricsBlocks,
62 + Datastore: metricsBlocks,
63 },
64 {
65 Prefix: ds.NewKey("/"),
77 - Datastore: d.metricsLevelDB,
66 + Datastore: metricsLevelDB,
67 },
68 })
80 - // Make sure it's ok to claim the virtual datastore from mount as
81 - // threadsafe. There's no clean way to make mount itself provide
82 - // this information without copy-pasting the code into two
83 - // variants. This is the same dilemma as the `[].byte` attempt at
84 - // introducing const types to Go.
85 - d.Datastore = mountDS
69
87 - return d, nil
70 + return mountDS, nil
71 }
72
73 func initDefaultDatastore(repoPath string, conf *config.Config) error {
@@ -101,5 +84,3 @@ func initDefaultDatastore(repoPath string, conf *config.Config) error {
84 }
85 return nil
86 }
104 -
105 -var _ repo.Datastore = (*defaultDatastore)(nil)
repo/repo.go
+1 -2
@@ -5,7 +5,6 @@ import (
5 "io"
6
7 ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
8 -
8 config "github.com/ipfs/go-ipfs/repo/config"
9 )
10
@@ -32,6 +31,6 @@ type Repo interface {
31 // Datastore is the interface required from a datastore to be
32 // acceptable to FSRepo.
33 type Datastore interface {
35 - ds.Datastore // should be threadsafe, just be careful
34 + ds.Batching // should be threadsafe, just be careful
35 io.Closer
36 }
routing/none/none_client.go
+2 -2
@@ -3,11 +3,11 @@ package nilrouting
3 import (
4 "errors"
5
6 - ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
6 context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
7 key "github.com/ipfs/go-ipfs/blocks/key"
8 p2phost "github.com/ipfs/go-ipfs/p2p/host"
9 peer "github.com/ipfs/go-ipfs/p2p/peer"
10 + repo "github.com/ipfs/go-ipfs/repo"
11 routing "github.com/ipfs/go-ipfs/routing"
12 logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
13 )
@@ -47,7 +47,7 @@ func (c *nilclient) Bootstrap(_ context.Context) error {
47 return nil
48 }
49
50 -func ConstructNilRouting(_ context.Context, _ p2phost.Host, _ ds.Datastore) (routing.IpfsRouting, error) {
50 +func ConstructNilRouting(_ context.Context, _ p2phost.Host, _ repo.Datastore) (routing.IpfsRouting, error) {
51 return &nilclient{}, nil
52 }
53
thirdparty/s3-datastore/datastore.go
+4
@@ -71,4 +71,8 @@ func (ds *S3Datastore) Close() error {
71 return nil
72 }
73
74 +func (ds *S3Datastore) Batch() (datastore.Batch, error) {
75 + return datastore.NewBasicBatch(ds), nil
76 +}
77 +
78 func (ds *S3Datastore) IsThreadSafe() {}