Commit 22e5d1e9 authored by Levin Zimmermann's avatar Levin Zimmermann

TalkMaster: Switch master if dialed M 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 bbf9f440
...@@ -130,8 +130,14 @@ func (node *_MasteredNode) TalkMaster(ctx context.Context, f func(context.Contex ...@@ -130,8 +130,14 @@ func (node *_MasteredNode) TalkMaster(ctx context.Context, f func(context.Contex
if errors.Is(err, cmdShutdown) { if errors.Is(err, cmdShutdown) {
return err // M commands to shutdown return err // M commands to shutdown
} }
var notPrimaryMaster *proto.NotPrimaryMaster
if errors.As(err, &notPrimaryMaster) {
primary := notPrimaryMaster.KnownMasterList[notPrimaryMaster.Primary]
node.MasterAddr = fmt.Sprintf("[%s]:%v", primary.Host, primary.Port)
}
// 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