Skip to content

Commit

Permalink
Merge pull request #795 from ipfs/deps/update2
Browse files Browse the repository at this point in the history
Deps: update and related fixes
  • Loading branch information
hsanjuan committed May 26, 2019
2 parents da6739a + a1d95f5 commit 501ee7b
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 193 deletions.
1 change: 0 additions & 1 deletion cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ func (c *Cluster) Shutdown(ctx context.Context) error {
}

c.cancel()
c.host.Close() // Shutdown all network services
c.wg.Wait()

// Cleanly close the datastore
Expand Down
27 changes: 19 additions & 8 deletions cmd/ipfs-cluster-service/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func daemon(c *cli.Context) error {
logger.Info("Initializing. For verbose output run with \"-l debug\". Please wait...")

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

bootstraps := parseBootstraps(c.StringSlice("bootstrap"))

Expand Down Expand Up @@ -81,7 +80,10 @@ func daemon(c *cli.Context) error {
cfgs.clusterCfg.LeaveOnShutdown = true
}

cluster, err := createCluster(ctx, c, ident, cfgs, raftStaging)
host, pubsub, dht, err := ipfscluster.NewClusterHost(ctx, ident, cfgs.clusterCfg)
checkErr("creating libp2p host", err)

cluster, err := createCluster(ctx, c, host, pubsub, dht, ident, cfgs, raftStaging)
checkErr("starting cluster", err)

// noop if no bootstraps
Expand All @@ -91,7 +93,7 @@ func daemon(c *cli.Context) error {
// will realize).
go bootstrap(ctx, cluster, bootstraps)

return handleSignals(ctx, cluster)
return handleSignals(ctx, cancel, cluster, host, dht)
}

// createCluster creates all the necessary things to produce the cluster
Expand All @@ -100,15 +102,15 @@ func daemon(c *cli.Context) error {
func createCluster(
ctx context.Context,
c *cli.Context,
host host.Host,
pubsub *pubsub.PubSub,
dht *dht.IpfsDHT,
ident *config.Identity,
cfgs *cfgs,
raftStaging bool,
) (*ipfscluster.Cluster, error) {

host, pubsub, dht, err := ipfscluster.NewClusterHost(ctx, ident, cfgs.clusterCfg)
checkErr("creating libP2P Host", err)

ctx, err = tag.New(ctx, tag.Upsert(observations.HostKey, host.ID().Pretty()))
ctx, err := tag.New(ctx, tag.Upsert(observations.HostKey, host.ID().Pretty()))
checkErr("tag context with host id", err)

peerstoreMgr := pstoremgr.New(host, cfgs.clusterCfg.GetPeerstorePath())
Expand Down Expand Up @@ -207,7 +209,13 @@ func bootstrap(ctx context.Context, cluster *ipfscluster.Cluster, bootstraps []m
}
}

func handleSignals(ctx context.Context, cluster *ipfscluster.Cluster) error {
func handleSignals(
ctx context.Context,
cancel context.CancelFunc,
cluster *ipfscluster.Cluster,
host host.Host,
dht *dht.IpfsDHT,
) error {
signalChan := make(chan os.Signal, 20)
signal.Notify(
signalChan,
Expand All @@ -223,6 +231,9 @@ func handleSignals(ctx context.Context, cluster *ipfscluster.Cluster) error {
ctrlcCount++
handleCtrlC(ctx, cluster, ctrlcCount)
case <-cluster.Done():
cancel()
dht.Close()
host.Close()
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/raft/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (cfg *Config) Default() error {

// Set up logging
cfg.RaftConfig.LogOutput = ioutil.Discard
cfg.RaftConfig.Logger = raftStdLogger // see logging.go
cfg.RaftConfig.Logger = &hcLogToLogger{}
return nil
}

Expand Down
100 changes: 99 additions & 1 deletion consensus/raft/logging.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package raft

import (
"fmt"
"io"
"log"
"strings"
"time"

hclog "github.com/hashicorp/go-hclog"
logging "github.com/ipfs/go-log"
)

Expand All @@ -15,6 +18,102 @@ const (
err
)

var raftLogger = logging.Logger("raftlib")

// this implements github.com/hashicorp/go-hclog
type hcLogToLogger struct {
extraArgs []interface{}
name string
}

func (log *hcLogToLogger) formatArgs(args []interface{}) string {
result := ""
args = append(args, log.extraArgs)
for i := 0; i < len(args); i = i + 2 {
key, ok := args[i].(string)
if !ok {
continue
}
val := args[i+1]
result += fmt.Sprintf(" %s=%s.", key, val)
}
return result
}

func (log *hcLogToLogger) format(msg string, args []interface{}) string {
argstr := log.formatArgs(args)
if len(argstr) > 0 {
argstr = ". Args: " + argstr
}
name := log.name
if len(name) > 0 {
name += ": "
}
return name + msg + argstr
}

func (log *hcLogToLogger) Trace(msg string, args ...interface{}) {
raftLogger.Debug(log.format(msg, args))
}

func (log *hcLogToLogger) Debug(msg string, args ...interface{}) {
raftLogger.Debug(log.format(msg, args))
}

func (log *hcLogToLogger) Info(msg string, args ...interface{}) {
raftLogger.Info(log.format(msg, args))
}

func (log *hcLogToLogger) Warn(msg string, args ...interface{}) {
raftLogger.Warning(log.format(msg, args))
}

func (log *hcLogToLogger) Error(msg string, args ...interface{}) {
raftLogger.Error(log.format(msg, args))
}

func (log *hcLogToLogger) IsTrace() bool {
return true
}

func (log *hcLogToLogger) IsDebug() bool {
return true
}

func (log *hcLogToLogger) IsInfo() bool {
return true
}

func (log *hcLogToLogger) IsWarn() bool {
return true
}

func (log *hcLogToLogger) IsError() bool {
return true
}

func (log *hcLogToLogger) With(args ...interface{}) hclog.Logger {
return &hcLogToLogger{extraArgs: args}
}

func (log *hcLogToLogger) Named(name string) hclog.Logger {
return &hcLogToLogger{name: log.name + ": " + name}
}

func (log *hcLogToLogger) ResetNamed(name string) hclog.Logger {
return &hcLogToLogger{name: name}
}

func (log *hcLogToLogger) SetLevel(level hclog.Level) {}

func (log *hcLogToLogger) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger {
return nil
}

func (log *hcLogToLogger) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer {
return nil
}

const repeatPoolSize = 10
const repeatReset = time.Minute

Expand All @@ -26,7 +125,6 @@ type logForwarder struct {
}

var raftStdLogger = log.New(&logForwarder{}, "", 0)
var raftLogger = logging.Logger("raftlib")

// Write forwards to our go-log logger.
// According to https://golang.org/pkg/log/#Logger.Output
Expand Down
52 changes: 22 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ module github.com/ipfs/ipfs-cluster
require (
contrib.go.opencensus.io/exporter/jaeger v0.1.0
contrib.go.opencensus.io/exporter/prometheus v0.1.0
github.com/ajstarks/svgo v0.0.0-20181006003313-6ce6a3bcf6cd // indirect
github.com/blang/semver v3.5.1+incompatible
github.com/boltdb/bolt v1.3.1 // indirect
github.com/dustin/go-humanize v1.0.0
github.com/fogleman/gg v1.3.0 // indirect
github.com/gogo/protobuf v1.2.1
github.com/golang/protobuf v1.3.1
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.2
github.com/hashicorp/raft v1.0.1
github.com/hashicorp/go-hclog v0.9.1
github.com/hashicorp/go-immutable-radix v1.1.0 // indirect
github.com/hashicorp/raft v1.1.0
github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea
github.com/hsanjuan/go-libp2p-gostream v0.0.32
github.com/hsanjuan/go-libp2p-http v0.0.3
github.com/hsanjuan/ipfs-lite v0.0.4
github.com/hsanjuan/go-libp2p-gostream v0.0.34
github.com/hsanjuan/go-libp2p-http v0.0.5
github.com/hsanjuan/ipfs-lite v0.0.8
github.com/ipfs/go-block-format v0.0.2
github.com/ipfs/go-cid v0.0.2
github.com/ipfs/go-datastore v0.0.5
github.com/ipfs/go-ds-badger v0.0.3
github.com/ipfs/go-ds-crdt v0.0.10
github.com/ipfs/go-ds-crdt v0.0.14
github.com/ipfs/go-fs-lock v0.0.1
github.com/ipfs/go-ipfs-api v0.0.1
github.com/ipfs/go-ipfs-blockstore v0.0.1
Expand All @@ -33,47 +33,39 @@ require (
github.com/ipfs/go-ipld-cbor v0.0.2
github.com/ipfs/go-ipld-format v0.0.2
github.com/ipfs/go-log v0.0.1
github.com/ipfs/go-merkledag v0.0.3
github.com/ipfs/go-mfs v0.0.7
github.com/ipfs/go-path v0.0.4
github.com/ipfs/go-unixfs v0.0.6
github.com/jung-kurt/gofpdf v1.4.1 // indirect
github.com/ipfs/go-merkledag v0.0.6
github.com/ipfs/go-mfs v0.0.11
github.com/ipfs/go-path v0.0.7
github.com/ipfs/go-unixfs v0.0.8
github.com/kelseyhightower/envconfig v1.3.0
github.com/lanzafame/go-libp2p-ocgorpc v0.0.3
github.com/libp2p/go-libp2p v0.0.25
github.com/libp2p/go-libp2p-connmgr v0.0.5
github.com/lanzafame/go-libp2p-ocgorpc v0.0.4
github.com/libp2p/go-libp2p v0.0.30
github.com/libp2p/go-libp2p-connmgr v0.0.6
github.com/libp2p/go-libp2p-consensus v0.0.1
github.com/libp2p/go-libp2p-crypto v0.0.2
github.com/libp2p/go-libp2p-gorpc v0.0.3
github.com/libp2p/go-libp2p-crypto v0.1.0
github.com/libp2p/go-libp2p-gorpc v0.0.5
github.com/libp2p/go-libp2p-host v0.0.3
github.com/libp2p/go-libp2p-interface-pnet v0.0.1
github.com/libp2p/go-libp2p-kad-dht v0.0.11
github.com/libp2p/go-libp2p-peer v0.1.1
github.com/libp2p/go-libp2p-peerstore v0.0.6
github.com/libp2p/go-libp2p-kad-dht v0.0.14
github.com/libp2p/go-libp2p-peer v0.2.0
github.com/libp2p/go-libp2p-peerstore v0.1.0
github.com/libp2p/go-libp2p-pnet v0.0.1
github.com/libp2p/go-libp2p-protocol v0.0.1
github.com/libp2p/go-libp2p-pubsub v0.0.3
github.com/libp2p/go-libp2p-protocol v0.1.0
github.com/libp2p/go-libp2p-pubsub v0.0.6
github.com/libp2p/go-libp2p-raft v0.0.3
github.com/libp2p/go-ws-transport v0.0.2
github.com/libp2p/go-ws-transport v0.0.5
github.com/multiformats/go-multiaddr v0.0.4
github.com/multiformats/go-multiaddr-dns v0.0.2
github.com/multiformats/go-multiaddr-net v0.0.1
github.com/multiformats/go-multicodec v0.1.6
github.com/multiformats/go-multihash v0.0.5
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v0.9.3
github.com/prometheus/procfs v0.0.0-20190519111021-9935e8e0588d // indirect
github.com/rs/cors v1.6.0
github.com/ugorji/go v1.1.4
github.com/urfave/cli v1.20.0
github.com/zenground0/go-dot v0.0.0-20180912213407-94a425d4984e
go.opencensus.io v0.21.0
go4.org v0.0.0-20190313082347-94abd6928b1d // indirect
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522 // indirect
golang.org/x/image v0.0.0-20190516052701-61b8692d9a5c // indirect
gonum.org/v1/gonum v0.0.0-20190520094443-a5f8f3a4840b
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e // indirect
gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b
google.golang.org/api v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20190516172635-bb713bdc0e52 // indirect
)

0 comments on commit 501ee7b

Please sign in to comment.