12.5 Sharded actors
@idle(ACCOUNT_IDLE)
actor Account sharded by id: AccountId {
var balance: Money = Money.zero()
@transient var hits: u64 = 0
on activate { log.debug("account {id} up") }
msg deposit(x: Money) { balance += x }
msg balance() -> Money { balance }
}
Account(id).deposit(amount)- The key is declared in the header (
sharded by name: Type) and is available in the body as an immutable field. Account(key)is anActorRef<Account>; the actor is activated on the first message on the node that owns the shard. At most one instance per key is active in the cluster at a time.varfields are saved to the journal after each message, before the reply is sent;@transient varfields are not saved. On activation the state is restored, otherwise the defaults are used; thenon activateis executed.@idle(d)unloads the actor afterdwithout messages (on passivatebefore unloading).- The semantics of message processing — §8.8. When a shard moves, the runtime repeats delivery; state-changing messages SHOULD be made idempotent.
- In tests
Account.local(key)creates an instance in the process without a cluster.
Implementation-defined. Deduplication of actor messages (D-8055; DIV-018; D-4899). The Standard requires at-least-once with deduplication but does not define its bounds. This implementation: the deduplication window is the last 64 messages; the marks do not expire by time (
IDEMPOTENCY_TTLdoes not apply to actor messages); there is no@mailboxattribute (queue size).
Related diagnostics
See also
Source: docs/spec/oxl-standard.en.md