engine

package
v0.0.0-...-2ff72f1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLeaderElected = errors.New("leader already elected")
	ErrNotLockHolder = errors.New("you're not mu holder")
)

Functions

This section is empty.

Types

type LeaderChangeFn

type LeaderChangeFn func(isLeader bool)

type LockSession

type LockSession struct {
	Mutex
	// contains filtered or unexported fields
}

func (*LockSession) GetHeartbeatInterval

func (s *LockSession) GetHeartbeatInterval() time.Duration

func (*LockSession) IsLeader

func (s *LockSession) IsLeader() bool

func (*LockSession) Release

func (s *LockSession) Release(ctx context.Context) error

func (*LockSession) Resign

func (s *LockSession) Resign(ctx context.Context) error

func (*LockSession) SetLeaderChangeFn

func (s *LockSession) SetLeaderChangeFn(fn LeaderChangeFn)

type Mutex

type Mutex interface {
	ID() string
	Key() string
	Timeout() time.Duration
	IsLocked() bool
	TryLock(ctx context.Context) error
	Release(ctx context.Context) error
	Refresh(ctx context.Context, lease time.Duration) error
}

type Session

type Session interface {
	ID() string
	Key() string
	Timeout() time.Duration
	IsLeader() bool
	Resign(ctx context.Context) error
	Release(ctx context.Context) error
	SetLeaderChangeFn(fn LeaderChangeFn)
}

func NewLockSession

func NewLockSession(ctx context.Context, mu Mutex) (Session, error)

type SessionClient

type SessionClient interface {
	Create(ctx context.Context, id, key string, timeout time.Duration) (Session, error)
}

type SessionStore

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

func NewSessionStore

func NewSessionStore(c SessionClient) *SessionStore

func (*SessionStore) Close

func (store *SessionStore) Close(ctx context.Context) error

Close all sessions and release the lock if held by any session

func (*SessionStore) Create

func (store *SessionStore) Create(ctx context.Context, key, id string, timeout time.Duration) (Session, error)

func (*SessionStore) Delete

func (store *SessionStore) Delete(ctx context.Context, key string) error

Delete will release the lock if held and session will be kept

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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