append to log
This block is part of the data group and was last modified in core v15.0.2.
append to log v15.0.2 Appends an entry to an ordered log per key: an order's status event, an audit record, a chat message. It takes the key's next sequence and is written through the storage.
- flow
- storage
valuerequiredthe storage the log's entries are documents of; it names the log
- key
valuerequiredthe log within the storage: an order, an account, a channel
- id
valuerequiredthe entry's id, unique within its key
- document
objectrequiredthe entry's own fields
- actor
valuewho appends; with nonce, what a retry is recognised by. The run's socket's user by default
- nonce
valuethe caller's own id for this append, so a retry is not a second entry
- group
valuegathers keys whose heads are read together (log_heads): the orders of a shop, the channels of a server
- key field
valuethe field that holds the key; log_key by default
- id field
valuethe field that holds the entry's id; id by default
- created field
valuethe field that holds the created sequence; created_seq by default
- changed field
valuethe field that holds the changed sequence; changed_seq by default
- flow
- success
condition - found
condition - entry
object - guid
value - seq
number - previous id
value - duplicate
condition - error
value
Allocates the key's next sequence, writes doc through the storage with the key, the id and the created and changed sequences set (field names from the four *_field pins) and a GUID derived from the storage, the key and the id, then records the entry in the Redis hot tail, the latest-entries cache, the key's head, and the group's heads when group is set. Example: storage order_events, key the order guid, id the event id, doc {status: "paid"}, group the shop. A retry with the same actor and nonce (a webhook's delivery id, a client's temporary id) returns the committed entry with duplicate=true and writes nothing; the nonce is reserved before the write, so a retry that arrives while the first call is still writing fails with APPEND_PENDING (try again shortly) instead of appending twice, and an append that failed before its document landed is not remembered. An append never replaces an entry: an id the key already has fails with ID_EXISTS, unless it is the same append sent again (same actor and nonce). prev_id is the key's head before this entry. Run it under a socket method's or lock's serialize on the key so commits and whatever announces them leave in one order. actor defaults to the run's socket's user. storage, key and id are required (STORAGE_REQUIRED, KEY_REQUIRED, ID_REQUIRED on error); LOG_NOT_ENABLED when the node runs no log. A sequence is a millisecond stamp from the key's own clock, max(now ms, the key's last + 1), so it is strictly increasing per key in commit order and compares with a cursor (cursor_set, cursor_lag).
Version history
Introduced in v15.0.2.
v15.0.2: block added in this release.
Back to
data Return to the main group to view all sub-groups Back to ordered log Return to the group to view all blocks within this group