Adds a logger to RoutingTable (#922)

* adds delete functions and tests for cache

* adds logger to routing table struct and passes it through to logger

* add loggers
This commit is contained in:
Dylan Lott 2018-12-21 17:48:53 -07:00 committed by GitHub
parent 05c1644fec
commit 2f6835a3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 9 deletions

View File

@ -166,7 +166,7 @@ func (node *Node) initOverlay(planet *Planet) error {
return err
}
routing, err := kademlia.NewRoutingTable(node.Info, teststore.New(), teststore.New())
routing, err := kademlia.NewRoutingTable(node.Log.Named("routing"), node.Info, teststore.New(), teststore.New())
if err != nil {
return err
}
@ -180,7 +180,7 @@ func (node *Node) initOverlay(planet *Planet) error {
node.StatDB = node.Database.StatDB()
node.Overlay = overlay.NewCache(teststore.New(), node.StatDB)
node.Discovery = discovery.NewDiscovery(node.Overlay, node.Kademlia, node.StatDB)
node.Discovery = discovery.NewDiscovery(node.Log.Named("discovery"), node.Overlay, node.Kademlia, node.StatDB)
return nil
}

View File

@ -51,7 +51,7 @@ func (c Config) Run(ctx context.Context, server *provider.Provider) (err error)
if !ok {
return Error.New("unable to get master db instance")
}
discovery := NewDiscovery(ol, kad, stat.StatDB())
discovery := NewDiscovery(zap.L().Named("discovery"), ol, kad, stat.StatDB())
zap.L().Debug("Starting discovery")
@ -62,15 +62,15 @@ func (c Config) Run(ctx context.Context, server *provider.Provider) (err error)
for {
select {
case <-ticker.C:
zap.L().Debug("Kicking off refresh")
discovery.log.Debug("Kicking off refresh")
err := discovery.Refresh(ctx)
if err != nil {
zap.L().Error("Error with cache refresh: ", zap.Error(err))
discovery.log.Error("Error with cache refresh: ", zap.Error(err))
}
err = discovery.Discovery(ctx)
if err != nil {
zap.L().Error("Error with cache discovery: ", zap.Error(err))
discovery.log.Error("Error with cache discovery: ", zap.Error(err))
}
case <-ctx.Done():
return

View File

@ -8,6 +8,7 @@ import (
"crypto/rand"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/storj/pkg/kademlia"
"storj.io/storj/pkg/overlay"
@ -22,14 +23,16 @@ var (
// Discovery struct loads on cache, kad, and statdb
type Discovery struct {
log *zap.Logger
cache *overlay.Cache
kad *kademlia.Kademlia
statdb statdb.DB
}
// NewDiscovery Returns a new Discovery instance with cache, kad, and statdb loaded on
func NewDiscovery(ol *overlay.Cache, kad *kademlia.Kademlia, stat statdb.DB) *Discovery {
func NewDiscovery(log *zap.Logger, ol *overlay.Cache, kad *kademlia.Kademlia, stat statdb.DB) *Discovery {
return &Discovery{
log: log,
cache: ol,
kad: kad,
statdb: stat,

View File

@ -81,7 +81,7 @@ func NewKademlia(log *zap.Logger, id storj.NodeID, nodeType pb.NodeType, bootstr
}
kdb, ndb := dbs[0], dbs[1]
rt, err := NewRoutingTable(self, kdb, ndb)
rt, err := NewRoutingTable(log, self, kdb, ndb)
if err != nil {
return nil, BootstrapErr.Wrap(err)
}

View File

@ -9,6 +9,7 @@ import (
"time"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/storj"
@ -31,6 +32,7 @@ type bucketID [len(storj.NodeID{})]byte
// RoutingTable implements the RoutingTable interface
type RoutingTable struct {
log *zap.Logger
self pb.Node
kadBucketDB storage.KeyValueStore
nodeBucketDB storage.KeyValueStore
@ -44,8 +46,9 @@ type RoutingTable struct {
}
// NewRoutingTable returns a newly configured instance of a RoutingTable
func NewRoutingTable(localNode pb.Node, kdb, ndb storage.KeyValueStore) (*RoutingTable, error) {
func NewRoutingTable(logger *zap.Logger, localNode pb.Node, kdb, ndb storage.KeyValueStore) (*RoutingTable, error) {
rt := &RoutingTable{
log: logger,
self: localNode,
kadBucketDB: kdb,
nodeBucketDB: ndb,