Files
tasks/common/membership/interfaces.go
Alfred Landrumandrodrigozhou 2923d019e4 move ringpop start call to service start (#4510)
<!-- Describe what has changed in this PR -->
**What changed?**
This moves the membership monitor Start call from a fx lifecycle hook to
each individual service's start method.

Note: this is on top of https://github.com/temporalio/temporal/pull/4506
, which is needed so that services can still get the hostinfo (server
address) to use when they, eg, initialize their service tagged loggers.

<!-- Tell your future self why have you made these changes -->
**Why?**
In short, because a service instance shouldn't join ringpop, and hence
begin to have requests forwarded to it, until it is ready to receive
them. In internal testing, focusing on the impact of history service
restarts/upgrades, we've seen requests suffer unnecessary delay because
they were forwarded to a new history pod before it began accepting on
its announced service address.

<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
This has been tested in a staging environment, and for each service
(listener, matching, history, worker), scaling up & down pod counts,
including to/from zero.

~~Note that with this change, the history service currently generates
errors at startup as it attempts lookups during its fx start sequence
(inside controller_impl.go), but it will acquire shards as expected.
I'll address the error logs in a quick followup PR.~~ (I addressed this
in this PR.)

<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**
If there's a condition that we haven't seen in testing that causes
services to lookup ringpop information during fx start time, they'll see
errors in places that haven't before. That could manifest as services
failing to start up, or failing to take on work as quickly as they had.

<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
No.
2023-08-07 17:54:05 -05:00

101 lines
4.4 KiB
Go

// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//go:generate mockgen -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination interfaces_mock.go
package membership
import (
"context"
"errors"
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/common/primitives"
)
// ErrUnknownService is thrown for a service that is not tracked by this instance
var ErrUnknownService = errors.New("service not tracked by Monitor")
// ErrInsufficientHosts is thrown when there are not enough hosts to serve the request
var ErrInsufficientHosts = serviceerror.NewUnavailable("Not enough hosts to serve the request")
// ErrListenerAlreadyExist is thrown on a duplicate AddListener call from the same listener
var ErrListenerAlreadyExist = errors.New("listener already exist for the service")
// ErrIncorrectAddressFormat is thrown on incorrect address format
var ErrIncorrectAddressFormat = errors.New("incorrect address format")
type (
// ChangedEvent describes a change in membership
ChangedEvent struct {
HostsAdded []HostInfo
HostsRemoved []HostInfo
}
// Monitor provides membership information for all temporal services.
// It can be used to query which member host of a service is responsible for serving a given key.
Monitor interface {
// Start causes this service to join the membership ring. Services
// should not call Start until they are ready to receive requests from
// other cluster members.
Start()
// EvictSelf evicts this member from the membership ring. After this method is
// called, other members will discover that this node is no longer part of the
// ring. This primitive is useful to carry out graceful host shutdown during deployments.
EvictSelf() error
// GetResolver returns the service resolver for a service in the cluster.
GetResolver(service primitives.ServiceName) (ServiceResolver, error)
// GetReachableMembers returns addresses of all members of the ring.
GetReachableMembers() ([]string, error)
// WaitUntilInitialized blocks until initialization is completed and returns the result
// of initialization. The current implementation does log.Fatal if it can't initialize,
// so currently this will never return non-nil, except for context cancel/timeout. A
// future implementation might return more errors.
WaitUntilInitialized(context.Context) error
}
// ServiceResolver provides membership information for a specific temporal service.
// It can also be used to determine the placement of resources across hosts.
ServiceResolver interface {
// Lookup looks up the host that currently owns the resource identified by the given key.
Lookup(key string) (HostInfo, error)
// AddListener adds a listener which will get notified on the given channel whenever membership changes.
AddListener(name string, notifyChannel chan<- *ChangedEvent) error
// RemoveListener removes a listener for this service.
RemoveListener(name string) error
// MemberCount returns the number of known hosts running this service.
MemberCount() int
// Members returns all known hosts available for this service.
Members() []HostInfo
// RequestRefresh requests that the membership information be refreshed.
RequestRefresh()
}
HostInfoProvider interface {
HostInfo() HostInfo
}
)