wal

package
v0.0.0-...-34e0b2d Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUpstreamClosed = errors.New("upstream closed")

Functions

This section is empty.

Types

type MessageFilter

type MessageFilter = func(message.ImmutableMessage) bool

type MessageHandler

type MessageHandler interface {
	// Handle is the callback for handling message.
	// The message will be passed to the handler for processing.
	// Handle operation can be blocked, but should listen to the context.Done() and upstream.
	// If the context is canceled, the handler should return immediately with ctx.Err.
	// If the upstream is closed, the handler should return immediately with ErrUpstreamClosed.
	// If the upstream recv a message, the handler should return the incoming message.
	// If the handler handle the message successfully, it should return the ok=true.
	Handle(ctx context.Context, upstream <-chan message.ImmutableMessage, msg message.ImmutableMessage) (incoming message.ImmutableMessage, ok bool, err error)

	// Close is called after all messages are handled or handling is interrupted.
	Close()
}

MessageHandler is used to handle message read from log. TODO: should be removed in future after msgstream is removed.

type OpenOption

type OpenOption struct {
	Channel types.PChannelInfo
}

OpenOption is the option for allocating wal instance.

type Opener

type Opener interface {
	// Open open a wal instance.
	Open(ctx context.Context, opt *OpenOption) (WAL, error)

	// Close closes the opener resources.
	Close()
}

Opener is the interface for build wal instance.

type OpenerBuilder

type OpenerBuilder interface {
	// Name of the wal builder, should be a lowercase string.
	Name() string

	Build() (Opener, error)
}

OpenerBuilder is the interface for build wal opener.

type ReadOption

type ReadOption struct {
	DeliverPolicy  options.DeliverPolicy
	MessageFilter  MessageFilter
	MesasgeHandler MessageHandler // message handler for message processing.

}

ReadOption is the option for reading records from the wal.

type Scanner

type Scanner interface {
	// Chan returns the channel of message if Option.MessageHandler is nil.
	Chan() <-chan message.ImmutableMessage

	// Channel returns the channel assignment info of the wal.
	Channel() types.PChannelInfo

	// Error returns the error of scanner failed.
	// Will block until scanner is closed or Chan is dry out.
	Error() error

	// Done returns a channel which will be closed when scanner is finished or closed.
	Done() <-chan struct{}

	// Close the scanner, release the underlying resources.
	// Return the error same with `Error`
	Close() error
}

Scanner is the interface for reading records from the wal.

type WAL

type WAL interface {
	WALName() string

	// Channel returns the channel assignment info of the wal.
	Channel() types.PChannelInfo

	// Append writes a record to the log.
	Append(ctx context.Context, msg message.MutableMessage) (message.MessageID, error)

	// Append a record to the log asynchronously.
	AppendAsync(ctx context.Context, msg message.MutableMessage, cb func(message.MessageID, error))

	// Read returns a scanner for reading records from the wal.
	Read(ctx context.Context, deliverPolicy ReadOption) (Scanner, error)

	// Available return a channel that will be closed when the wal is available.
	Available() <-chan struct{}

	// IsAvailable returns if the wal is available.
	IsAvailable() bool

	// Close closes the wal instance.
	Close()
}

WAL is the WAL framework interface. !!! Don't implement it directly, implement walimpls.WAL instead.

Jump to

Keyboard shortcuts

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