logrepl

package
v0.7.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup added in v0.7.1

func Cleanup(ctx context.Context, c CleanupConfig) error

Cleanup drops the provided replication slot and publication. It will terminate any backends consuming the replication slot before deletion.

Types

type CDCConfig added in v0.7.1

type CDCConfig struct {
	LSN             pglogrepl.LSN
	SlotName        string
	PublicationName string
	Tables          []string
	TableKeys       map[string]string
}

Config holds configuration values for CDCIterator.

type CDCHandler

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

CDCHandler is responsible for handling logical replication messages, converting them to a record and sending them to a channel.

func NewCDCHandler

func NewCDCHandler(
	rs *internal.RelationSet,
	tableKeys map[string]string,
	out chan<- sdk.Record,
) *CDCHandler

func (*CDCHandler) Handle

func (h *CDCHandler) Handle(ctx context.Context, m pglogrepl.Message, lsn pglogrepl.LSN) error

Handle is the handler function that receives all logical replication messages.

type CDCIterator

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

CDCIterator asynchronously listens for events from the logical replication slot and returns them to the caller through Next.

func NewCDCIterator

func NewCDCIterator(ctx context.Context, pgconf *pgconn.Config, c CDCConfig) (*CDCIterator, error)

NewCDCIterator initializes logical replication by creating the publication and subscription manager.

func (*CDCIterator) Ack

func (i *CDCIterator) Ack(_ context.Context, sdkPos sdk.Position) error

Ack forwards the acknowledgment to the subscription.

func (*CDCIterator) Next

func (i *CDCIterator) Next(ctx context.Context) (sdk.Record, error)

Next returns the next record retrieved from the subscription. This call will block until either a record is returned from the subscription, the subscription stops because of an error or the context gets canceled. Returns error when the subscription has been started.

func (*CDCIterator) StartSubscriber added in v0.7.1

func (i *CDCIterator) StartSubscriber(ctx context.Context) error

StartSubscriber starts the logical replication service in the background. Blocks until the subscription becomes ready.

func (*CDCIterator) TXSnapshotID added in v0.7.1

func (i *CDCIterator) TXSnapshotID() string

TXSnapshotID returns the transaction snapshot which is received when the replication slot is created. The value can be empty, when the iterator is resuming.

func (*CDCIterator) Teardown

func (i *CDCIterator) Teardown(ctx context.Context) error

Teardown stops the CDC subscription and blocks until the subscription is done or the context gets canceled. If the subscription stopped with an unexpected error, the error is returned.

type CleanupConfig added in v0.7.1

type CleanupConfig struct {
	URL             string
	SlotName        string
	PublicationName string
}

type CombinedIterator added in v0.7.1

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

func NewCombinedIterator added in v0.7.1

func NewCombinedIterator(ctx context.Context, pool *pgxpool.Pool, conf Config) (*CombinedIterator, error)

NewCombinedIterator will initialize and start the Snapshot and CDC iterators. Failure to parse the position or validate the config will return an error.

func (*CombinedIterator) Ack added in v0.7.1

func (*CombinedIterator) Next added in v0.7.1

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

Next provides the next available record from the snapshot or CDC stream. If the end of the snapshot is reached, next will switch to the CDC iterator and retrive the next available record. Failure to switch the iterator will return an error.

func (*CombinedIterator) Teardown added in v0.7.1

func (c *CombinedIterator) Teardown(ctx context.Context) error

Teardown will stop and teardown the CDC and Snapshot iterators.

type Config

type Config struct {
	Position        sdk.Position
	SlotName        string
	PublicationName string
	Tables          []string
	TableKeys       map[string]string
	WithSnapshot    bool
}

func (Config) Validate added in v0.7.1

func (c Config) Validate() error

Validate performs validation tasks on the config.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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