﻿# Bind a job transition to ownership and input revisions in one etcd transaction

Use one etcd transaction to compare the relevant ownership and input state before publishing related control records, while keeping external execution separate.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/etcd-transaction-compare-revision/
Language: en

## A valid result can belong to obsolete inputs

A worker finishes a partition while another coordinator changes the input manifest. Publishing the worker's output pointer and marking the partition complete in separate operations can accept a result for the old manifest or leave a completed marker without the intended pointer. The required decision spans several control records: current ownership, the input identity and the state transition being accepted. Treating each record as individually valid misses the relationship that makes their combined state meaningful to downstream workers and the final job aggregator.

## Compare the complete admission condition

The [etcd transaction API](https://etcd.io/docs/v3.6/learning/api/) evaluates a conjunction of comparisons atomically and executes its success or failure branch accordingly. A proposed job protocol can require the expected input revision, the still-valid ownership key and the expected job state before updating the result pointer and completion record together. The [concurrency reference](https://etcd.io/docs/v3.6/dev-guide/api_concurrency_reference_v3/) documents ownership keys usable for guarded etcd updates. Define the condition before execution. Checking ownership in a preceding request and comparing the manifest later leaves an interval in which either premise can change.

## Choose comparison targets deliberately

A value comparison asks whether bytes match; a modification-revision comparison identifies an observed mutation state. A key's version changes with modification and resets after deletion, so it should not be treated as a globally unique lifetime identity. The creation revision identifies a different property again. Choose the target according to the application's conflict rule, including deletion and recreation. For a job reused under a new manifest, preserving a familiar value such as ready is insufficient evidence that the original assignment is still the current assignment for that logical name.

## Interpret the selected branch and response

A successful RPC is not synonymous with a true comparison. Inspect `succeeded` and interpret the corresponding response list. The failure branch is itself a list of operations; it is not inherently read-only or harmless. Keep it explicit so a rejected admission cannot accidentally mutate unrelated job state. The API documentation also directs clients needing the transaction revision to its top-level response header rather than interpreting inner response headers. Preserve that revision with the accepted result identity, while recognizing that response loss can still leave the client uncertain about whether the transaction completed.

## Exercise competing and stale transitions

In an isolated fixture, let competing coordinators read the same job state, then attempt acceptance using their retained expectations. Change the manifest between observation and acceptance in another case, and include deletion followed by recreation. Verify that only the transition matching the declared ownership and input conditions is admitted and that related control records agree afterward. The [API guarantees](https://etcd.io/docs/v3.6/learning/api_guarantees/) give one revision to the transaction's keyspace changes. Retain actual record values and branch outcomes; a count of successful network responses cannot establish the intended atomic relationship.

## Do not extend the transaction outside etcd

An accepted transaction can authorize dispatch or publication, but it does not atomically execute an external training process, upload a checkpoint or make a remote database write. Those effects need their own reconciliation and idempotency contract. [Conditional pointer publication](/journal/guide-http-precondition-publish/) protects a different, single-endpoint update. [Retry and operation ledgers](/journal/provider-post-retry-idempotency-ledger/) explain the remaining effect boundary. Acceptance here means the etcd control state changed under the correct combined predicates. It does not mean all downstream effects finished, the referenced artifact passed validation or every cache already observed the new revision.
