update raft lib, improve raft logging
This commit is contained in:
1 parent
52705f6982
commit
c3f419bbc5
5 files changed
+23
-17
No files matched your search
+8
-6
@@ -2,6 +2,7 @@ package cluster
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -67,10 +68,10 @@ func (client *Client) SyncApply(command []byte) (*ApplyLogResponse, error) {
|
||||
if client.leaderState.isLeader {
|
||||
apply, err := client.r.SyncApply(command)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("apply to raft as a leader: %v", err)
|
||||
}
|
||||
logResponse := apply.(ApplyLogResponse)
|
||||
return &logResponse, err
|
||||
return &logResponse, nil
|
||||
}
|
||||
|
||||
if client.leaderClient == nil {
|
||||
@@ -78,7 +79,7 @@ func (client *Client) SyncApply(command []byte) (*ApplyLogResponse, error) {
|
||||
}
|
||||
response, err := client.leaderClient.Ack(command, defaultApplyTimeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("send to leader to apply: %v", err)
|
||||
}
|
||||
|
||||
var logResponse ApplyLogResponse
|
||||
@@ -99,7 +100,7 @@ func (client *Client) SyncApplyOnLeader(command []byte) (*ApplyLogResponse, erro
|
||||
}
|
||||
apply, err := client.r.SyncApply(command)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("apply to raft as a leader: %v", err)
|
||||
}
|
||||
logResponse := apply.(ApplyLogResponse)
|
||||
return &logResponse, err
|
||||
@@ -115,7 +116,6 @@ func (client *Client) listenLeader() {
|
||||
}).Info(codes.LeaderStateChanged, "leader state changed")
|
||||
|
||||
if client.leaderClient != nil {
|
||||
log.Debugf(0, "close previous leader ws connection %s", client.leaderState.leaderAddr)
|
||||
client.leaderClient.Close()
|
||||
client.leaderClient = nil
|
||||
}
|
||||
@@ -148,7 +148,9 @@ func (client *Client) declareMyselfToLeader(leaderClient *SocketLeaderClient) {
|
||||
if err != nil {
|
||||
log.Warnf(codes.SendDeclarationToLeader, "send declaration to leader. err: %v", err)
|
||||
} else if response != utils.WsOkResponse {
|
||||
log.Warnf(codes.SendDeclarationToLeader, "send declaration to leader. response: %s", response)
|
||||
log.Warnf(codes.SendDeclarationToLeader, "send declaration to leader. error response: '%s'", response)
|
||||
} else {
|
||||
log.Info(codes.SendDeclarationToLeader, "successfully sent my declaration to leader")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,9 @@ func (c *SocketLeaderClient) Close() {
|
||||
c.cancel()
|
||||
err := c.client.Close()
|
||||
if err != nil {
|
||||
log.Warnf(codes.LeaderClientConnectionError, "leader client close err: %v", err)
|
||||
log.Warnf(codes.LeaderClientConnectionError, "leader client %s close err: %v", c.url, err)
|
||||
}
|
||||
log.Debug(0, "leader client connection closed")
|
||||
log.Debugf(0, "close previous leader ws connection %s", c.url)
|
||||
}
|
||||
|
||||
func NewSocketLeaderClient(address string, leaderDisconnectionCallback func()) *SocketLeaderClient {
|
||||
@@ -84,12 +84,16 @@ func NewSocketLeaderClient(address string, leaderDisconnectionCallback func()) *
|
||||
leaderClient.client.OnDisconnect(func(err error) {
|
||||
log.WithMetadata(map[string]interface{}{
|
||||
"leaderAddr": address,
|
||||
"error": err,
|
||||
}).Warn(codes.LeaderClientDisconnected, "disconnected ws from leader")
|
||||
leaderDisconnectionCallback()
|
||||
})
|
||||
|
||||
leaderClient.client.OnError(func(err error) {
|
||||
log.Warnf(codes.LeaderClientConnectionError, "leader client on error: %v", err)
|
||||
log.WithMetadata(map[string]interface{}{
|
||||
"leaderAddr": address,
|
||||
"error": err,
|
||||
}).Warn(codes.LeaderClientDisconnected, "leader client on error")
|
||||
})
|
||||
leaderClient.client.OnConnect(func() {
|
||||
log.WithMetadata(map[string]interface{}{
|
||||
|
||||
@@ -6,8 +6,8 @@ require (
|
||||
github.com/asaskevich/govalidator v0.0.0-20180315120708-ccb8e960c48f
|
||||
github.com/cenkalti/backoff/v4 v4.1.0
|
||||
github.com/go-pg/pg/v9 v9.1.7
|
||||
github.com/hashicorp/raft v1.1.2
|
||||
github.com/hashicorp/raft-boltdb v0.0.0-20191021154308-4207f1bf0617
|
||||
github.com/hashicorp/raft v1.2.0
|
||||
github.com/hashicorp/raft-boltdb/v2 v2.0.0-20210409134258-03c10cc3d4ea
|
||||
github.com/integration-system/bellows v1.0.1
|
||||
github.com/integration-system/isp-etp-go/v2 v2.1.2
|
||||
github.com/integration-system/isp-lib-test v1.6.3
|
||||
|
||||
@@ -61,7 +61,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
|
||||
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/buaazp/fasthttprouter v0.1.1 h1:4oAnN0C3xZjylvZJdP35cxfclyn4TYkW6Y+DSvS+h8Q=
|
||||
github.com/buaazp/fasthttprouter v0.1.1/go.mod h1:h/Ap5oRVLeItGKTVBb+heQPks+HdIUtGmI4H5WCYijM=
|
||||
@@ -280,11 +279,13 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
|
||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||
github.com/hashicorp/raft v1.1.0/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM=
|
||||
github.com/hashicorp/raft v1.1.1/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8=
|
||||
github.com/hashicorp/raft v1.1.2 h1:oxEL5DDeurYxLd3UbcY/hccgSPhLLpiBZ1YxtWEq59c=
|
||||
github.com/hashicorp/raft v1.1.2/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8=
|
||||
github.com/hashicorp/raft v1.2.0 h1:mHzHIrF0S91d3A7RPBvuqkgB4d/7oFJZyvf1Q4m7GA0=
|
||||
github.com/hashicorp/raft v1.2.0/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8=
|
||||
github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea h1:xykPFhrBAS2J0VBzVa5e80b5ZtYuNQtgXjN40qBZlD4=
|
||||
github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea/go.mod h1:pNv7Wc3ycL6F5oOWn+tPGo2gWD4a5X+yp/ntwdKLjRk=
|
||||
github.com/hashicorp/raft-boltdb v0.0.0-20191021154308-4207f1bf0617 h1:CJDRE/2tBNFOrcoexD2nvTRbQEox3FDxl4NxIezp1b8=
|
||||
github.com/hashicorp/raft-boltdb v0.0.0-20191021154308-4207f1bf0617/go.mod h1:aUF6HQr8+t3FC/ZHAC+pZreUBhTaxumuu3L+d37uRxk=
|
||||
github.com/hashicorp/raft-boltdb/v2 v2.0.0-20210409134258-03c10cc3d4ea h1:pXD01QLdHmn4Ij82g1vksWbZXwSH6il7Svrm/rdUk18=
|
||||
github.com/hashicorp/raft-boltdb/v2 v2.0.0-20210409134258-03c10cc3d4ea/go.mod h1:kiPs9g148eLShc2TYagUAyKDnD+dH9U+CQKsXzlY9xo=
|
||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
@@ -720,7 +721,6 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/raft"
|
||||
raftboltdb "github.com/hashicorp/raft-boltdb"
|
||||
"github.com/hashicorp/raft-boltdb/v2"
|
||||
"github.com/integration-system/isp-log/adapter"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/codes"
|
||||
|
||||
Reference in new issue
Block a user