fix(idempotency)!: 두 멱등 저장소가 operation id·release·inspect에 같게 답한다

문제: 같은 호출에 Redis와 PostgreSQL 저장소(와 in-memory fake)가 다르게
답한다.
- owner token이 같아도 호출이 claim과 다른 operation id를 대면 Redis는
  다섯 전이(start·renew·complete·fail·release)를 OPERATION_CONFLICT로
  거절하고 PostgreSQL·fake는 적용한다. PostgreSQL은 CAS에 핸들의 claim
  operation만 쓰고 호출의 id는 last_transition_operation_id에 적기만 한다.
- PostgreSQL complete 재생은 operation id만 보고 owner를 보지 않아, 같은
  id를 쓴 다른 attempt의 늦은 complete를 이미 적용된 완료로 확인한다.
  Redis는 NOT_OWNER.
- fake의 claim·inspect는 같은 token·다른 operation에 OwnerOperationConflict
  ·OPERATION_CONFLICT를 내지 않는다. PostgreSQL·fake의 inspect는 완료된
  기록이면 그 응답을 재생하고 Redis는 OPERATION_CONFLICT.
- 기록이 없는 release에 Redis는 ALREADY_RELEASED_SAME_OPERATION, PostgreSQL
  ·fake는 ABSENT. Redis release는 revision을 보지 않아, 같은 attempt가 claim을
  넘겨받기 전 핸들로 지금의 claim을 지운다.

방법: 소유자 결정 (a)로 PostgreSQL·fake를 Redis에 맞춘다. owner token이
같고 호출 id가 기록의 claim id와 다르면 다섯 전이 모두 OPERATION_CONFLICT,
기록은 그대로. 나머지 셋은 "거절이 안전한 쪽, 운영 호출자 경로가 안 바뀌는
쪽"으로 정했다.
- complete 재생은 같은 owner token에만 확인한다(Redis에 맞춤).
- fake claim은 진행 중 기록에 OwnerOperationConflict, inspect는 같은 token·
  다른 operation이면 상태와 상관없이 OPERATION_CONFLICT. PostgreSQL inspect도
  완료 재생보다 이 검사를 먼저 한다.
- 기록 없는 release는 셋 다 ABSENT. Redis adapter가 ABSENT를 그대로 넘기고
  RELEASE 스크립트와 command fake가 핸들 revision을 본다. release한 기록을
  지울지 남길지는 저장소 선택이라 release 재시도는 ABSENT(Redis·fake)와
  ALREADY_RELEASED_SAME_OPERATION(PostgreSQL)으로 갈리는 것을 계약이 허용한다.
버린 대안: Redis를 PostgreSQL에 맞추기(Redis에는 전이 id를 둘 필드가 없어
인자가 죽는다), PostgreSQL release를 삭제로 바꾸기(release 뒤 기록 모양은
계약이 저장소 선택으로 정해 두었다), 기록 없는 release를 셋 다
ALREADY_RELEASED로(찾지 못한 것을 성공으로 확인한다 — JPA 설계 22.2와 반대).
공유 계약 IdempotencyStoreContract에 12케이스를 더했다. 포트·결과 enum
Javadoc, persistence-jpa·cache-redis README, TESTING_STRATEGY, application-core
CLAUDE.md, 결정 색인, 업그레이드 안내 5절을 같이 고쳤다.

위험·한계: 템플릿의 호출자(IdempotencyExecutor)는 늘 claim의 id를 넘기고
release를 부르지 않아 HTTP 동작은 같다. store 포트를 직접 부르며 전이마다
다른 id를 넘기던 코드는 OPERATION_CONFLICT를 받는다. PostgreSQL 통합
테스트가 그렇게 쓰고 있어 claim의 id로 바꿨다. last_transition_operation_id
열은 이제 늘 claim_operation_id와 같다(마이그레이션은 건드리지 않음).
같은 token의 넘겨받기 전 핸들로 이미 끝난 complete·markFailed를 다시 보내는
경우는 저장소마다 답이 다르다(범위 밖, 보고에 적음).

검증: desktop, 공유 잠금, 기준 06f520e6.
- RED(기준 커밋 + 계약만): in-memory fake 계약 49 중 8 실패, Redis
  command fake 2, 실 Redis(redisContainerContractTest) 2, 실 PostgreSQL
  (jpaPlatformContractTest) 7 — 실패 메시지가 위 차이 그대로("expected:
  OPERATION_CONFLICT but was: STARTED", "expected: ABSENT but was:
  ALREADY_RELEASED_SAME_OPERATION" 등).
- GREEN(이 커밋과 같은 트리): 네 leaf check(application-core 412·skip 19
  시간 케이스, persistence-jpa 664, cache-redis 215, redis-runtime 65),
  네 leaf testQualityCheck, jpaPlatformContractTest 419,
  postgresqlIdempotencyIntegrationTest 10, redisContainerContractTest 90,
  app-bootstrap integrationTest 10, sample integrationTest 63,
  documentContractTest 65, architectureTest 228, composition:idempotency
  check 32 — 모두 rc=0, 실패·skip 0(fake 시간 케이스 19 제외).
- scripts/check-work-docs.py, --links docs, git diff --check 통과.

Refs: docs/reviews/2026-11-03-rereview/round6/02-idempotency-outbound.md Declined to judge
BREAKING CHANGE: 멱등 store 포트를 직접 부르는 코드는 전이마다 claim의
operation id(IdempotencyOwner.claimOperationId())를 넘겨야 한다. 다른 id는
OPERATION_CONFLICT다. Redis release는 기록이 없으면 ABSENT를 돌려준다.
직접 구현한 store는 IdempotencyStoreContract의 새 케이스를 통과해야 한다.
This commit is contained in:
DongHyeonka
2026-11-06 22:25:45 +09:00
parent 06f520e667
commit 200019aa5c
20 changed files with 437 additions and 47 deletions
+3
View File
@@ -288,6 +288,9 @@ generation; the V1 `IdempotencyScope`/`tryBegin` API is gone.
(owner decision 2026-11-04, re-review RR5-01-02·03). A record lives for the lease plus the replay TTL. `IdempotencyStoreContract` holds Redis and PostgreSQL to both on
real servers; the in-memory fake models no time, so it runs only the contract's time-free cases
(re-review 2026-11-04 RR-01-11, RR-03-11, RR3-03-04).
- Every transition names the operation its record was claimed under (`IdempotencyOwner.claimOperationId()`).
Another one is `OPERATION_CONFLICT` in every store and changes nothing; so is an inspection that
brings the owner token under another operation (owner decision 2026-11-06).
The former ArchUnit freeze rule `inbound_port_implementations_do_not_declare_keyed_idempotency`
and its fixture were removed when this branch merged.
@@ -8,6 +8,10 @@ public enum IdempotencyCompleteOutcome {
ABSENT,
NOT_OWNER,
NOT_IN_PROGRESS,
/**
* The call names an operation other than the one the record was claimed under; nothing was
* recorded (owner decision 2026-11-06).
*/
OPERATION_CONFLICT,
INDETERMINATE,
UNAVAILABLE
@@ -8,6 +8,11 @@ public enum IdempotencyFailOutcome {
ABSENT,
NOT_OWNER,
NOT_IN_PROGRESS,
/**
* The call names an operation other than the one the record was claimed under (owner decision
* 2026-11-06), or this failure was already recorded with another disposition or retention.
* Nothing changed.
*/
OPERATION_CONFLICT,
INDETERMINATE,
UNAVAILABLE
@@ -16,6 +16,10 @@ public enum IdempotencyInspectionOutcome {
*/
ABANDONED,
FINGERPRINT_MISMATCH,
/**
* The attempt's owner token holds the record under another operation. It is the answer in every
* state, a completed record included: its response is not replayed to it.
*/
OPERATION_CONFLICT,
UNAVAILABLE
}
@@ -3,10 +3,19 @@ package dev.caskeleton.application.idempotency;
/** Outcomes of releasing a claim only while business execution has not started. */
public enum IdempotencyReleaseOutcome {
RELEASED_BEFORE_EXECUTION,
/** This release was already applied: a store that keeps released records recognises it. */
ALREADY_RELEASED_SAME_OPERATION,
/**
* No record exists: it expired, was never there, or was released by a store that deletes what it
* releases — that store cannot tell its own release's retry apart, so it confirms nothing.
*/
ABSENT,
NOT_OWNER,
EXECUTION_ALREADY_STARTED,
/**
* The call names an operation other than the one the record was claimed under; nothing was
* released (owner decision 2026-11-06).
*/
OPERATION_CONFLICT,
INDETERMINATE,
UNAVAILABLE
@@ -29,7 +29,10 @@ public enum IdempotencyRenewOutcome {
* with the same handle are still recorded (owner decision 2026-11-04).
*/
LEASE_EXPIRED(false),
/** The same operation id already renewed with different arguments. */
/**
* The call names an operation other than the one the record was claimed under (owner decision
* 2026-11-06), or this renewal was already applied asking for a different lease. Nothing changed.
*/
OPERATION_CONFLICT(false),
/** The store may have applied the renewal; inspect before relying on either answer. */
INDETERMINATE(false),
@@ -33,7 +33,11 @@ public enum IdempotencyStartOutcome {
* store started it).
*/
LEASE_EXPIRED(false),
/** The same operation id already started this record with different arguments. */
/**
* The handle's owner token holds the record, but the call names an operation other than the one
* the record was claimed under; nothing changed. Every store refuses it (owner decision
* 2026-11-06 — the PostgreSQL store started it).
*/
OPERATION_CONFLICT(false),
/** The store may have applied the start; inspect before relying on either answer. */
INDETERMINATE(false),
@@ -21,6 +21,14 @@ import java.time.Duration;
* record from its holder. Only the record's own lifetime ends it: once it is gone, every call
* answers {@code ABSENT} (owner decision 2026-11-04; re-review 2026-11-04 RR5-01-02·03; {@code
* IdempotencyStoreContract}).
*
* <p>Every transition names the operation its record was claimed under — the handle's {@link
* IdempotencyOwner#claimOperationId()}. A holder naming another one is answered {@code
* OPERATION_CONFLICT} and nothing changes; a claim that brings the owner token under another
* operation to a record still in progress is {@link
* IdempotencyClaimOutcome.OwnerOperationConflict}, and an inspection is {@code OPERATION_CONFLICT}
* in every state (owner decision 2026-11-06). For renew and failure {@code OPERATION_CONFLICT} also
* still means the same transition was already applied with other arguments.
*/
public interface IdempotencyStorePort {
@@ -514,6 +514,244 @@ public abstract class IdempotencyStoreContract {
.isGreaterThan(claimed.stateRevision());
}
// Every transition names the operation its record was claimed under. A holder naming another one
// is refused as OPERATION_CONFLICT and the record is left as it was: the Redis store refused it,
// the PostgreSQL store and the in-memory fake applied it — the PostgreSQL store wrote the named
// operation beside the claim's and read the claim's from the handle (owner decision 2026-11-06).
@Test
void startingUnderAnotherOperationThanTheClaimIsAConflictThatStartsNothing() {
// given
IdempotencyStorePort store = subject();
IdempotencyOwner claimed = acquire(store);
// when
IdempotencyMutationResult<IdempotencyStartOutcome> conflict =
store.markExecutionStarted(claimed, OTHER_OPERATION);
// then
assertThat(conflict.outcome()).isEqualTo(IdempotencyStartOutcome.OPERATION_CONFLICT);
assertThat(store.markExecutionStarted(claimed, OPERATION).outcome())
.isEqualTo(IdempotencyStartOutcome.STARTED);
}
@Test
void renewingUnderAnotherOperationThanTheClaimIsAConflictThatRenewsNothing() {
// given
IdempotencyStorePort store = subject();
IdempotencyOwner executing = executing(store);
// when
IdempotencyMutationResult<IdempotencyRenewOutcome> conflict =
store.renew(executing, Duration.ofSeconds(30), OTHER_OPERATION);
// then
assertThat(conflict.outcome()).isEqualTo(IdempotencyRenewOutcome.OPERATION_CONFLICT);
// The revision did not move, so the handle the start returned still completes the record.
assertThat(store.complete(executing, new StoredResponse("{}"), Duration.ofHours(1), OPERATION))
.isEqualTo(IdempotencyCompleteOutcome.COMPLETED);
}
@Test
void completingUnderAnotherOperationThanTheClaimIsAConflictThatRecordsNothing() {
// given
IdempotencyStorePort store = subject();
IdempotencyOwner executing = executing(store);
// when
IdempotencyCompleteOutcome conflict =
store.complete(
executing, new StoredResponse("{\"v\":1}"), Duration.ofHours(1), OTHER_OPERATION);
// then
assertThat(conflict).isEqualTo(IdempotencyCompleteOutcome.OPERATION_CONFLICT);
// No response was recorded: another one completes the record rather than conflicting with it.
assertThat(
store.complete(
executing, new StoredResponse("{\"v\":2}"), Duration.ofHours(1), OPERATION))
.isEqualTo(IdempotencyCompleteOutcome.COMPLETED);
}
@Test
void markingFailedUnderAnotherOperationThanTheClaimIsAConflictThatMarksNothing() {
// given
IdempotencyStorePort store = subject();
IdempotencyOwner executing = executing(store);
// when
IdempotencyFailOutcome conflict =
store.markFailed(
executing,
IdempotencyFailureDisposition.NO_EFFECT_RETRYABLE,
Duration.ofHours(1),
OTHER_OPERATION);
// then
assertThat(conflict).isEqualTo(IdempotencyFailOutcome.OPERATION_CONFLICT);
assertThat(store.complete(executing, new StoredResponse("{}"), Duration.ofHours(1), OPERATION))
.isEqualTo(IdempotencyCompleteOutcome.COMPLETED);
}
@Test
void releasingUnderAnotherOperationThanTheClaimIsAConflictThatReleasesNothing() {
// given
IdempotencyStorePort store = subject();
IdempotencyOwner claimed = acquire(store);
// when
IdempotencyReleaseOutcome conflict = store.releaseBeforeExecution(claimed, OTHER_OPERATION);
// then
assertThat(conflict).isEqualTo(IdempotencyReleaseOutcome.OPERATION_CONFLICT);
assertThat(store.markExecutionStarted(claimed, OPERATION).outcome())
.isEqualTo(IdempotencyStartOutcome.STARTED);
}
@Test
void anotherAttemptCompletingARecordCompletedUnderTheSameOperationIsNotItsOwner() {
// given
// One operation id on two attempts — a caller that keeps its operation id across resends. The
// second attempt took the retryable failure over and completed it; the first attempt's late
// completion is not that completion. The PostgreSQL store confirmed it, because its replay
// check read the operation id and not the owner.
IdempotencyStorePort store = subject();
IdempotencyOwner first = executing(store);
store.markFailed(
first, IdempotencyFailureDisposition.NO_EFFECT_RETRYABLE, Duration.ofHours(1), OPERATION);
IdempotencyOwner second =
started(store, ownerOf(store.claim(claim(store.newClaimAttempt(OPERATION), FINGERPRINT))));
store.complete(second, new StoredResponse("{\"v\":1}"), Duration.ofHours(1), OPERATION);
// when
IdempotencyCompleteOutcome late =
store.complete(first, new StoredResponse("{\"v\":1}"), Duration.ofHours(1), OPERATION);
// then
assertThat(late).isEqualTo(IdempotencyCompleteOutcome.NOT_OWNER);
}
@Test
void aClaimWithTheOwnerTokenUnderAnotherOperationIsAnOwnerOperationConflict() {
// given
IdempotencyStorePort store = subject();
IdempotencyClaimAttempt attempt = store.newClaimAttempt(OPERATION);
IdempotencyOwner claimed = ownerOf(store.claim(claim(attempt, FINGERPRINT)));
// when
IdempotencyClaimOutcome conflict =
store.claim(
claim(new IdempotencyClaimAttempt(attempt.ownerToken(), OTHER_OPERATION), FINGERPRINT));
// then
assertThat(conflict).isInstanceOf(IdempotencyClaimOutcome.OwnerOperationConflict.class);
assertThat(store.markExecutionStarted(claimed, OPERATION).outcome())
.isEqualTo(IdempotencyStartOutcome.STARTED);
}
@Test
void inspectingAClaimWithTheOwnerTokenUnderAnotherOperationIsAnOperationConflict() {
// given
IdempotencyStorePort store = subject();
IdempotencyClaimAttempt attempt = store.newClaimAttempt(OPERATION);
store.claim(claim(attempt, FINGERPRINT));
// when
IdempotencyInspection inspection =
store.inspect(
new IdempotencyInspectionRequest(
SCOPE,
FINGERPRINT,
new IdempotencyClaimAttempt(attempt.ownerToken(), OTHER_OPERATION)));
// then
assertThat(inspection.outcome()).isEqualTo(IdempotencyInspectionOutcome.OPERATION_CONFLICT);
}
@Test
void inspectingACompletedRecordWithTheOwnerTokenUnderAnotherOperationIsAnOperationConflict() {
// given
// In every state, a completed record included: the Redis store refused it, the PostgreSQL
// store and the in-memory fake replayed the response to it.
IdempotencyStorePort store = subject();
IdempotencyClaimAttempt attempt = store.newClaimAttempt(OPERATION);
store.complete(
started(store, ownerOf(store.claim(claim(attempt, FINGERPRINT)))),
new StoredResponse("{\"ok\":true}"),
Duration.ofHours(1),
OPERATION);
// when
IdempotencyInspection inspection =
store.inspect(
new IdempotencyInspectionRequest(
SCOPE,
FINGERPRINT,
new IdempotencyClaimAttempt(attempt.ownerToken(), OTHER_OPERATION)));
// then
assertThat(inspection.outcome()).isEqualTo(IdempotencyInspectionOutcome.OPERATION_CONFLICT);
}
@Test
void releasingAScopeWithNoRecordIsAbsent() {
// given
// A handle whose record is gone — expired, reaped — stands in here as one for a scope nobody
// claimed. Nothing was found, so nothing is confirmed: the Redis store answered that it had
// already released it.
IdempotencyStorePort store = subject();
IdempotencyOwner gone =
new IdempotencyOwner(SCOPE, store.newClaimAttempt(OPERATION).ownerToken(), 1, 1, OPERATION);
// when
IdempotencyReleaseOutcome released = store.releaseBeforeExecution(gone, OPERATION);
// then
assertThat(released).isEqualTo(IdempotencyReleaseOutcome.ABSENT);
}
@Test
void aReleaseRetriedAfterItWasAppliedReleasesNothingMore() {
// given
IdempotencyStorePort store = subject();
IdempotencyOwner claimed = acquire(store);
store.releaseBeforeExecution(claimed, OPERATION);
// when
IdempotencyReleaseOutcome again = store.releaseBeforeExecution(claimed, OPERATION);
// then
// A store that keeps the released record recognises the release (PostgreSQL); one that forgets
// it finds no record (Redis, the in-memory fake). Neither releases a second time.
assertThat(again)
.isIn(
IdempotencyReleaseOutcome.ALREADY_RELEASED_SAME_OPERATION,
IdempotencyReleaseOutcome.ABSENT);
}
@Test
void releasingThroughTheHandleFromBeforeTheAttemptTookItsClaimOverIsRefusedAsAStaleOwner() {
// given
// The same attempt took its retryable failure over, so the record is a claim again under the
// same owner token and operation. The Redis program read no revision and released it.
IdempotencyStorePort store = subject();
IdempotencyClaimAttempt attempt = store.newClaimAttempt(OPERATION);
IdempotencyOwner before = ownerOf(store.claim(claim(attempt, FINGERPRINT)));
store.markFailed(
started(store, before),
IdempotencyFailureDisposition.NO_EFFECT_RETRYABLE,
Duration.ofHours(1),
OPERATION);
IdempotencyOwner current = ownerOf(store.claim(claim(attempt, FINGERPRINT)));
// when
IdempotencyReleaseOutcome released = store.releaseBeforeExecution(before, OPERATION);
// then
assertThat(released).isEqualTo(IdempotencyReleaseOutcome.NOT_OWNER);
assertThat(store.markExecutionStarted(current, OPERATION).outcome())
.isEqualTo(IdempotencyStartOutcome.STARTED);
}
@Test
@DisplayName("실행 중인 자기 기록을 inspect하면 기록 수명이 아니라 claim이 받은 처리 lease 만료 시각이 나온다")
void inspectingAnOwnExecutionReportsItsProcessingLeaseNotTheRecordLifetime() {
@@ -34,7 +34,8 @@ import java.util.Random;
* attempt against an in-flight record is always {@code InProgress}. Leases and replay windows are
* reported as {@link Instant#MAX}. What it keeps exact is what a test of a caller relies on: one
* claim wins, the owner handle's revision advances on every transition, a completed response
* replays, a different fingerprint is refused, and a retryable failure can be claimed again.
* replays, a different fingerprint is refused, a retryable failure can be claimed again, and an
* owner naming an operation other than its claim's is refused.
*/
public final class InMemoryIdempotencyStore implements IdempotencyStorePort {
@@ -82,6 +83,10 @@ public final class InMemoryIdempotencyStore implements IdempotencyStorePort {
&& row.owner.claimOperationId().equals(request.claimAttempt().operationId())) {
return new IdempotencyClaimOutcome.ReplayedAcquire(row.owner, Instant.MAX);
}
// The owner token under another operation is refused, not reported in progress.
if (row.owner.ownerToken().equals(request.claimAttempt().ownerToken())) {
return new IdempotencyClaimOutcome.OwnerOperationConflict();
}
return new IdempotencyClaimOutcome.InProgress(Duration.ZERO, row.owner.attempt());
}
@@ -92,11 +97,13 @@ public final class InMemoryIdempotencyStore implements IdempotencyStorePort {
IdempotencyStartOutcome outcome =
row == null
? IdempotencyStartOutcome.ABSENT
: !row.owner.equals(owner)
? IdempotencyStartOutcome.NOT_OWNER
: row.state != IdempotencyState.CLAIMED
? IdempotencyStartOutcome.NOT_CLAIMED
: IdempotencyStartOutcome.STARTED;
: row.namesAnotherOperation(owner, operationId)
? IdempotencyStartOutcome.OPERATION_CONFLICT
: !row.owner.equals(owner)
? IdempotencyStartOutcome.NOT_OWNER
: row.state != IdempotencyState.CLAIMED
? IdempotencyStartOutcome.NOT_CLAIMED
: IdempotencyStartOutcome.STARTED;
if (outcome != IdempotencyStartOutcome.STARTED) {
return new IdempotencyMutationResult<>(outcome, null, IdempotencyStartOutcome::carriesOwner);
}
@@ -114,11 +121,13 @@ public final class InMemoryIdempotencyStore implements IdempotencyStorePort {
IdempotencyRenewOutcome refused =
row == null
? IdempotencyRenewOutcome.ABSENT
: !row.owner.equals(owner)
? IdempotencyRenewOutcome.NOT_OWNER
: row.state != IdempotencyState.EXECUTING
? IdempotencyRenewOutcome.NOT_IN_PROGRESS
: null;
: row.namesAnotherOperation(owner, operationId)
? IdempotencyRenewOutcome.OPERATION_CONFLICT
: !row.owner.equals(owner)
? IdempotencyRenewOutcome.NOT_OWNER
: row.state != IdempotencyState.EXECUTING
? IdempotencyRenewOutcome.NOT_IN_PROGRESS
: null;
if (refused != null) {
return new IdempotencyMutationResult<>(refused, null, IdempotencyRenewOutcome::carriesOwner);
}
@@ -137,6 +146,9 @@ public final class InMemoryIdempotencyStore implements IdempotencyStorePort {
if (row == null) {
return IdempotencyCompleteOutcome.ABSENT;
}
if (row.namesAnotherOperation(owner, operationId)) {
return IdempotencyCompleteOutcome.OPERATION_CONFLICT;
}
if (row.state == IdempotencyState.COMPLETED && owner.equals(row.completedBy)) {
// The completing handle retried, as after a lost reply: the same result is a no-op, another
// result is a conflict, exactly as the stores answer.
@@ -166,6 +178,9 @@ public final class InMemoryIdempotencyStore implements IdempotencyStorePort {
if (row == null) {
return IdempotencyFailOutcome.ABSENT;
}
if (row.namesAnotherOperation(owner, operationId)) {
return IdempotencyFailOutcome.OPERATION_CONFLICT;
}
if (!row.owner.equals(owner)) {
return IdempotencyFailOutcome.NOT_OWNER;
}
@@ -186,6 +201,9 @@ public final class InMemoryIdempotencyStore implements IdempotencyStorePort {
if (row == null) {
return IdempotencyReleaseOutcome.ABSENT;
}
if (row.namesAnotherOperation(owner, operationId)) {
return IdempotencyReleaseOutcome.OPERATION_CONFLICT;
}
if (!row.owner.equals(owner)) {
return IdempotencyReleaseOutcome.NOT_OWNER;
}
@@ -205,6 +223,11 @@ public final class InMemoryIdempotencyStore implements IdempotencyStorePort {
if (!row.fingerprint.equals(request.requestFingerprint())) {
return IdempotencyInspection.outcome(IdempotencyInspectionOutcome.FINGERPRINT_MISMATCH);
}
// The stores' order: the owner token under another operation is refused in every state.
if (row.owner.ownerToken().equals(request.claimAttempt().ownerToken())
&& !row.owner.claimOperationId().equals(request.claimAttempt().operationId())) {
return IdempotencyInspection.outcome(IdempotencyInspectionOutcome.OPERATION_CONFLICT);
}
if (row.state == IdempotencyState.COMPLETED) {
return new IdempotencyInspection(
IdempotencyInspectionOutcome.COMPLETED_REPLAY,
@@ -274,5 +297,15 @@ public final class InMemoryIdempotencyStore implements IdempotencyStorePort {
owner = owner.withStateRevision(owner.stateRevision() + 1);
state = next;
}
/**
* Whether the record's owner names an operation other than its claim's. The stores refuse that
* before anything else is read, whatever the handle's revision ({@code
* IdempotencyStoreContract}).
*/
boolean namesAnotherOperation(IdempotencyOwner caller, OperationId operationId) {
return owner.ownerToken().equals(caller.ownerToken())
&& !owner.claimOperationId().equals(operationId);
}
}
}