Commit 550c57ff authored by Levin Zimmermann's avatar Levin Zimmermann

TalkMaster: Switch master if dialed is secondary

When connecting to a master node, the client needs to try a different
master if the initially tried one is a secondary master node. This
statement wasn't implemented yet before this patch and therefore it was
good luck if the initally tried master was the primary one - and the
connection worked - or if it was a secondary master - and the client
got stuck in re-trying the same node forever. This patch makes NEO/go
usage with clusters of more than one master therefore much more stable.
parent 02e8b7ed
...@@ -132,18 +132,14 @@ func (node *_MasteredNode) TalkMaster(ctx context.Context, f func(context.Contex ...@@ -132,18 +132,14 @@ func (node *_MasteredNode) TalkMaster(ctx context.Context, f func(context.Contex
return err // M commands to shutdown return err // M commands to shutdown
} }
log.Warning(ctx, errors.Cause(err)) var notPrimaryMaster *proto.NotPrimaryMaster
if errors.As(err, &notPrimaryMaster) {
var unexpectedMsg *neonet.ErrUnexpectedMsg primary := notPrimaryMaster.KnownMasterList[notPrimaryMaster.Primary]
if errors.As(err, &unexpectedMsg) { node.MasterAddr = fmt.Sprintf("[%s]:%v", primary.Host, primary.Port)
if unexpectedMsg.MsgCode == proto.MsgCode(&proto.NotPrimaryMaster{}) { return err
log.Warning(ctx, unexpectedMsg.MsgCode)
log.Warning(ctx, unexpectedMsg.Msg)
}
} }
// TODO if err == "reject identification / protocol error" -> shutdown client? // TODO if err == "reject identification / protocol error" -> shutdown client?
// TODO if err == "not a primary" -> try redirected address
// exit on cancel / throttle reconnecting // exit on cancel / throttle reconnecting
select { select {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment