LogoRobo.js
Framework

WriteAheadLog

Class: WriteAheadLog

Write-Ahead Log manager.

Handles WAL entry creation, phase tracking, and cleanup. WAL is only enabled when the adapter supports scan.

Constructors

new WriteAheadLog()

new WriteAheadLog(adapter, config?): WriteAheadLog

Parameters

ParameterType
adapterFlashcoreAdapter<string, unknown>
config?WALConfig

Returns

WriteAheadLog

Accessors

maxEntrySize

Get Signature

get maxEntrySize(): number

Get the max entry size.

Returns

number


staleThresholdMs

Get Signature

get staleThresholdMs(): number

Get the stale threshold.

Returns

number

Methods

begin()

begin(input): Promise<string>

Begin a new WAL entry.

Creates a new entry with phase='pending' and persists it.

Parameters

ParameterTypeDescription
inputWALEntryInputEntry input (without id, timestamp, phase)

Returns

Promise<string>

WAL entry ID

Throws

Error if WAL is disabled


complete()

complete(walId): Promise<void>

Mark a WAL entry as complete and delete it.

Parameters

ParameterTypeDescription
walIdstringWAL entry ID

Returns

Promise<void>


deleteEntry()

deleteEntry(walId): Promise<void>

Delete a WAL entry and all its segments.

Parameters

ParameterType
walIdstring

Returns

Promise<void>


getAllEntryKeys()

getAllEntryKeys(): Promise<string[]>

Get all WAL entry keys (for recovery).

Returns

Promise<string[]>

Array of WAL entry keys


isEnabled()

isEnabled(): boolean

Check if WAL is enabled for this adapter. WAL requires scan capability.

Returns

boolean


isStale()

isStale(entry): boolean

Check if an entry is stale (old pending entry that should be rolled back).

Parameters

ParameterType
entryWALEntry

Returns

boolean


markPhase()

markPhase(walId, phase): Promise<void>

Mark a WAL entry as having reached a phase.

Parameters

ParameterTypeDescription
walIdstringWAL entry ID
phaseWalPhaseNew phase

Returns

Promise<void>


readEntry()

readEntry(walId): Promise<WALEntry>

Read a WAL entry by ID.

Handles both inline and segmented entries.

Parameters

ParameterTypeDescription
walIdstringWAL entry ID

Returns

Promise<WALEntry>

Entry or null if not found


shouldReplay()

shouldReplay(entry): boolean

Determine if an entry should be replayed or rolled back.

  • If phase > 'pending', always replay (authoritative writes started)
  • If phase == 'pending' and stale, rollback
  • If phase == 'pending' and recent, replay (may have crashed during WAL write)

Parameters

ParameterType
entryWALEntry

Returns

boolean


writeEntry()

writeEntry(entry): Promise<void>

Write a WAL entry.

Handles segmentation for large entries.

Parameters

ParameterType
entryWALEntry

Returns

Promise<void>

On this page