:ferricstore_wal_nif (ferricstore v0.4.3)

Copy Markdown View Source

Rust NIF append-log I/O module.

Replaces file:write and file:datasync with a Rust background thread that handles O_DIRECT, commit_delay batching, and fdatasync.

All NIF functions run on normal BEAM schedulers (<1μs each). The blocking I/O runs on a dedicated Rust OS thread.

This module is registered as an Erlang atom :ferricstore_wal_nif so the WARaft segment log can call it from Erlang.

Summary

Functions

Close the WAL file. Blocks until drain + sync + close.

Open a WAL file. Spawns background I/O thread.

Open a raw append file with no header offset. Used by WARaft segment logs.

Returns current logical file size in bytes.

Read bytes from WAL at offset. Used during recovery.

Reserve file space without extending logical length. Used by WARaft segment logs.

Request async fdatasync. Sends {wal_sync_complete, Ref, synced_position} on completion.

Request async fdatasync with a per-sync adaptive delay.

Write pre-formatted iodata to the WAL buffer. Does NOT write to disk.

Functions

close(handle)

Close the WAL file. Blocks until drain + sync + close.

open(path, commit_delay_us, pre_allocate_bytes, max_buffer_bytes)

Open a WAL file. Spawns background I/O thread.

open_raw_append(path, commit_delay_us, max_buffer_bytes, start_offset)

Open a raw append file with no header offset. Used by WARaft segment logs.

position(handle)

Returns current logical file size in bytes.

pread(handle, offset, len)

Read bytes from WAL at offset. Used during recovery.

preallocate_keep_size(path, bytes)

Reserve file space without extending logical length. Used by WARaft segment logs.

sync(handle, caller_pid, ref)

Request async fdatasync. Sends {wal_sync_complete, Ref, synced_position} on completion.

sync_with_delay(handle, caller_pid, ref, delay_us)

Request async fdatasync with a per-sync adaptive delay.

write(handle, iodata)

Write pre-formatted iodata to the WAL buffer. Does NOT write to disk.