allocator

package
v0.10.3-0...-8c9dab5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRequest

type BaseRequest struct {
	Done  chan error
	Valid bool
}

BaseRequest implements Request interface.

func (*BaseRequest) Notify

func (req *BaseRequest) Notify(err error)

Notify is used to send error to the requester.

func (*BaseRequest) Wait

func (req *BaseRequest) Wait() error

Wait is blocked until the request is allocated or an error occurs.

type CachedAllocator

type CachedAllocator struct {
	Ctx        context.Context
	CancelFunc context.CancelFunc

	Reqs      chan Request
	ToDoReqs  []Request
	CanDoReqs []Request
	SyncReqs  []Request

	TChan         TickerChan
	ForceSyncChan chan Request

	SyncFunc    func() (bool, error)
	ProcessFunc func(req Request) error

	CheckSyncFunc func(timeout bool) bool
	PickCanDoFunc func()
	SyncErr       error
	Role          string
	// contains filtered or unexported fields
}

Allocator allocates from a global allocator by its given member functions

func (*CachedAllocator) CleanCache

func (ta *CachedAllocator) CleanCache()

CleanCache is used to force synchronize with global allocator.

func (*CachedAllocator) Close

func (ta *CachedAllocator) Close()

Close mainly stop the internal coroutine and recover resources.

func (*CachedAllocator) Init

func (ta *CachedAllocator) Init()

Init mainly initialize internal members.

func (*CachedAllocator) Start

func (ta *CachedAllocator) Start() error

Start starts the loop of checking whether to synchronize with the global allocator.

type EmptyTicker

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

EmptyTicker implements TickerChan, but it will never issue a signal in Chan.

func (*EmptyTicker) Chan

func (t *EmptyTicker) Chan() <-chan time.Time

Chan returns a read-only channel from which you can only receive time.Time type data. As for EmptyTicker, you will never read data from Chan.

func (*EmptyTicker) Close

func (t *EmptyTicker) Close()

Close does nothing.

func (*EmptyTicker) Init

func (t *EmptyTicker) Init()

Init does nothing.

func (*EmptyTicker) Reset

func (t *EmptyTicker) Reset()

Reset does nothing.

type GlobalIDAllocator

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

GlobalIDAllocator is the global single point TSO allocator.

func NewGlobalIDAllocator

func NewGlobalIDAllocator(key string, base kv.TxnKV) *GlobalIDAllocator

NewGlobalIDAllocator creates GlobalIDAllocator for allocates ID.

func (*GlobalIDAllocator) Alloc

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

func (*GlobalIDAllocator) AllocOne

func (gia *GlobalIDAllocator) AllocOne() (typeutil.UniqueID, error)

AllocOne allocates one id.

func (*GlobalIDAllocator) Initialize

func (gia *GlobalIDAllocator) Initialize() error

Initialize will initialize the created global TSO allocator.

type GlobalIDAllocatorInterface

type GlobalIDAllocatorInterface interface {
	// Initialize will initialize the created global TSO allocator.
	Initialize() error
	// Alloc allocates the id of the count number.
	Alloc(count uint32) (typeutil.UniqueID, typeutil.UniqueID, error)
	// AllocOne allocates one id.
	AllocOne() (typeutil.UniqueID, error)
}

type IDAllocator

type IDAllocator struct {
	CachedAllocator

	PeerID UniqueID
	// contains filtered or unexported fields
}

IDAllocator allocates Unique and monotonically increasing IDs from Root Coord. It could also batch allocate for less root coord server access

func NewIDAllocator

func NewIDAllocator(ctx context.Context, remoteAllocator remoteInterface, peerID UniqueID) (*IDAllocator, error)

NewIDAllocator creates an ID Allocator allocate Unique and monotonically increasing IDs from RootCoord.

func (*IDAllocator) Alloc

func (ia *IDAllocator) Alloc(count uint32) (UniqueID, UniqueID, error)

Alloc allocates the id of the count number.

func (*IDAllocator) AllocOne

func (ia *IDAllocator) AllocOne() (UniqueID, error)

AllocOne allocates one id.

func (*IDAllocator) Start

func (ia *IDAllocator) Start() error

Start creates some working goroutines of IDAllocator.

type IDRequest

type IDRequest struct {
	BaseRequest
	// contains filtered or unexported fields
}

IDRequest implements Request and is used to get global unique Identities.

type Interface

type Interface interface {
	Alloc(count uint32) (UniqueID, UniqueID, error)
	AllocOne() (UniqueID, error)
}

Allocator interface is an interface for alloc id. Alloc allocates the id of the count number. AllocOne allocates one id. See GlobalIDAllocator for implementation details

func NewLocalAllocator

func NewLocalAllocator(start, end int64) Interface

type MockAllocator

type MockAllocator struct {
	mock.Mock
}

MockAllocator is an autogenerated mock type for the Interface type

func NewMockAllocator

func NewMockAllocator(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockAllocator

NewMockAllocator creates a new instance of MockAllocator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockAllocator) Alloc

func (_m *MockAllocator) Alloc(count uint32) (int64, int64, error)

Alloc provides a mock function with given fields: count

func (*MockAllocator) AllocOne

func (_m *MockAllocator) AllocOne() (int64, error)

AllocOne provides a mock function with given fields:

func (*MockAllocator) EXPECT

func (_m *MockAllocator) EXPECT() *MockAllocator_Expecter

type MockAllocator_AllocOne_Call

type MockAllocator_AllocOne_Call struct {
	*mock.Call
}

MockAllocator_AllocOne_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllocOne'

func (*MockAllocator_AllocOne_Call) Return

func (*MockAllocator_AllocOne_Call) Run

func (*MockAllocator_AllocOne_Call) RunAndReturn

