wal

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRetention     = 1 * time.Hour
	DefaultCheckInterval = 10 * time.Minute
)

Variables

View Source
var (
	ErrEntryNotFound     = errors.New("oxia: entry not found")
	ErrOffsetOutOfBounds = errors.New("oxia: offset out of bounds")
	ErrReaderClosed      = errors.New("oxia: reader already closed")
	ErrInvalidNextOffset = errors.New("oxia: invalid next offset in wal")

	InvalidTerm   int64 = -1
	InvalidOffset int64 = -1
)
View Source
var DefaultFactoryOptions = &FactoryOptions{
	BaseWalDir:  "data/wal",
	Retention:   1 * time.Hour,
	SegmentSize: 64 * 1024 * 1024,
	SyncData:    true,
}

Functions

This section is empty.

Types

type CommitOffsetProvider

type CommitOffsetProvider interface {
	CommitOffset() int64
}

type Factory added in v0.3.0

type Factory interface {
	io.Closer
	NewWal(namespace string, shard int64, provider CommitOffsetProvider) (Wal, error)
}

func NewWalFactory

func NewWalFactory(options *FactoryOptions) Factory

type FactoryOptions added in v0.3.0

type FactoryOptions struct {
	BaseWalDir  string
	Retention   time.Duration
	SegmentSize int32
	SyncData    bool
}

type ReadOnlySegment

type ReadOnlySegment interface {
	io.Closer

	BaseOffset() int64
	LastOffset() int64

	Read(offset int64) ([]byte, error)

	Delete() error

	OpenTimestamp() time.Time
}

type ReadOnlySegmentsGroup

type ReadOnlySegmentsGroup interface {
	io.Closer

	Get(offset int64) (common.RefCount[ReadOnlySegment], error)

	TrimSegments(offset int64) error

	AddedNewSegment(baseOffset int64)

	PollHighestSegment() (common.RefCount[ReadOnlySegment], error)
}

type ReadWriteSegment

type ReadWriteSegment interface {
	ReadOnlySegment

	Append(offset int64, data []byte) error

	Truncate(lastSafeOffset int64) error

	HasSpace(l int) bool

	Flush() error
}

type Reader added in v0.3.0

type Reader interface {
	io.Closer
	// ReadNext returns the next entry in the log according to the Reader's direction.
	// If a forward/reverse WalReader has passed the end/beginning of the log, it returns [ErrorEntryNotFound].
	// To avoid this error, use HasNext.
	ReadNext() (*proto.LogEntry, error)
	// HasNext returns true if there is an entry to read.
	HasNext() bool
}

Reader reads the Wal sequentially. It is not synchronized itself.

type Trimmer

type Trimmer interface {
	io.Closer
}

type Wal

type Wal interface {
	io.Closer
	// Append writes an entry to the end of the log.
	// The wal is synced when Append returns
	Append(entry *proto.LogEntry) error

	// AppendAsync an entry without syncing the WAL
	// Caller should use Sync to make the entry visible
	AppendAsync(entry *proto.LogEntry) error

	// Sync flushes all the entries in the wal to disk
	Sync(ctx context.Context) error

	// TruncateLog removes entries from the end of the log that have an ID greater than lastSafeEntry.
	TruncateLog(lastSafeEntry int64) (int64, error)

	// NewReader returns a new WalReader to traverse the log from the entry after `after` towards the log end
	NewReader(after int64) (Reader, error)
	// NewReverseReader returns a new WalReader to traverse the log from the last entry towards the beginning
	NewReverseReader() (Reader, error)

	// LastOffset Return the offset of the last entry committed to the WAL
	// Return InvalidOffset if the WAL is empty
	LastOffset() int64

	// FirstOffset Return the offset of the first valid entry that is present in the WAL
	// Return InvalidOffset if the WAL is empty
	FirstOffset() int64

	// Clear removes all the entries in the WAL
	Clear() error

	// Delete all the files and directories of the wal
	Delete() error
}

Jump to

Keyboard shortcuts

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