wal

package
v0.0.0-...-08e4fbc Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Closer

type Closer interface {
	Close() error
}

Closer is the interface that groups the Close methods.

type Commit

type Commit func() error

Commit is a function for committing an event log

type EventHandler

type EventHandler interface {
	Typ() string
	Check(context.Context, any) (need bool, err error)
	Encode(any) ([]byte, error)
	Decode([]byte) (any, error)
	Handle(context.Context, any) error
}

EventHandler is the interface that groups a few methods.

type Hydro

type Hydro struct {
	*haxmap.Map[string, EventHandler]
	// contains filtered or unexported fields
}

Hydro is the simplest wal implementation.

func NewHydro

func NewHydro(path string, timeout time.Duration) (*Hydro, error)

NewHydro initailizes a new Hydro instance.

func (*Hydro) Close

func (h *Hydro) Close() error

Close disconnects the kvdb.

func (*Hydro) Log

func (h *Hydro) Log(eventyp string, item any) (Commit, error)

Log records a log item.

func (*Hydro) Recover

func (h *Hydro) Recover(ctx context.Context)

Recover starts a disaster recovery, which will replay all the events.

func (*Hydro) Register

func (h *Hydro) Register(handler EventHandler)

Register registers a new event handler.

type HydroEvent

type HydroEvent struct {
	// A global unique identifier.
	ID uint64 `json:"ID"`

	// Registered event type name.
	Type string `json:"type"`

	// The encoded log item.
	Item []byte `json:"item"`
}

HydroEvent indicates a log event.

func NewHydroEvent

func NewHydroEvent(ID uint64, typ string, item []byte) *HydroEvent

NewHydroEvent initializes a new HydroEvent instance.

func (HydroEvent) Encode

func (e HydroEvent) Encode() ([]byte, error)

Encode this event

func (HydroEvent) Key

func (e HydroEvent) Key() []byte

Key returns this event's key path.

type Logger

type Logger interface {
	Log(string, any) (Commit, error)
}

Logger is the interface that wraps the basic Log method.

type Recoverer

type Recoverer interface {
	Recover(context.Context)
}

Recoverer is the interface that wraps the basic Recover method.

type Registry

type Registry interface {
	Register(EventHandler)
}

Registry is the interface that wraps the basic Register method.

type WAL

type WAL interface {
	Registry
	Recoverer
	Logger
	Closer
}

WAL is the interface that groups the Register and Recover interfaces.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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