sequence

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sequence provides atomic sequence counters for XxSql.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager manages multiple sequences.

func NewManager

func NewManager(path string, walLogger WALLogger) *Manager

NewManager creates a new sequence manager.

func (*Manager) BatchNextValue

func (m *Manager) BatchNextValue(name string, count int) ([]int64, error)

BatchNextValue returns multiple values from a sequence.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the sequence manager.

func (*Manager) CreateSequence

func (m *Manager) CreateSequence(config SequenceConfig) error

CreateSequence creates a new sequence.

func (*Manager) CurrentValue

func (m *Manager) CurrentValue(name string) (int64, error)

CurrentValue returns the current value of a sequence without advancing it.

func (*Manager) DropSequence

func (m *Manager) DropSequence(name string) error

DropSequence drops a sequence.

func (*Manager) Exists

func (m *Manager) Exists(name string) bool

Exists checks if a sequence exists.

func (*Manager) Flush

func (m *Manager) Flush() error

Flush triggers an immediate persist.

func (*Manager) GetRange

func (m *Manager) GetRange(name string, count int) (start, end int64, err error)

GetRange returns a range of values from a sequence. This is more efficient than multiple NextValue calls for bulk operations.

func (*Manager) GetSequence

func (m *Manager) GetSequence(name string) (*Sequence, error)

GetSequence returns information about a sequence.

func (*Manager) ListSequences

func (m *Manager) ListSequences() []string

ListSequences returns a list of all sequence names.

func (*Manager) Load

func (m *Manager) Load() error

Load loads sequences from disk.

func (*Manager) NextValue

func (m *Manager) NextValue(name string) (int64, error)

NextValue returns the next value from a sequence. This is thread-safe and uses atomic operations.

func (*Manager) Persist

func (m *Manager) Persist() error

Persist saves all sequences to disk.

func (*Manager) Reset

func (m *Manager) Reset(name string) error

Reset resets a sequence to its start value.

func (*Manager) SetCurrentValue

func (m *Manager) SetCurrentValue(name string, value int64) error

SetCurrentValue sets the current value of a sequence. This is used for recovery and administrative purposes.

func (*Manager) Stats

func (m *Manager) Stats() Stats

Stats returns statistics about the sequence manager.

type Sequence

type Sequence struct {
	Name        string
	Current     int64
	Increment   int64
	MinValue    int64
	MaxValue    int64
	StartValue  int64
	Cycle       bool
	CacheSize   int32 // Number of values to cache in memory
	CacheEnd    int64 // End of current cache range
	Created     time.Time
	LastUpdated time.Time
}

Sequence represents a named sequence counter.

type SequenceConfig

type SequenceConfig struct {
	Name      string
	Start     int64
	Increment int64
	MinValue  int64
	MaxValue  int64
	Cycle     bool
	CacheSize int32
}

SequenceConfig holds configuration for creating a sequence.

func DefaultSequenceConfig

func DefaultSequenceConfig(name string) SequenceConfig

DefaultSequenceConfig returns default configuration for a sequence.

type Stats

type Stats struct {
	SequenceCount int    `json:"sequence_count"`
	Version       uint64 `json:"version"`
}

Stats holds sequence manager statistics.

type WALLogger

type WALLogger interface {
	LogSequenceCreate(name string, startValue int64) error
	LogSequenceDrop(name string) error
	LogSequenceNext(name string, value int64) error
}

WALLogger defines the interface for WAL logging.

Jump to

Keyboard shortcuts

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