func (_c *MockAllocator_AllocOne_Call) RunAndReturn(run func() (int64, error)) *MockAllocator_AllocOne_Call

type MockAllocator_Alloc_Call

type MockAllocator_Alloc_Call struct {
	*mock.Call
}

MockAllocator_Alloc_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Alloc'

func (*MockAllocator_Alloc_Call) Return

func (*MockAllocator_Alloc_Call) Run

func (_c *MockAllocator_Alloc_Call) Run(run func(count uint32)) *MockAllocator_Alloc_Call

func (*MockAllocator_Alloc_Call) RunAndReturn

func (_c *MockAllocator_Alloc_Call) RunAndReturn(run func(uint32) (int64, int64, error)) *MockAllocator_Alloc_Call

type MockAllocator_Expecter

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

func (*MockAllocator_Expecter) Alloc

func (_e *MockAllocator_Expecter) Alloc(count interface{}) *MockAllocator_Alloc_Call

Alloc is a helper method to define mock.On call

  • count uint32

func (*MockAllocator_Expecter) AllocOne

AllocOne is a helper method to define mock.On call

type MockGIDAllocator

type MockGIDAllocator struct {
	Interface
	AllocF    func(count uint32) (UniqueID, UniqueID, error)
	AllocOneF func() (UniqueID, error)
	UpdateIDF func() error
}

func NewMockGIDAllocator

func NewMockGIDAllocator() *MockGIDAllocator

func (MockGIDAllocator) Alloc

func (m MockGIDAllocator) Alloc(count uint32) (UniqueID, UniqueID, error)

func (MockGIDAllocator) AllocOne

func (m MockGIDAllocator) AllocOne() (UniqueID, error)

func (MockGIDAllocator) UpdateID

func (m MockGIDAllocator) UpdateID() error

type MockGlobalIDAllocator

type MockGlobalIDAllocator struct {
	mock.Mock
}

MockGlobalIDAllocator is an autogenerated mock type for the GlobalIDAllocatorInterface type

func NewMockGlobalIDAllocator

func NewMockGlobalIDAllocator(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockGlobalIDAllocator

NewMockGlobalIDAllocator creates a new instance of MockGlobalIDAllocator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockGlobalIDAllocator) Alloc

func (_m *MockGlobalIDAllocator) Alloc(count uint32) (int64, int64, error)

Alloc provides a mock function with given fields: count

func (*MockGlobalIDAllocator) AllocOne

func (_m *MockGlobalIDAllocator) AllocOne() (int64, error)

AllocOne provides a mock function with given fields:

func (*MockGlobalIDAllocator) EXPECT

func (*MockGlobalIDAllocator) Initialize

func (_m *MockGlobalIDAllocator) Initialize() error

Initialize provides a mock function with given fields:

type MockGlobalIDAllocator_AllocOne_Call

type MockGlobalIDAllocator_AllocOne_Call struct {
	*mock.Call
}

MockGlobalIDAllocator_AllocOne_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllocOne'

func (*MockGlobalIDAllocator_AllocOne_Call) Return

func (*MockGlobalIDAllocator_AllocOne_Call) Run

func (*MockGlobalIDAllocator_AllocOne_Call) RunAndReturn

type MockGlobalIDAllocator_Alloc_Call

type MockGlobalIDAllocator_Alloc_Call struct {
	*mock.Call
}

MockGlobalIDAllocator_Alloc_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Alloc'

func (*MockGlobalIDAllocator_Alloc_Call) Return

func (*MockGlobalIDAllocator_Alloc_Call) Run

func (*MockGlobalIDAllocator_Alloc_Call) RunAndReturn

type MockGlobalIDAllocator_Expecter

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

func (*MockGlobalIDAllocator_Expecter) Alloc

Alloc is a helper method to define mock.On call

  • count uint32

func (*MockGlobalIDAllocator_Expecter) AllocOne

AllocOne is a helper method to define mock.On call

func (*MockGlobalIDAllocator_Expecter) Initialize

Initialize is a helper method to define mock.On call

type MockGlobalIDAllocator_Initialize_Call

type MockGlobalIDAllocator_Initialize_Call struct {
	*mock.Call
}

MockGlobalIDAllocator_Initialize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Initialize'

func (*MockGlobalIDAllocator_Initialize_Call) Return

func (*MockGlobalIDAllocator_Initialize_Call) Run

func (*MockGlobalIDAllocator_Initialize_Call) RunAndReturn

type Request

type Request interface {
	Wait() error
	Notify(error)
}

Request defines an interface which has Wait and Notify methods.

type SyncRequest

type SyncRequest struct {
	BaseRequest
}

SyncRequest embeds BaseRequest and is used to force synchronize from RootCoordinator.

type Ticker

type Ticker struct {
	UpdateInterval time.Duration
	// contains filtered or unexported fields
}

Ticker implements TickerChan and is a simple wrapper for time.TimeTicker.

func (*Ticker) Chan

func (t *Ticker) Chan() <-chan time.Time

Chan return a read-only channel from which you can only receive time.Time type data

func (*Ticker) Close

func (t *Ticker) Close()

Close closes the inner member `ticker`.

func (*Ticker) Init

func (t *Ticker) Init()

Init initialize the inner member `ticker` whose type is a pointer to time.Ticker.

func (*Ticker) Reset

func (t *Ticker) Reset()

Reset resets the inner member `ticker`.

type TickerChan

type TickerChan interface {
	Chan() <-chan time.Time
	Close()
	Init()
	Reset()
}

TickerChan defines an interface.

type UniqueID

type UniqueID = typeutil.UniqueID

UniqueID is alias of typeutil.UniqueID

Jump to

Keyboard shortcuts

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