wal

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	SUFFIX = ".log"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Closer

type Closer interface {
	Close() error
}

type Reader

type Reader interface {
	Read() (*common.Chunk, error)
}

type ReaderCloser

type ReaderCloser interface {
	Reader
	Closer
}

func NewReaderCloser

func NewReaderCloser(filepath string) (ReaderCloser, error)

NewReaderCloser creates and returns a new WalReaderCloser instance initialized with the provided file path. It opens the file in read-write mode and wraps it into a Wal struct which implements ReaderCloser interface. If the file cannot be opened, an error is returned. The WalReaderCloser allows reading from and closing the Write-Ahead Log (WAL) file.

type Wal

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

func (*Wal) Close

func (w *Wal) Close() error

Close synchronously flushes any unwritten data to disk, closes the WAL file, and removes the file from the filesystem. Returns an error if any of these operations fail.

func (*Wal) Read

func (w *Wal) Read() (*common.Chunk, error)

Read decodes the next chunk from the Write-Ahead Log (WAL), verifying its integrity using CRC checksum. It returns a pointer to a Chunk which includes the key-value pair, and a boolean indicating deletion. If the chunk is marked as deleted, the value will be nil. It returns an error if any read operation fails or if the checksum does not match.

func (*Wal) Sync

func (w *Wal) Sync() error

Sync ensures that any buffered data in the Write-Ahead Log (WAL) is written to the disk and flushed. It returns an error if the synchronization operation fails.

func (*Wal) Write

func (w *Wal) Write(chunk *common.Chunk) error

Write encodes the provided chunk using the utility encoder, then writes the encoded bytes to the WAL file. Returns an error if encoding fails or writing to the file encounters an issue.

type Writer

type Writer interface {
	Write(*common.Chunk) error
}

type WriterCloser

type WriterCloser interface {
	Writer
	Closer
}

func NewWriterCloser

func NewWriterCloser(walDir string) (WriterCloser, error)

NewWriterCloser creates and returns a new WriterCloser instance initialized with a Write-Ahead Log (WAL) file located in the specified directory. The filename is generated based on the current time and appended with a predefined suffix. It opens the file for writing, creating it if necessary, and wraps it within a Wal structure. Returns a WriterCloser interface and an error if the file operation fails.

Jump to

Keyboard shortcuts

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