dlog

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DLog

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

DLog manages the logA/logB double-buffered log files. Follows the double-buffering pattern where one log is active for writes and the other is inactive (being snapshotted or ready for compaction).

func NewDLog

func NewDLog(baseDir string, logger *slog.Logger) (*DLog, error)

NewDLog creates a new double-buffered log manager. Initializes both logA and logB files, determines active log from state. Defaults to LogA as active if no state exists.

func (*DLog) AppendEntry

func (dl *DLog) AppendEntry(entry *Entry) (logPosition int64, logFile LogFileID, err error)

AppendEntry appends an Entry to the active log file. The Entry.Commit is provided by the caller (from seq.Seq.NextCommit()). Returns the log position and which log file (A or B) it was written to. Does NOT automatically switch active log - that's handled by the caller when compaction boundaries are reached.

func (*DLog) Close

func (dl *DLog) Close() error

Close closes both log files.

func (*DLog) GetActiveLog

func (dl *DLog) GetActiveLog() LogFileID

GetActiveLog returns the currently active log file ID.

func (*DLog) GetInactiveLog

func (dl *DLog) GetInactiveLog() LogFileID

GetInactiveLog returns the currently inactive log file ID.

func (*DLog) Iterator

func (dl *DLog) Iterator() (*DLogIter, error)

Iterator creates an iterator for reading entries from both log files in commit order. Starts at position 0 for both files. Note: Currently uses non-streaming reads. Streaming support can be added later.

func (*DLog) ReadEntryAt

func (dl *DLog) ReadEntryAt(logFile LogFileID, position int64) (*Entry, error)

ReadEntryAt reads an Entry from the specified log file at the given position. logFile must be "A" or "B".

func (*DLog) SwitchActive

func (dl *DLog) SwitchActive() error

SwitchActive switches the active log (A ↔ B). Called by the caller when compaction boundaries are reached.

type DLogFile

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

DLogFile represents a single log file with its operations

func (*DLogFile) AppendEntry

func (dlf *DLogFile) AppendEntry(entry *Entry) (position int64, err error)

AppendEntry appends an Entry to this log file. Format: [4 bytes: uint32 length (big-endian)][entry data in Tony wire format] Returns the byte position where the entry was written.

func (*DLogFile) Close

func (dlf *DLogFile) Close() error

Close closes the log file.

func (*DLogFile) Position

func (dlf *DLogFile) Position() int64

Position returns the current write position (for appends).

func (*DLogFile) ReadEntryAt

func (dlf *DLogFile) ReadEntryAt(position int64) (*Entry, error)

ReadEntryAt reads an Entry from the specified byte position. Reads length prefix, then entry data, deserializes to Entry.

func (*DLogFile) Size

func (dlf *DLogFile) Size() (int64, error)

Size returns the current size of the log file.

type DLogIter

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

DLogIter provides sequential iteration over log entries using streaming reads. Uses streaming parsing to avoid loading entire entries into memory. Iterates over both logA and logB, switching between them based on commit order.

func (*DLogIter) Done

func (it *DLogIter) Done() bool

Done returns true if iterator has reached end of both files.

func (*DLogIter) Next

func (it *DLogIter) Next() (*Entry, LogFileID, int64, error)

Next reads and returns the next entry from both log files in commit order. Returns the entry, its log file ID and position, and any error. Returns io.EOF when both files are exhausted.

type Entry

type Entry struct {
	Commit     int64     // Commit number (set when appended to log)
	Timestamp  string    // RFC3339 timestamp
	Patch      *ir.Node  // Root patch/diff (always at root, empty kinded path "")
	TxSource   *tx.State // Transaction state (for transaction entries)
	SnapPos    *int64    // Snapshot position (for snapshot entries)
	LastCommit *int64    // Last commit before compaction (for compaction entries)
}

Entry represents a log entry written to logA/logB. This structure supports 4 types of entries:

  • Plain patch: Patch set, TxSource/SnapPos nil *LastCommit=Commit-1
  • Transaction: Patch and TxSource set, SnapPos nil *LastCommit=Commit-1
  • Snapshot: SnapPos set to point to log where state exists, TxSource nil, LastCommit nil
  • Compaction: Patch set, LastCommit set Commit-*LastCommit > 1, TxSource nil, SnapPos nil

func NewEntry

func NewEntry(state *tx.State, mergedPatch *ir.Node, commit int64, timestamp string, lastCommit int64) *Entry

NewEntry creates a dlog.Entry for a transaction commit. The entry contains the merged patch and transaction state for debugging/dev. Parameters:

  • state: The transaction state (will be stored in TxSource)
  • mergedPatch: The merged root patch/diff (already merged from all participants)
  • commit: The commit number for this entry
  • timestamp: RFC3339 timestamp string
  • lastCommit: The commit number before this one (typically commit-1)

func (*Entry) FromTony

func (s *Entry) FromTony(data []byte, opts ...gomap.UnmapOption) error

FromTony parses Tony format bytes and populates Entry.

func (*Entry) FromTonyIR

func (s *Entry) FromTonyIR(node *ir.Node, opts ...gomap.UnmapOption) error

FromTonyIR populates Entry from a Tony IR node.

func (*Entry) ToTony

func (s *Entry) ToTony(opts ...gomap.MapOption) ([]byte, error)

ToTony converts Entry to Tony format bytes.

func (*Entry) ToTonyIR

func (s *Entry) ToTonyIR(opts ...gomap.MapOption) (*ir.Node, error)

ToTonyIR converts Entry to a Tony IR node.

type LogFileID

type LogFileID string

LogFileID identifies which log file (A or B)

const (
	LogFileA LogFileID = "A"
	LogFileB LogFileID = "B"
)

Jump to

Keyboard shortcuts

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