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?): WriteAheadLogParameters
| Parameter | Type |
|---|---|
adapter | FlashcoreAdapter<string, unknown> |
config? | WALConfig |
Returns
Accessors
maxEntrySize
Get Signature
get maxEntrySize(): numberGet the max entry size.
Returns
number
staleThresholdMs
Get Signature
get staleThresholdMs(): numberGet 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
| Parameter | Type | Description |
|---|---|---|
input | WALEntryInput | Entry 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
| Parameter | Type | Description |
|---|---|---|
walId | string | WAL entry ID |
Returns
Promise<void>
deleteEntry()
deleteEntry(walId): Promise<void>Delete a WAL entry and all its segments.
Parameters
| Parameter | Type |
|---|---|
walId | string |
Returns
Promise<void>
getAllEntryKeys()
getAllEntryKeys(): Promise<string[]>Get all WAL entry keys (for recovery).
Returns
Promise<string[]>
Array of WAL entry keys
isEnabled()
isEnabled(): booleanCheck if WAL is enabled for this adapter. WAL requires scan capability.
Returns
boolean
isStale()
isStale(entry): booleanCheck if an entry is stale (old pending entry that should be rolled back).
Parameters
| Parameter | Type |
|---|---|
entry | WALEntry |
Returns
boolean
markPhase()
markPhase(walId, phase): Promise<void>Mark a WAL entry as having reached a phase.
Parameters
| Parameter | Type | Description |
|---|---|---|
walId | string | WAL entry ID |
phase | WalPhase | New phase |
Returns
Promise<void>
readEntry()
readEntry(walId): Promise<WALEntry>Read a WAL entry by ID.
Handles both inline and segmented entries.
Parameters
| Parameter | Type | Description |
|---|---|---|
walId | string | WAL entry ID |
Returns
Promise<WALEntry>
Entry or null if not found
shouldReplay()
shouldReplay(entry): booleanDetermine 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
| Parameter | Type |
|---|---|
entry | WALEntry |
Returns
boolean
writeEntry()
writeEntry(entry): Promise<void>Write a WAL entry.
Handles segmentation for large entries.
Parameters
| Parameter | Type |
|---|---|
entry | WALEntry |
Returns
Promise<void>
