wal

package
v0.0.0-...-3a73a5e Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxRead = 110 * 1024 * 1024 // 110MB
)

Variables

View Source
var (
	ErrExpectHeader         = fmt.Errorf("expect having header before writing data")
	ErrHeaderAlreadyWritten = fmt.Errorf("header is already written")
)

Functions

func OpenWithHeader

func OpenWithHeader(filepPath string) (wlog *WalLog, h *Header, err error)

OpenWithHeader opens the wallog and returns the header of the log, it's up to the caller to close the wal file

Types

type Header struct {
	EventLogVersion string     `json:"log_version"`
	OrgID           string     `json:"org_id"`
	SessionID       string     `json:"session_id"`
	UserID          string     `json:"user_id"`
	UserName        string     `json:"user_name"`
	UserEmail       string     `json:"user_email"`
	ConnectionName  string     `json:"connection_name"`
	ConnectionType  string     `json:"connection_type"`
	Status          string     `json:"status"`
	Script          string     `json:"script"`
	Labels          string     `json:"labels"` // we save it as string and convert at storage layer
	Verb            string     `json:"verb"`
	StartDate       *time.Time `json:"start_date"`
}

func (*Header) Validate

func (h *Header) Validate() error

type ReaderFunc

type ReaderFunc func(eventLog []byte) error

type WalLog

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

func Open

func Open(filePath string) (*WalLog, error)

Open opens a wal file with default options, it's up to the caller to close the wal file

func OpenWriteHeader

func OpenWriteHeader(filepPath string, h *Header) (*WalLog, error)

OpenWithHeader opens the wallog and write the header, it's up to the caller to close the wal file

func (*WalLog) Close

func (w *WalLog) Close() error

func (*WalLog) Header

func (w *WalLog) Header() (*Header, error)

Header retrieves the header from the wal file

func (*WalLog) ReadAtMost

func (w *WalLog) ReadAtMost(max uint32, readerFn ReaderFunc) (bool, error)

ReadAtMost reads event logs from a write ahead log up to max bytes specified. It returns a boolean indicading if it's truncated. It's up to the caller to decode the event log properly using a decoder.

func (*WalLog) ReadFull

func (w *WalLog) ReadFull(readerFn ReaderFunc) (bool, error)

ReadFull reads events from the write ahead log until it reaches it max default size.

func (*WalLog) Write

func (w *WalLog) Write(event eventlog.Encoder) error

Write add the event to the write ahead log file. It supports writing any object that implements the eventlog.Encoder interface

func (*WalLog) WriteHeader

func (w *WalLog) WriteHeader(h *Header) error

WriteHeader writes h in the first position of the log

Jump to

Keyboard shortcuts

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