sync2

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 47

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batcher

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

Batcher delays concurrent operations for a configurable interval in order to batch them up or otherwise clock their operation to run concurrently.

It is implemented as a channel of int32s. Each waiter blocks on the channel from which it gets a sequentially increasing batch ID when the timer elapses.

Hence a waiter is delayed for at most the batch interval.

func NewBatcher

func NewBatcher(interval time.Duration) *Batcher

NewBatcher returns a new Batcher

func (*Batcher) Wait

func (b *Batcher) Wait() int

Wait adds a new waiter to the queue and blocks until the next batch

type Consolidator

type Consolidator interface {
	Create(string) (PendingResult, bool)
	Items() []ConsolidatorCacheItem
	Record(query string)
}

Consolidator consolidates duplicate queries from executing simulaneously and shares results between them.

func NewConsolidator

func NewConsolidator() Consolidator

NewConsolidator creates a new Consolidator

type ConsolidatorCache

type ConsolidatorCache struct {
	*cache.LRUCache[*ccount]
}

ConsolidatorCache is a thread-safe object used for counting how often recent queries have been consolidated. It is also used by the txserializer package to count how often transactions have been queued and had to wait because they targeted the same row (range).

func NewConsolidatorCache

func NewConsolidatorCache(capacity int64) *ConsolidatorCache

NewConsolidatorCache creates a new cache with the given capacity.

func (*ConsolidatorCache) Items

Items returns the items in the cache as an array of String, int64 structs

func (*ConsolidatorCache) Record

func (cc *ConsolidatorCache) Record(query string)

Record increments the count for "query" by 1. If it's not in the cache yet, it will be added.

type ConsolidatorCacheItem

type ConsolidatorCacheItem struct {
	Query string
	Count int64
}

ConsolidatorCacheItem is a wrapper for the items in the consolidator cache

type FakeConsolidator added in v0.17.0

type FakeConsolidator struct {
	// CreateCalls can be used to inspect Create calls.
	CreateCalls []string
	// CreateReturns can be used to inspect Create return values.
	CreateReturns []*FakeConsolidatorCreateReturn
	// CreateReturnCreated pre-configures the return value of Create calls.
	CreateReturn *FakeConsolidatorCreateReturn
	// RecordCalls can be usd to inspect Record calls.
	RecordCalls []string
}

FakeConsolidator satisfies the Consolidator interface and can be used to mock how Vitess interacts with the Consolidator.

func NewFakeConsolidator added in v0.17.0

func NewFakeConsolidator() *FakeConsolidator

NewFakeConsolidator creates a new FakeConsolidator.

func (*FakeConsolidator) Create added in v0.17.0

func (fc *FakeConsolidator) Create(sql string) (PendingResult, bool)

Create records the Create call for later verification, and returns a pre-configured PendingResult and "created" bool.

func (*FakeConsolidator) Items added in v0.17.0

Items is currently a no-op.

func (*FakeConsolidator) Record added in v0.17.0

func (fc *FakeConsolidator) Record(sql string)

Record records the Record call for later verification.

type FakeConsolidatorCreateReturn added in v0.17.0

type FakeConsolidatorCreateReturn struct {
	// PendingResult contains the PendingResult return value of a call to
	// FakeConsolidator.Create.
	PendingResult
	// PendingResult contains the Created return value of a call to
	// FakeConsolidator.Create.
	Created bool
}

FakeConsolidatorCreateReturn wraps the two return values of a call to FakeConsolidator.Create.

type FakePendingResult added in v0.17.0

type FakePendingResult struct {
	// BroadcastCalls can be used to inspect Broadcast calls.
	BroadcastCalls int
	// WaitCalls can be used to inspect Wait calls.
	WaitCalls int
	// contains filtered or unexported fields
}

FakePendingResult satisfies the PendingResult interface and can be used to mock how Vitess interacts with the Consolidator.

func (*FakePendingResult) Broadcast added in v0.17.0

func (fr *FakePendingResult) Broadcast()

Broadcast records the Broadcast call for later verification.

func (*FakePendingResult) Err added in v0.17.0

func (fr *FakePendingResult) Err() error

Err returns the pre-configured error.

func (*FakePendingResult) Result added in v0.17.0

func (fr *FakePendingResult) Result() *sqltypes.Result

Result returns the pre-configured Result.

func (*FakePendingResult) SetErr added in v0.17.0

func (fr *FakePendingResult) SetErr(err error)

SetErr stores the err, which can be retrieved with Err.

func (*FakePendingResult) SetResult added in v0.17.0

func (fr *FakePendingResult) SetResult(result *sqltypes.Result)

SetResult stores the result, which can be retrieved with Result.

func (*FakePendingResult) Wait added in v0.17.0

func (fr *FakePendingResult) Wait()

Wait records the Wait call for later verification.

type PendingResult added in v0.17.0

type PendingResult interface {
	Broadcast()
	Err() error
	SetErr(error)
	SetResult(*sqltypes.Result)
	Result() *sqltypes.Result
	Wait()
}

PendingResult is a wrapper for result of a query.

Jump to

Keyboard shortcuts

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