soma.cell

W0007: scale_eventual_consistency

W0007 scale_eventual_consistency — eventual consistency on a slot that reads its own writes.

A warning of soma check, the checker of the Soma programming language (soma explain W0007).

The rule

soma check warns with W0007 when the slot named by scale { shard: … } is marked [consistent] while the scale section says consistency: eventual: the slot promises to read its own writes, but under eventual consistency a read after a write may return stale data. Eventual is the only consistency the cluster runtime implements (soma verify fails consistency: strong, and the cluster mode of soma serve refuses it), so the fix is to drop consistent from the sharded slot and write the handlers to tolerate stale reads.

A program that triggers it

wrong.cell

cell Orders {
    memory {
        orders: Map<String, Int> [persistent, consistent]
    }
    on place(id: String, total: Int) {
        orders.set(id, total)
        return orders.get(id)
    }
    scale {
        replicas: 3
        shard: orders
        consistency: eventual
    }
}

What soma check prints:

$ soma check wrong.cell
warning: cell 'Orders' uses eventual consistency on shard 'orders' — reads after writes may return stale data
  --> wrong.cell:9:5
  |
9 |     scale {
  |     ^
✓ 1 warning(s), no errors.

The fix field of soma check --json: Review and address the reported warning.

On line 3, orders: Map<String, Int> [persistent, consistent] becomes orders: Map<String, Int> [persistent].

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -1,5 +1,5 @@
 cell Orders {
     memory {
-        orders: Map<String, Int> [persistent, consistent]
+        orders: Map<String, Int> [persistent]
     }
     on place(id: String, total: Int) {

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.