Consistency
There are two reads. The entity snapshot is updated in the commit the sync response waited for. A named query reads a projection table the worker fills in after that commit.
ACCEPTED means the ledger and the snapshot committed. Read the snapshot or the timeline for that commit. Read a named query for the projection.
Two reads
| Read | What it returns | When it moves |
|---|---|---|
| Entity snapshot | State committed with the intent | In the runtime commit |
| Named query, no token | Projection rows, possibly from cache | After the worker applies the event |
| Named query with a token | That entity’s projection row once its watermark has reached the token cursor | A miss is 409 and is not cached |
Intents for one entity run one at a time. Rules read the entity snapshot. They do not read the projection.
Token from a sync write
POST /v1/platforms/{platform}/applications/{application}/intents/execute with "mode": "sync".
When the intent is COMMITTED and the cursor is greater than 0, the response includes cursor and consistencyToken. An async accept has no cursor yet, so it has no token. A rejected intent has no token.
Send the token as X-Causet-Consistency on the query. A bare X-Causet-Min-Cursor header is 400. The cursor has to come from the signed token.
The query
queries:
get_counter:
from: counter_view
consistency: read_your_writes
input:
counter_id: { type: string, required: true }
stream_id: { type: string, required: true }
where:
counter_id: { eq: input.counter_id }
stream_id: { eq: input.stream_id }
limit: 1read_your_writes and entity_local both mean one entity and no join. The inputs contain the token’s stream id and entity id. The stream id on the token is the bare state name (counter), not counter_stream.
What the query service returns
The worker writes the watermark in the same database transaction as the projection change. The stored cursor is the greatest cursor applied for that stream, entity, projection, and version. An older apply cannot move it backward. A miss returns immediately. The query does not wait.
| Status | error | When |
|---|---|---|
| 200 | Watermark is READY, the projection version matches, and ledger_cursor is at least the token cursor | |
| 400 | VALIDATION_ERROR | Bare min cursor, malformed token, join or other entity, or inputs that are not the token’s stream and entity |
| 401 | UNAUTHORIZED | Signature failed, or the token is for another platform, application, or fork |
| 409 | PROJECTION_NOT_VISIBLE | No ready watermark, version mismatch, or the watermark cursor is still behind |
Read the query again on 409. The intent already committed. The header, the flag, and the crash cases are in Read consistency.
What to use
| You need | Read |
|---|---|
| The entity that just committed | causet inspect state or the entity API |
| The order of commits | causet inspect timeline |
| A list, a dashboard, or a lookup | A named query |
| That one entity’s projection row to include this commit | The consistency token on that query |