iterator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModeSnapshot represents a snapshot iterator mode.
	ModeSnapshot = "snapshot"
	// ModeCDC represents a CDC iterator mode.
	ModeCDC = "cdc"
)

Variables

View Source
var (
	// ErrNoInitializedIterator occurs when the Combined iterator has no any initialized underlying iterators.
	ErrNoInitializedIterator = errors.New("no initialized iterator")
	// ErrFindAllShardsInKeyspaceReturnedNothing occurs when the vtctl's FindAllShardsInKeyspace command returned nothing.
	ErrFindAllShardsInKeyspaceReturnedNothing = errors.New("FindAllShardsInKeyspace returned nothing")
	// ErrNoIterator occurs when the [Combined] iterator doesn't have any underlying iterators ([Snapshot] or [CDC]).
	ErrNoIterator = errors.New("combined doesn't have an iterator")
)

Functions

This section is empty.

Types

type Combined

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

Combined is a combined iterator that contains both snapshot and cdc iterators.

func NewCombined

func NewCombined(ctx context.Context, params CombinedParams) (*Combined, error)

NewCombined creates new instance of the Combined.

func (*Combined) HasNext

func (c *Combined) HasNext(ctx context.Context) (bool, error)

HasNext returns a bool indicating whether the iterator has the next record to return or not. If the underlying snapshot iterator returns false, the combined iterator will try to switch to the cdc iterator.

func (*Combined) Next

func (c *Combined) Next(ctx context.Context) (sdk.Record, error)

Next returns the next record.

func (*Combined) Stop

func (c *Combined) Stop(ctx context.Context) error

Stop stops the underlying iterators and closes a database connection.

type CombinedParams

type CombinedParams struct {
	Address        string
	Table          string
	KeyColumn      string
	Keyspace       string
	TabletType     string
	OrderingColumn string
	Columns        []string
	BatchSize      int
	Snapshot       bool
	Username       string
	Password       string
	MaxRetries     int
	RetryTimeout   time.Duration
	Position       *Position
}

CombinedParams is an incoming params for the NewCombined function.

type Mode

type Mode string

Mode defines an iterator mode.

type Position

type Position struct {
	Mode Mode `json:"mode"`
	// Keyspace holds a name of a VTGate keyspace that the connector interact with.
	// Mode: snapshot, cdc.
	Keyspace string `json:"keyspace"`
	// LastProcessedElementValue is a value of the element
	// at which the iterator stopped reading rows.
	// The iterator will continue reading from the element if it's not empty.
	// Mode: snapshot, cdc.
	LastProcessedElementValue any `json:"last_processed_element_value,omitempty"`
	// ShardGtids holds a list of shards which the connector will read events from.
	// Mode: cdc.
	ShardGtids []*binlogdata.ShardGtid `json:"shard_gtids,omitempty"`
}

Position is a combined iterator's position.

func ParsePosition

func ParsePosition(sdkPosition sdk.Position) (*Position, error)

ParsePosition converts an sdk.Position into a Position.

func (*Position) MarshalSDKPosition

func (p *Position) MarshalSDKPosition() (sdk.Position, error)

MarshalSDKPosition marshals the underlying position into a sdk.Position as JSON bytes.

Jump to

Keyboard shortcuts

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