Skip to main content

Wal

Struct Wal 

Source
pub struct Wal { /* private fields */ }
Expand description

append-only 日志句柄。打开即追加,绝不截断;打开即持单写者锁, 打开即验完整历史(完整性链断裂 → 拒开,带病审计绝不续写)。

Implementations§

Source§

impl Wal

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, CoreError>

打开(不存在则创建)用于追加。禁 truncate:已有内容一律保留。

先自动创建父目录(W-43a 默认路径 ~/.wanning/wal.jsonl 的「零配置」体验; 显式路径同样受益),再拿单写者锁(fail-closed:第二个写进程拒启),再 整体验一遍已有历史(read_verified:逐行可解析 + 完整性链——历史被 改/删/排,拒开不续写),再以追加模式打开。锁定之后验历史,才不会和另一个 进程的追加赛跑。

Source

pub fn path(&self) -> &Path

Source

pub fn line_count(&self) -> u64

已写入行数(含历史行,1-based 下一条即 line_count() + 1)。

Source

pub fn chain_tail(&self) -> u64

完整性链尾值(最后一条记录的链值;空日志为创世值 0)。

Source

pub fn append(&mut self, record: &WalRecord) -> Result<u64, CoreError>

追加一条记录,返回其行号(1-based)。

每条写完立即 flush——审计必须先于一切下游动作落盘(真消费触发前的证据)。 行号即 seq、链尾即 prev,与读回验证的口径一致。

Trait Implementations§

Source§

impl Debug for Wal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Wal

§

impl RefUnwindSafe for Wal

§

impl Send for Wal

§

impl Sync for Wal

§

impl Unpin for Wal

§

impl UnsafeUnpin for Wal

§

impl UnwindSafe for Wal

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.