segment

package
v0.0.0-...-6029cb0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DSN       string
	TableName string
	Schema    string
}

type Segment

type Segment struct {
	Start   int64 // Inclusive start ID
	End     int64 // Inclusive end ID (max_id)
	Current int64 // Current ID being distributed
}

Segment represents a range of IDs

type SegmentBuffer

type SegmentBuffer struct {
	BizTag int32
	Step   int32

	Current *Segment
	Next    *Segment

	*SegmentIDGen
	// contains filtered or unexported fields
}

SegmentBuffer manages double buffering of segments

func (*SegmentBuffer) NextID

func (b *SegmentBuffer) NextID(ctx context.Context) (int64, error)

NextID gets the next ID with double buffering logic

type SegmentIDGen

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

SegmentIDGen is the main struct for distributed ID generation

func NewSegmentIDGen

func NewSegmentIDGen(ctx context.Context, config Config) (*SegmentIDGen, error)

NewSegmentIDGen creates a new ID generator instance dsn: Postgres connection string

func (*SegmentIDGen) Close

func (g *SegmentIDGen) Close()

Close is a no-op as connection is managed globally

func (*SegmentIDGen) GetID

func (g *SegmentIDGen) GetID(ctx context.Context, bizTag int32) (int64, error)

GetID retrieves the next unique ID for the given bizTag

func (*SegmentIDGen) Init

func (g *SegmentIDGen) Init(ctx context.Context, bizTag int32, startId int64, step int32) error

Init initializes the ID generator for a specific business tag bizTag: Business identifier startId: The starting ID (if not exists) step: The step size for each segment allocation

Jump to

Keyboard shortcuts

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