Ferricstore.CommandTime (ferricstore v0.4.3)

Copy Markdown View Source

Shared clock for command code that can run both outside and inside Raft apply.

Outside Raft, command code uses the cluster-adjusted HLC time. Inside Raft apply, relative expiry and other time-derived command results must use the timestamp stored in the log entry so every replica computes the same state.

Summary

Functions

Returns the command time in milliseconds.

Runs fun with a stamped Raft apply time visible to command modules.

Functions

now_ms()

@spec now_ms() :: non_neg_integer()

Returns the command time in milliseconds.

If a Raft state machine apply scope installed a stamped log-entry time, that value is returned. Otherwise this falls back to the local cluster-adjusted HLC clock.

with_now_ms(now_ms, fun)

@spec with_now_ms(non_neg_integer(), (-> result)) :: result when result: term()

Runs fun with a stamped Raft apply time visible to command modules.