dlm

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreateTableLease = "CREATE TABLE IF NOT EXISTS dlm_lease(" +
		"`topic` varchar(20) NOT NULL," +
		"`key` varchar(50) NOT NULL," +
		"`lessee` varchar(36) NOT NULL," +
		"`since` int NOT NULL DEFAULT '0'," +
		"`ttl` int NOT NULL DEFAULT '0'," +
		"PRIMARY KEY (topic, key));"

	CreateTableTopic = "CREATE TABLE IF NOT EXISTS dlm_topic(" +
		"`topic` varchar(20) NOT NULL," +
		"`ttl` int NOT NULL DEFAULT '0'," +
		"PRIMARY KEY (topic));"
)

Variables

View Source
var (
	ErrExpiredLease = errors.New("dlm: lease expires")
	ErrNoLease      = errors.New("dlm: no lease")
	ErrNotYourLease = errors.New("dlm: not your lease")
	ErrLeaseExists  = errors.New("dlm: lease exists")

	ErrFrozenTopic = errors.New("dlm: topic is frozen")

	ErrBadDatabase = errors.New("dlm: bad database operation")
)
View Source
var (
	DefaultTimeout   = 3 * time.Second
	DefaultLeaseTerm = 5 * time.Second
	DefaultKeepAlive = 1 * time.Second

	Logger = slog.Default()
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

Conn wrap net.Conn with context support

func (*Conn) Close added in v0.0.4

func (c *Conn) Close() error

func (*Conn) Read

func (c *Conn) Read(p []byte) (n int, err error)

func (*Conn) Write

func (c *Conn) Write(p []byte) (n int, err error)

type Lease

type Lease struct {
	Topic string
	Key   string

	Lessee string
	Since  int64
	TTL    sqle.Duration

	// Only available on mutex
	ExpiresOn time.Time `json:"-"`
}

Lease lock period on the key

func (*Lease) IsExpired

func (l *Lease) IsExpired(start time.Time) bool

IsExpired check if lease expires on mutex side

func (*Lease) IsLive

func (l *Lease) IsLive() bool

IsLive check if lease is live on node side

type LockRequest

type LockRequest struct {
	ID    string
	Topic string
	Key   string
	TTL   time.Duration
}

type Mutex

type Mutex struct {
	context.Context
	// contains filtered or unexported fields
}

func New

func New(id, topic, key string, options ...MutexOption) *Mutex

func (*Mutex) Error

func (m *Mutex) Error(errs []error, err error) error

Error try unwrap consensus known error

func (*Mutex) Freeze

func (m *Mutex) Freeze(ctx context.Context, topic string) error

func (*Mutex) Keepalive

func (m *Mutex) Keepalive()

func (*Mutex) Lock

func (m *Mutex) Lock(ctx context.Context) error

func (*Mutex) Renew

func (m *Mutex) Renew(ctx context.Context) error

func (*Mutex) Reset

func (m *Mutex) Reset(ctx context.Context, topic string) error

func (*Mutex) Unlock

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

type MutexOption

type MutexOption func(m *Mutex)

func WithKeepAlive added in v0.0.4

func WithKeepAlive(d time.Duration) MutexOption

func WithPeers

func WithPeers(peers ...string) MutexOption

func WithTTL

func WithTTL(d time.Duration) MutexOption

func WithTimeout

func WithTimeout(d time.Duration) MutexOption

type Node

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

func NewNode

func NewNode(addr string, db *sqle.DB, options ...NodeOption) *Node

func (*Node) Freeze

func (n *Node) Freeze(topic string, ok *bool) error

func (*Node) NewLock

func (n *Node) NewLock(req LockRequest, t *Lease) error

func (*Node) ReleaseLock

func (n *Node) ReleaseLock(req LockRequest, ok *bool) error

func (*Node) RenewLock

func (n *Node) RenewLock(req LockRequest, t *Lease) error

func (*Node) Reset

func (n *Node) Reset(topic string, ok *bool) error

func (*Node) Start

func (n *Node) Start() error

Start start the node and its RPC service

func (*Node) Stop

func (n *Node) Stop()

Stop stop the node and its RPC service

type NodeOption

type NodeOption func(n *Node)

func WithLogger

func WithLogger(l *slog.Logger) NodeOption

Jump to

Keyboard shortcuts

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