Remove zap dependency from boltdb (#334)

* Remove zap dependency from boltdb

* Avoid pulling in testing in main binary
This commit is contained in:
Egon Elbre 2018-09-10 12:52:53 +03:00 committed by JT Olio
parent 2eb660d4b7
commit 00ac266bda
5 changed files with 16 additions and 30 deletions

View File

@ -16,6 +16,7 @@ import (
proto "storj.io/storj/protos/overlay"
"storj.io/storj/storage"
"storj.io/storj/storage/boltdb"
"storj.io/storj/storage/storelogger"
)
const (
@ -52,21 +53,20 @@ type RoutingOptions struct {
// NewRoutingTable returns a newly configured instance of a RoutingTable
func NewRoutingTable(localNode *proto.Node, options *RoutingOptions) (*RoutingTable, error) {
logger := zap.L()
kdb, err := boltdb.NewClient(logger, options.kpath, KademliaBucket)
kdb, err := boltdb.New(options.kpath, KademliaBucket)
if err != nil {
return nil, RoutingErr.New("could not create kadBucketDB: %s", err)
}
ndb, err := boltdb.NewClient(logger, options.npath, NodeBucket)
ndb, err := boltdb.New(options.npath, NodeBucket)
if err != nil {
return nil, RoutingErr.New("could not create nodeBucketDB: %s", err)
}
rp := make(map[string][]*proto.Node)
rt := &RoutingTable{
self: localNode,
kadBucketDB: kdb,
nodeBucketDB: ndb,
kadBucketDB: storelogger.New(zap.L(), kdb),
nodeBucketDB: storelogger.New(zap.L(), ndb),
transport: &defaultTransport,
mutex: &sync.Mutex{},
replacementCache: rp,

View File

@ -18,6 +18,7 @@ import (
"storj.io/storj/storage"
"storj.io/storj/storage/boltdb"
"storj.io/storj/storage/redis"
"storj.io/storj/storage/storelogger"
)
const (
@ -52,13 +53,13 @@ func NewRedisOverlayCache(address, password string, db int, DHT dht.DHT) (*Cache
// NewBoltOverlayCache returns a pointer to a new Cache instance with an initialized connection to a Bolt db.
func NewBoltOverlayCache(dbPath string, DHT dht.DHT) (*Cache, error) {
bc, err := boltdb.NewClient(zap.L(), dbPath, OverlayBucket)
bc, err := boltdb.New(dbPath, OverlayBucket)
if err != nil {
return nil, err
}
return &Cache{
DB: bc,
DB: storelogger.New(zap.L(), bc),
DHT: DHT,
}, nil
}

View File

@ -14,7 +14,7 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/zeebo/errs"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"storj.io/storj/internal/test"
"storj.io/storj/pkg/dht"
@ -24,6 +24,7 @@ import (
"storj.io/storj/storage/boltdb"
"storj.io/storj/storage/redis"
"storj.io/storj/storage/redis/redisserver"
"storj.io/storj/storage/storelogger"
)
var (
@ -240,7 +241,7 @@ func boltTestClient(t *testing.T, data test.KvStore) (_ storage.KeyValueStore, _
boltPath, err := filepath.Abs("test_bolt.db")
assert.NoError(t, err)
client, err := boltdb.NewClient(zap.L(), boltPath, "testBoltdb")
client, err := boltdb.New(boltPath, "testBoltdb")
assert.NoError(t, err)
cleanup := func() {
@ -252,7 +253,7 @@ func boltTestClient(t *testing.T, data test.KvStore) (_ storage.KeyValueStore, _
populateStorage(t, client, data)
}
return client, cleanup
return storelogger.New(zaptest.NewLogger(t), client), cleanup
}
func populateStorage(t *testing.T, client storage.KeyValueStore, data test.KvStore) {

View File

@ -12,6 +12,7 @@ import (
"storj.io/storj/pkg/utils"
proto "storj.io/storj/protos/pointerdb"
"storj.io/storj/storage/boltdb"
"storj.io/storj/storage/storelogger"
)
const (
@ -37,13 +38,14 @@ func (c Config) Run(ctx context.Context, server *provider.Provider) error {
return Error.New("unsupported db scheme: %s", dburl.Scheme)
}
bdb, err := boltdb.NewClient(zap.L(), dburl.Path, PointerBucket)
bdb, err := boltdb.New(dburl.Path, PointerBucket)
if err != nil {
return err
}
defer func() { _ = bdb.Close() }()
proto.RegisterPointerDBServer(server.GRPC(), NewServer(bdb, zap.L(), c))
bdblogged := storelogger.New(zap.L(), bdb)
proto.RegisterPointerDBServer(server.GRPC(), NewServer(bdblogged, zap.L(), c))
return server.Run(ctx)
}

View File

@ -1,18 +0,0 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package boltdb
import (
"go.uber.org/zap"
"storj.io/storj/storage"
"storj.io/storj/storage/storelogger"
)
// NewClient instantiates a new BoltDB client given db file path, and a bucket name
func NewClient(log *zap.Logger, path, bucket string) (storage.KeyValueStore, error) {
client, err := New(path, bucket)
db := storelogger.New(log, client)
return db, err
}