tso

package
v0.10.3-0...-caf207f Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// UpdateTimestampStep is used to update timestamp.
	UpdateTimestampStep = 50 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator interface {
	// Initialize is used to initialize a TSO allocator.
	// It will synchronize TSO with etcd and initialize the
	// memory for later allocation work.
	Initialize() error
	// UpdateTSO is used to update the TSO in memory and the time window in etcd.
	UpdateTSO() error
	// SetTSO sets the physical part with given tso. It's mainly used for BR restore
	// and can not forcibly set the TSO smaller than now.
	SetTSO(tso uint64) error
	// GenerateTSO is used to generate a given number of TSOs.
	// Make sure you have initialized the TSO allocator before calling.
	GenerateTSO(count uint32) (uint64, error)
	// Reset is used to reset the TSO allocator.
	Reset()

	GetLastSavedTime() time.Time
}

Allocator is a Timestamp Oracle allocator.

type GlobalTSOAllocator

type GlobalTSOAllocator struct {
	LimitMaxLogic bool
	// contains filtered or unexported fields
}

GlobalTSOAllocator is the global single point TSO allocator.

func NewGlobalTSOAllocator

func NewGlobalTSOAllocator(key string, txnKV kv.TxnKV) *GlobalTSOAllocator

NewGlobalTSOAllocator creates a new global TSO allocator.

func (*GlobalTSOAllocator) Alloc

func (gta *GlobalTSOAllocator) Alloc(count uint32) (typeutil.Timestamp, error)

Alloc allocates a batch of timestamps. What is returned is the starting timestamp.

func (*GlobalTSOAllocator) AllocOne

func (gta *GlobalTSOAllocator) AllocOne() (typeutil.Timestamp, error)

AllocOne only allocates one timestamp.

func (*GlobalTSOAllocator) GenerateTSO

func (gta *GlobalTSOAllocator) GenerateTSO(count uint32) (uint64, error)

GenerateTSO is used to generate a given number of TSOs. Make sure you have initialized the TSO allocator before calling.

func (*GlobalTSOAllocator) GetLastSavedTime

func (gta *GlobalTSOAllocator) GetLastSavedTime() time.Time

GetLastSavedTime get the last saved time for tso.

func (*GlobalTSOAllocator) Initialize

func (gta *GlobalTSOAllocator) Initialize() error

Initialize will initialize the created global TSO allocator.

func (*GlobalTSOAllocator) Reset

func (gta *GlobalTSOAllocator) Reset()

Reset is used to reset the TSO allocator.

func (*GlobalTSOAllocator) SetLimitMaxLogic

func (gta *GlobalTSOAllocator) SetLimitMaxLogic(flag bool)

SetLimitMaxLogic is to enable or disable the maximum limit on the logical part of the hybrid timestamp. When enabled, if the logical part of the hybrid timestamp exceeds the maximum limit, GlobalTSOAllocator will sleep for a period and try to allocate the timestamp again.

func (*GlobalTSOAllocator) SetTSO

func (gta *GlobalTSOAllocator) SetTSO(tso uint64) error

SetTSO sets the physical part with given tso.

func (*GlobalTSOAllocator) UpdateTSO

func (gta *GlobalTSOAllocator) UpdateTSO() error

UpdateTSO is used to update the TSO in memory and the time window in etcd.

type MockAllocator

type MockAllocator struct {
	Allocator
	InitializeF       func() error
	UpdateTSOF        func() error
	SetTSOF           func(tso uint64) error
	GenerateTSOF      func(count uint32) (uint64, error)
	ResetF            func()
	GetLastSavedTimeF func() time.Time
}

func NewMockAllocator

func NewMockAllocator() *MockAllocator

func (MockAllocator) GenerateTSO

func (m MockAllocator) GenerateTSO(count uint32) (uint64, error)

func (MockAllocator) GetLastSavedTime

func (m MockAllocator) GetLastSavedTime() time.Time

func (MockAllocator) Initialize

func (m MockAllocator) Initialize() error

func (MockAllocator) Reset

func (m MockAllocator) Reset()

func (MockAllocator) SetTSO

func (m MockAllocator) SetTSO(tso uint64) error

func (MockAllocator) UpdateTSO

func (m MockAllocator) UpdateTSO() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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