mongo

package
v1.0.1-20230322 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const LeaderKey = "leader"

Variables

This section is empty.

Functions

This section is empty.

Types

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

Keeper mongo implement

func NewKeeper

func NewKeeper(opt *KeeperOption) *Keeper

NewKeeper

func (*Keeper) AliveNodes

func (k *Keeper) AliveNodes() ([]string, error)

AliveNodes get all alive nodes

func (*Keeper) Close

func (k *Keeper) Close()

close component

func (*Keeper) Init

func (k *Keeper) Init() error

Init

func (*Keeper) IsAlive

func (k *Keeper) IsAlive(workerKey string) (bool, error)

IsAlive check if a worker still alive

func (*Keeper) IsLeader

func (k *Keeper) IsLeader() bool

IsLeader indicate the component if is leader node

func (*Keeper) NewMutex

func (k *Keeper) NewMutex(key string) mod.DistributedMutex

NewMutex(key string) create a new distributed mutex

func (*Keeper) WorkerKey

func (k *Keeper) WorkerKey() string

WorkerKey must match `xxxx-1` format

func (*Keeper) WorkerNumber

func (k *Keeper) WorkerNumber() int

WorkerNumber get the the key number of Worker key, if here is a WorkKey like `worker-1`, then it will return "1"

type KeeperOption

type KeeperOption struct {
	// Key the work key, must be the format like "xxxx-{{number}}", number is the code of worker
	Key string
	// mongo connection string
	ConnStr  string
	Database string
	// the prefix will append to the database
	Prefix string
	// UnhealthyTime default 5s, campaign and heartbeat time will be half of it
	UnhealthyTime time.Duration
	// Timeout default 2s
	Timeout time.Duration
}

KeeperOption

type LeaderPayload

type LeaderPayload struct {
	ID        string    `bson:"_id"`
	WorkerKey string    `bson:"workerKey"`
	UpdatedAt time.Time `bson:"updatedAt"`
}

LeaderPayload leader election dto

type LockDetail

type LockDetail struct {
	Key       string    `bson:"_id"`
	ExpiredAt time.Time `bson:"expiredAt"`
	Identity  string    `bson:"identity"`
}

type MongoMutex

type MongoMutex struct {
	// contains filtered or unexported fields
}

func (*MongoMutex) Lock

func (m *MongoMutex) Lock(ctx context.Context, ops ...mod.LockOptionOp) error

func (*MongoMutex) Unlock

func (m *MongoMutex) Unlock(ctx context.Context) error

type Payload

type Payload struct {
	WorkerKey string    `bson:"_id"`
	UpdatedAt time.Time `bson:"updatedAt"`
}

Payload header beat dto

Jump to

Keyboard shortcuts

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