Documentation ¶
Index ¶
- Constants
- Variables
- func AcquireDistributedLock(ctx context.Context, cli *clientv3.Client, key string, ttlInSec int) (release func(), err error)
- func GetOwnerKeyInfo(ctx, logCtx context.Context, etcdCli *clientv3.Client, etcdKey, id string) (string, int64, error)
- func WatchOwnerForTest(ctx context.Context, m Manager, etcdSession *concurrency.Session, key string, ...) error
- type DDLOwnerChecker
- type Listener
- type ListenersWrapper
- type Manager
- type OpType
Constants ¶
const ( // WaitTimeOnForceOwner is the time to wait before or after force to be owner. WaitTimeOnForceOwner = 5 * time.Second )
Variables ¶
var ManagerSessionTTL = 60
ManagerSessionTTL is the etcd session's TTL in seconds. It's exported for testing.
Functions ¶
func AcquireDistributedLock ¶
func AcquireDistributedLock( ctx context.Context, cli *clientv3.Client, key string, ttlInSec int, ) (release func(), err error)
AcquireDistributedLock creates a mutex with ETCD client, and returns a mutex release function.
func GetOwnerKeyInfo ¶
func GetOwnerKeyInfo( ctx, logCtx context.Context, etcdCli *clientv3.Client, etcdKey, id string, ) (string, int64, error)
GetOwnerKeyInfo gets the owner key and current revision.
func WatchOwnerForTest ¶
func WatchOwnerForTest(ctx context.Context, m Manager, etcdSession *concurrency.Session, key string, createRevison int64) error
WatchOwnerForTest watches the ownerKey. This function is used to test watchOwner().
Types ¶
type DDLOwnerChecker ¶
type DDLOwnerChecker interface { // IsOwner returns whether the ownerManager is the owner. IsOwner() bool }
DDLOwnerChecker is used to check whether tidb is owner.
type Listener ¶
type Listener interface { OnBecomeOwner() OnRetireOwner() }
Listener is used to listen the ownerManager's owner state.
type ListenersWrapper ¶
type ListenersWrapper struct {
// contains filtered or unexported fields
}
ListenersWrapper is a list of listeners. A way to broadcast events to multiple listeners.
func NewListenersWrapper ¶
func NewListenersWrapper(listeners ...Listener) *ListenersWrapper
NewListenersWrapper creates a new OwnerListeners.
func (*ListenersWrapper) OnBecomeOwner ¶
func (ol *ListenersWrapper) OnBecomeOwner()
OnBecomeOwner broadcasts the OnBecomeOwner event to all listeners.
func (*ListenersWrapper) OnRetireOwner ¶
func (ol *ListenersWrapper) OnRetireOwner()
OnRetireOwner broadcasts the OnRetireOwner event to all listeners.
type Manager ¶
type Manager interface { // ID returns the ID of the manager. ID() string // IsOwner returns whether the ownerManager is the owner. IsOwner() bool // RetireOwner make the manager to be a not owner. It's exported for testing. RetireOwner() // GetOwnerID gets the owner ID. GetOwnerID(ctx context.Context) (string, error) // SetOwnerOpValue updates the owner op value. SetOwnerOpValue(ctx context.Context, op OpType) error // CampaignOwner campaigns the owner. It will start a background goroutine to // campaign owner in a loop, and when become or retire owner, it will call methods // of the listener. CampaignOwner(...int) error // CampaignCancel cancels one etcd campaign, it will also close the underlying // etcd session. After this method is called, the manager can be used to campaign // owner again. CampaignCancel() // BreakCampaignLoop breaks the campaign loop, related listener methods will // be called. The underlying etcd session the related campaign key will remain, // so if some instance is the owner before, after break and campaign again, it // will still be the owner. BreakCampaignLoop() // ResignOwner will resign and start a new election if it's the owner. ResignOwner(ctx context.Context) error // Close closes the manager, after close, no methods can be called. Close() // SetListener sets the listener, set before CampaignOwner. SetListener(listener Listener) // ForceToBeOwner restart the owner election and trying to be the new owner by // end campaigns of all candidates and start a new campaign in a single transaction. // // This method is only used during upgrade and try to make node of newer version // to be the DDL owner, to mitigate the issue https://github.com/pingcap/tidb/issues/54689, // current instance shouldn't call CampaignOwner before calling this method. // don't use it in other cases. // // Note: only one instance can call this method at a time, so you have to use // a distributed lock when there are multiple instances of new version TiDB trying // to be the owner. See runInBootstrapSession for where we lock it in DDL. ForceToBeOwner(ctx context.Context) error }
Manager is used to campaign the owner and manage the owner information.
func NewMockManager ¶
NewMockManager creates a new mock Manager.
type OpType ¶
type OpType byte
OpType is the owner key value operation type.
func GetOwnerOpValue ¶
func GetOwnerOpValue(ctx context.Context, etcdCli *clientv3.Client, ownerPath, logPrefix string) (OpType, error)
GetOwnerOpValue gets the owner op value.
func (OpType) IsSyncedUpgradingState ¶
IsSyncedUpgradingState represents whether the upgrading state is synchronized.