journal

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package journal implements WAL-like append-only “journal” files.

Intended use cases:

  1. Database WAL files.
  2. Log files of various kinds.
  3. Archival of historical database records.

Features:

  1. Suitable for records of all sizes, from very short to very long. Long records can be written to the file in chunks. Multiple short records can be combined into a single transaction with minimal overhead.

  2. Crash-resistant (if followed by an fsync). Contains a CRC32 checksum of each record, and automatically trims the file after the first corrupted record.

  3. Performant.

  4. Automatically rotates the files when they reach a certain size. (You can also trigger the rotation programmatically at any time.)

  5. Manages segment file namingю

The

File format: segmentHeader (recordHeader bytes* padding* recordTrailer)

  • file = segmentHeader record*
  • segmentHeader = magic:64 segmentNumber:32 flags:32 prevChecksum:64 fixedMarker:64*4 segmentMarker:64*4 checksum:64
  • header = magic:64 seq:32 fe:16 se:16 flags:64
  • record = flagsAndSize:uvarint timestamp:32? bytes* checksum:64?

Index

Constants

View Source
const DefaultMaxFileSize = 4 * 1024 * 1024
View Source
const IgnorableTimestampDriftSeconds = 10

Variables

View Source
var (
	ErrIncompatible       = fmt.Errorf("incompatible journal")
	ErrUnsupportedVersion = fmt.Errorf("unsupported journal version")
)

Functions

This section is empty.

Types

type Journal

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

Journal represents a set of AOFs.

func New

func New(dir string, o Options) *Journal

func (*Journal) Commit

func (j *Journal) Commit() error

func (*Journal) FinishWriting

func (j *Journal) FinishWriting()

func (*Journal) Now

func (j *Journal) Now() uint32

func (*Journal) StartWriting

func (j *Journal) StartWriting()

func (*Journal) String

func (j *Journal) String() string

func (*Journal) WriteRecord

func (j *Journal) WriteRecord(timestamp uint32, data []byte) error

type Options

type Options struct {
	Context          context.Context
	FileName         string // e.g. "mydb-*.bin"
	MaxFileSize      int64  // new segment after this size
	DebugName        string
	Now              func() time.Time
	JournalInvariant [32]byte
	SegmentInvariant [32]byte

	Logger  *slog.Logger
	OnLoad  func()
	Verbose bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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