Skip to content

Add call stack print for Error, Fatal and Panic #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ before_script:
- echo $TRAVIS_SECURE_ENV_VARS
script:
- bash build.sh
- go test -v -race $(go list ./... | grep -v "/vendor/") -coverprofile cover.out
- go test -v -race -failfast -parallel 16 $(go list ./... | grep -v "/vendor/") -coverprofile cover.out
- cd rpc && go test -test.bench ^BenchmarkPersistentCaller_Call$ -test.run ^$ && cd -
- gocovmerge cover.out $(find cmd -name "*.cover.out") > coverage.txt && rm -f cover.out
- bash <(curl -s https://codecov.io/bash)
Expand Down
31 changes: 9 additions & 22 deletions cmd/cql-minerd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ var nodeCmds []*utils.CMD

var FJ = filepath.Join

func TestBuild(t *testing.T) {
Convey("build", t, func() {
log.SetLevel(log.DebugLevel)
So(utils.Build(), ShouldBeNil)
})
}

func startNodes() {
ctx := context.Background()

Expand Down Expand Up @@ -90,7 +83,7 @@ func startNodes() {
[]string{"-config", FJ(testWorkingDir, "./integration/node_1/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/follower1.cover.out"),
},
"follower1", testWorkingDir, logDir, true,
"follower1", testWorkingDir, logDir, false,
); err == nil {
nodeCmds = append(nodeCmds, cmd)
} else {
Expand All @@ -101,7 +94,7 @@ func startNodes() {
[]string{"-config", FJ(testWorkingDir, "./integration/node_2/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/follower2.cover.out"),
},
"follower2", testWorkingDir, logDir, true,
"follower2", testWorkingDir, logDir, false,
); err == nil {
nodeCmds = append(nodeCmds, cmd)
} else {
Expand All @@ -114,7 +107,7 @@ func startNodes() {
3122,
3121,
3120,
}, time.Millisecond*200)
}, time.Second)

if err != nil {
log.Fatalf("wait for port ready timeout: %v", err)
Expand Down Expand Up @@ -154,7 +147,7 @@ func startNodes() {
[]string{"-config", FJ(testWorkingDir, "./integration/node_miner_1/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/miner1.cover.out"),
},
"miner1", testWorkingDir, logDir, true,
"miner1", testWorkingDir, logDir, false,
); err == nil {
nodeCmds = append(nodeCmds, cmd)
} else {
Expand All @@ -167,7 +160,7 @@ func startNodes() {
[]string{"-config", FJ(testWorkingDir, "./integration/node_miner_2/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/miner2.cover.out"),
},
"miner2", testWorkingDir, logDir, true,
"miner2", testWorkingDir, logDir, false,
); err == nil {
nodeCmds = append(nodeCmds, cmd)
} else {
Expand Down Expand Up @@ -324,15 +317,9 @@ func TestFullProcess(t *testing.T) {
startNodes()
defer stopNodes()
var err error
err = utils.WaitToConnect(context.Background(), "127.0.0.1", []int{
2144,
2145,
2146,
3122,
3121,
3120,
}, time.Millisecond*200)
time.Sleep(2 * time.Second)

time.Sleep(10 * time.Second)

So(err, ShouldBeNil)

err = client.Init(FJ(testWorkingDir, "./integration/node_c/config.yaml"), []byte(""))
Expand Down Expand Up @@ -506,7 +493,7 @@ func benchMiner(b *testing.B, minerCount uint16, bypassSign bool) {
3122,
3121,
3120,
}, time.Millisecond*200)
}, 2*time.Second)
time.Sleep(time.Second)
}

Expand Down
42 changes: 1 addition & 41 deletions cmd/cql-minerd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/CovenantSQL/CovenantSQL/crypto/asymmetric"
"github.com/CovenantSQL/CovenantSQL/crypto/kms"
"github.com/CovenantSQL/CovenantSQL/metric"
"github.com/CovenantSQL/CovenantSQL/proto"
"github.com/CovenantSQL/CovenantSQL/route"
"github.com/CovenantSQL/CovenantSQL/rpc"
"github.com/CovenantSQL/CovenantSQL/utils"
Expand Down Expand Up @@ -118,7 +117,7 @@ func initLogs() {
func main() {
// set random
rand.Seed(time.Now().UnixNano())
log.SetLevel(log.InfoLevel)
log.SetLevel(log.DebugLevel)
flag.Parse()

if showVersion {
Expand Down Expand Up @@ -216,45 +215,6 @@ func main() {
}
}()

// start block producer pinger
go func() {
var localNodeID proto.NodeID
var err error

// get local node id
if localNodeID, err = kms.GetLocalNodeID(); err != nil {
return
}

// get local node info
var localNodeInfo *proto.Node
if localNodeInfo, err = kms.GetNodeInfo(localNodeID); err != nil {
return
}

log.WithField("node", localNodeInfo).Debug("construct local node info")

go func() {
for {
select {
case <-time.After(time.Second):
case <-stopCh:
return
}

// send ping requests to block producer
bpNodeIDs := route.GetBPs()

for _, bpNodeID := range bpNodeIDs {
err := rpc.PingBP(localNodeInfo, bpNodeID)
if err == nil {
return
}
}
}
}()
}()

// start dbms
var dbms *worker.DBMS
if dbms, err = startDBMS(server); err != nil {
Expand Down
60 changes: 60 additions & 0 deletions cmd/cql-minerd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ package main
import (
"fmt"
"os"
"strings"
"syscall"
"time"

"github.com/CovenantSQL/CovenantSQL/conf"
"github.com/CovenantSQL/CovenantSQL/crypto/kms"
"github.com/CovenantSQL/CovenantSQL/kayak"
"github.com/CovenantSQL/CovenantSQL/proto"
"github.com/CovenantSQL/CovenantSQL/route"
"github.com/CovenantSQL/CovenantSQL/rpc"
"github.com/CovenantSQL/CovenantSQL/utils/log"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh/terminal"
)

Expand All @@ -51,6 +56,11 @@ func initNode() (server *rpc.Server, err error) {
// init kms routing
route.InitKMS(conf.GConf.PubKeyStoreFile)

err = registerNodeToBP(15 * time.Second)
if err != nil {
log.Fatalf("register node to BP failed: %v", err)
}

// init server
if server, err = createServer(
conf.GConf.PrivateKeyFile, conf.GConf.PubKeyStoreFile, masterKey, conf.GConf.ListenAddr); err != nil {
Expand All @@ -73,3 +83,53 @@ func createServer(privateKeyPath, pubKeyStorePath string, masterKey []byte, list

return
}

func registerNodeToBP(timeout time.Duration) (err error) {
// get local node id
localNodeID, err := kms.GetLocalNodeID()
if err != nil {
err = errors.Wrap(err, "register node to BP")
return
}

// get local node info
localNodeInfo, err := kms.GetNodeInfo(localNodeID)
if err != nil {
err = errors.Wrap(err, "register node to BP")
return
}

log.WithField("node", localNodeInfo).Debug("construct local node info")

pingWaitCh := make(chan proto.NodeID)
bpNodeIDs := route.GetBPs()
for _, bpNodeID := range bpNodeIDs {
go func(ch chan proto.NodeID, id proto.NodeID) {
for {
err := rpc.PingBP(localNodeInfo, id)
if err == nil {
log.Infof("ping BP succeed: %v", localNodeInfo)
ch <- id
return
}
if strings.Contains(err.Error(), kayak.ErrNotLeader.Error()) {
log.Debug("stop ping non leader BP node")
return
}

log.Warnf("ping BP failed: %v", err)
time.Sleep(3 * time.Second)
}
}(pingWaitCh, bpNodeID)
}

select {
case bp := <-pingWaitCh:
close(pingWaitCh)
log.WithField("BP", bp).Infof("ping BP succeed")
case <-time.After(timeout):
return errors.New("ping BP timeout")
}

return
}
14 changes: 4 additions & 10 deletions cmd/cql-observer/observation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ var nodeCmds []*utils.CMD

var FJ = filepath.Join

func TestBuild(t *testing.T) {
Convey("build", t, func() {
log.SetLevel(log.DebugLevel)
So(utils.Build(), ShouldBeNil)
})
}

func startNodes() {
// wait for ports to be available
var err error
Expand All @@ -80,7 +73,7 @@ func startNodes() {
[]string{"-config", FJ(testWorkingDir, "./observation/node_0/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-observer/leader.cover.out"),
},
"leader", testWorkingDir, logDir, false,
"leader", testWorkingDir, logDir, true,
); err == nil {
nodeCmds = append(nodeCmds, cmd)
} else {
Expand Down Expand Up @@ -115,7 +108,7 @@ func startNodes() {
4120,
4121,
4122,
}, time.Millisecond*200)
}, time.Second)
if err != nil {
log.Fatalf("wait for port ready timeout: %v", err)
}
Expand Down Expand Up @@ -233,11 +226,12 @@ func TestFullProcess(t *testing.T) {
log.SetLevel(log.DebugLevel)

Convey("test full process", t, func() {
var err error
startNodes()
defer stopNodes()

time.Sleep(10 * time.Second)

var err error
err = client.Init(FJ(testWorkingDir, "./observation/node_c/config.yaml"), []byte(""))
So(err, ShouldBeNil)

Expand Down
10 changes: 1 addition & 9 deletions cmd/cqld/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/CovenantSQL/CovenantSQL/rpc"
"github.com/CovenantSQL/CovenantSQL/utils"
"github.com/CovenantSQL/CovenantSQL/utils/log"
. "github.com/smartystreets/goconvey/convey"
)

var (
Expand All @@ -43,13 +42,6 @@ var (

var FJ = filepath.Join

func TestBuild(t *testing.T) {
Convey("build", t, func() {
log.SetLevel(log.DebugLevel)
So(utils.Build(), ShouldBeNil)
})
}

func start3BPs() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
Expand Down Expand Up @@ -97,7 +89,7 @@ func TestStartBP_CallRPC(t *testing.T) {
2122,
2121,
2120,
}, time.Millisecond*200)
}, time.Second)
if err != nil {
log.Fatalf("wait for port ready timeout: %v", err)
}
Expand Down
34 changes: 1 addition & 33 deletions cmd/cqld/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func runNode(nodeID proto.NodeID, listenAddr string) (err error) {
peers,
nodeID,
2*time.Second,
100*time.Millisecond,
900*time.Millisecond,
)
chain, err := bp.NewChain(chainConfig)
if err != nil {
Expand Down Expand Up @@ -242,38 +242,6 @@ func initDBService(kvServer *KayakKVServer, metricService *metric.CollectServer)
return
}

//FIXME(auxten): clean up ugly periodicPingBlockProducer
func periodicPingBlockProducer() {
var localNodeID proto.NodeID
var err error

// get local node id
if localNodeID, err = kms.GetLocalNodeID(); err != nil {
return
}

// get local node info
var localNodeInfo *proto.Node
if localNodeInfo, err = kms.GetNodeInfo(localNodeID); err != nil {
return
}

log.WithField("node", localNodeInfo).Debug("construct local node info")

go func() {
for {
time.Sleep(time.Second)

// send ping requests to block producer
bpNodeIDs := route.GetBPs()

for _, bpNodeID := range bpNodeIDs {
rpc.PingBP(localNodeInfo, bpNodeID)
}
}
}()
}

func loadGenesis() *types.Block {
genesisInfo := conf.GConf.BP.BPGenesis
log.WithField("config", genesisInfo).Info("load genesis config")
Expand Down
9 changes: 9 additions & 0 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,14 @@ func LoadConfig(configPath string) (config *Config, err error) {
if config.Miner != nil && !path.IsAbs(config.Miner.RootDir) {
config.Miner.RootDir = path.Join(configDir, config.Miner.RootDir)
}
/*
The `go test -race` makes BP catch up block too slow, so let's make
genesis block just one day ago in test mode
*/
if config.IsTestMode {
if config.BP != nil {
config.BP.BPGenesis.Timestamp = time.Now().AddDate(0, 0, -1)
}
}
return
}
Loading