owner

package
v1.1.0-beta.0...-9958228 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ManagerSessionTTL = 60

ManagerSessionTTL is the etcd session's TTL in seconds. It's exported for testing.

View Source
var WaitTimeOnForceOwner = 5 * time.Second

WaitTimeOnForceOwner is the time to wait before or after force to be owner. make it a var for test.

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 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

func NewMockManager(ctx context.Context, id string, store kv.Storage, ownerKey string) Manager

NewMockManager creates a new mock Manager.

func NewOwnerManager

func NewOwnerManager(ctx context.Context, etcdCli *clientv3.Client, prompt, id, key string) Manager

NewOwnerManager creates a new Manager.

type OpType

type OpType byte

OpType is the owner key value operation type.

const (
	OpNone               OpType = 0
	OpSyncUpgradingState OpType = 1
)

List operation of types.

func GetOwnerOpValue

func GetOwnerOpValue(ctx context.Context, etcdCli *clientv3.Client, ownerPath string) (OpType, error)

GetOwnerOpValue gets the owner op value.

func (OpType) IsSyncedUpgradingState

func (ot OpType) IsSyncedUpgradingState() bool

IsSyncedUpgradingState represents whether the upgrading state is synchronized.

func (OpType) String

func (ot OpType) String() string

String implements fmt.Stringer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL