mirror of
https://github.com/openziti/ziti.git
synced 2026-11-25 08:52:03 +00:00
7f2f619e88
- adds a startup reconcile that asks the leader to move this node's stored raft address to its configured advertise address, retrying with jittered backoff until the change is visible locally - wakes the running reconcile on leader events instead of starting a second one, and jitters the first attempt and each wake so controllers reconciling after the same event spread their requests - keeps checking a node whose copy of the configuration doesn't list it yet, as after a restart before any of the log reached it, instead of treating it as reconciled - adds an UpdatePeerAddressRequest peer message carrying the member id, the address the node believes is stored and the new address; the leader accepts it only from the node it names and does not forward it - adds updateMemberAddressAsLeader, which changes a member's address in place, keeping its suffrage, after refusing non-members, addresses held by another member and stale from addresses - probes the new address as a sanity check, refusing the change if a different controller answers and making it with a warning if the address can't be reached, since some controllers only dial out - conditions the update on a configuration index read from the raft log and snapshot stores, since GetConfiguration().Index() is always zero in the pinned raft version - routes AddPeer requests that find an existing member at a new address to the in-place update instead of remove and re-add, identifying the member through GetPeerInfo rather than the request id - falls back to the member id when the raft transport dials a stored address with no peer connected at it - adds a probe hello header so probe connections are closed without registering a peer - excludes self by server id in GetPeerAddresses - corrects the inverted voter flag in the peer AddPeer log and removes the unused ctrlAddress field - tests single-node, follower, non-voter and leader address changes, refused and unverified addresses, requests from the wrong sender, membership changes made while a member is offline or during the probe, and configuration lookup across snapshots and log gaps - tests the reconcile starting on an empty log and waiting until the configuration lists the node - waits in the HA test harness for a restarted peer's own configuration to list it before restarting it - adds a changelog entry describing the address update and the leader version requirement
80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package handler_peer_ctrl
|
|
|
|
import (
|
|
raft2 "github.com/hashicorp/raft"
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/openziti/channel/v5"
|
|
"github.com/openziti/ziti/v2/common/pb/cmd_pb"
|
|
"github.com/openziti/ziti/v2/controller/peermsg"
|
|
"github.com/openziti/ziti/v2/controller/raft"
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func newAddPeerHandler(controller *raft.Controller) channel.ContentTypeReceiver {
|
|
return &addPeerHandler{
|
|
controller: controller,
|
|
}
|
|
}
|
|
|
|
type addPeerHandler struct {
|
|
controller *raft.Controller
|
|
}
|
|
|
|
func (self *addPeerHandler) ContentType() int32 {
|
|
return int32(cmd_pb.ContentType_AddPeerRequestType)
|
|
}
|
|
|
|
func (self *addPeerHandler) HandleReceive(msg *channel.Message, ch channel.Channel) {
|
|
log := pfxlog.ContextLogger(ch.Label())
|
|
request := &cmd_pb.AddPeerRequest{}
|
|
if err := proto.Unmarshal(msg.Body, request); err != nil {
|
|
log.WithError(err).Error("failed to unmarshal add peer message")
|
|
go sendErrorResponse(msg, ch, err, peermsg.ErrorCodeBadMessage)
|
|
return
|
|
}
|
|
go self.handleAddPeer(msg, ch, request)
|
|
}
|
|
|
|
func (self *addPeerHandler) handleAddPeer(m *channel.Message, ch channel.Channel, req *cmd_pb.AddPeerRequest) {
|
|
log := pfxlog.ContextLogger(ch.Label())
|
|
|
|
log.Infof("received join request id: %v, addr: %v, voter: %v", req.Id, req.Addr, req.IsVoter)
|
|
|
|
if !self.controller.IsBootstrapped() {
|
|
sendErrorResponse(m, ch, errors.New("node not member of bootstrapped cluster, unable to add peers"), peermsg.ErrorCodeGeneric)
|
|
return
|
|
}
|
|
|
|
if err := self.controller.HandleAddPeer(req); err != nil {
|
|
if errors.Is(err, raft2.ErrNotLeader) {
|
|
sendErrorResponse(m, ch, err, peermsg.ErrorCodeNotLeader)
|
|
} else {
|
|
sendErrorResponse(m, ch, err, peermsg.ErrorCodeGeneric)
|
|
}
|
|
} else {
|
|
resp := channel.NewMessage(int32(cmd_pb.ContentType_SuccessResponseType), nil)
|
|
resp.ReplyTo(m)
|
|
if sendErr := ch.Send(resp); sendErr != nil {
|
|
logrus.WithError(sendErr).Error("error while sending success response")
|
|
}
|
|
}
|
|
}
|