go.temporal.io/server@v1.23.0/common/membership/interfaces.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 //go:generate mockgen -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination interfaces_mock.go 26 27 package membership 28 29 import ( 30 "context" 31 "errors" 32 33 "go.temporal.io/api/serviceerror" 34 35 "go.temporal.io/server/common/primitives" 36 ) 37 38 // ErrUnknownService is thrown for a service that is not tracked by this instance 39 var ErrUnknownService = errors.New("service not tracked by Monitor") 40 41 // ErrInsufficientHosts is thrown when there are not enough hosts to serve the request 42 var ErrInsufficientHosts = serviceerror.NewUnavailable("Not enough hosts to serve the request") 43 44 // ErrListenerAlreadyExist is thrown on a duplicate AddListener call from the same listener 45 var ErrListenerAlreadyExist = errors.New("listener already exist for the service") 46 47 // ErrIncorrectAddressFormat is thrown on incorrect address format 48 var ErrIncorrectAddressFormat = errors.New("incorrect address format") 49 50 type ( 51 52 // ChangedEvent describes a change in membership 53 ChangedEvent struct { 54 HostsAdded []HostInfo 55 HostsRemoved []HostInfo 56 } 57 58 // Monitor provides membership information for all temporal services. 59 // It can be used to query which member host of a service is responsible for serving a given key. 60 Monitor interface { 61 // Start causes this service to join the membership ring. Services 62 // should not call Start until they are ready to receive requests from 63 // other cluster members. 64 Start() 65 // EvictSelf evicts this member from the membership ring. After this method is 66 // called, other members will discover that this node is no longer part of the 67 // ring. This primitive is useful to carry out graceful host shutdown during deployments. 68 EvictSelf() error 69 // GetResolver returns the service resolver for a service in the cluster. 70 GetResolver(service primitives.ServiceName) (ServiceResolver, error) 71 // GetReachableMembers returns addresses of all members of the ring. 72 GetReachableMembers() ([]string, error) 73 // WaitUntilInitialized blocks until initialization is completed and returns the result 74 // of initialization. The current implementation does log.Fatal if it can't initialize, 75 // so currently this will never return non-nil, except for context cancel/timeout. A 76 // future implementation might return more errors. 77 WaitUntilInitialized(context.Context) error 78 } 79 80 // ServiceResolver provides membership information for a specific temporal service. 81 // It can also be used to determine the placement of resources across hosts. 82 ServiceResolver interface { 83 // Lookup looks up the host that currently owns the resource identified by the given key. 84 Lookup(key string) (HostInfo, error) 85 // LookupN looks n hosts that owns the resource identified by the given key, if n greater than total number 86 // of hosts total number of hosts will be returned 87 LookupN(key string, n int) []HostInfo 88 // AddListener adds a listener which will get notified on the given channel whenever membership changes. 89 AddListener(name string, notifyChannel chan<- *ChangedEvent) error 90 // RemoveListener removes a listener for this service. 91 RemoveListener(name string) error 92 // MemberCount returns the number of known hosts running this service. 93 MemberCount() int 94 // Members returns all known hosts available for this service. 95 Members() []HostInfo 96 // RequestRefresh requests that the membership information be refreshed. 97 RequestRefresh() 98 } 99 100 HostInfoProvider interface { 101 HostInfo() HostInfo 102 } 103 )