Repository navigation
feat(distributed)!: replace the N-identical-PUT fan-out with per-key CAS (#284) - #386
Merged
Merged
Conversation
…CAS (#284) BREAKING CHANGE: `cluster.consistency_level` and `cluster.cache_replication` are removed from the configuration file. Because the loader decodes strictly, a config that still sets either now fails at startup naming the key and line — which is the intended outcome, since the alternative is accepting a setting that selects nothing. Delete the lines; there is no replacement to set, because what replaced the first is per-operation (`DistributedOperation.Precondition`) and the second was read by no code at all. `ClusterManager.InvalidateCacheKey` also gains an `etag` parameter. Four things go, and what connects them is that each named a distributed guarantee the code did not provide. `ConsistencyLevel` and its three constants all issued the same unconditional PutObject and differed only in how many nodes issued it, so what an operator picked changed the request count and not the guarantee. `ConsistencyStrong` fanned the identical bytes at the identical key to every target node and called majority success "linearizable"; every node writes the same key in the same bucket and S3 holds the single copy, so N-1 of those PUTs were billed requests that changed nothing. Deleted rather than cut to two levels: under CAS the distinguishing fact is whether the operation carries a precondition, and a `types.Precondition` field already says that, so a two-name enum beside it would be a second encoding of `Precondition.IsZero()`. `CacheReplicator` sent N-1 peers a PUT of an object's own bytes back to the same key, and when gossip was not running — every unit test — sent nothing and added the byte count to `BytesReplicated` anyway. The one test covering it asserted `c.replicator != nil`, which is what let it survive: proving a field was assigned proves nothing about the subsystem, and that assignment was the only part of it that worked. The proposal machinery's `broadcastProposal` slept 100ms and then voted for its own proposal, so a majority of one was always found and `executeProposal` called `SetLeader`. A node cannot be made leader by being named. #133 was closed as not-the-direction with the stub still in the tree; #284's criteria said delete. Three of five `EntryType` constants had no producer anywhere — verified by grep, not assumed — so they and the empty switch arms naming them are gone. The surviving strings are unchanged, so an entry of a removed type from an older peer still decodes and applies as the no-op it always was. What replaced the taxonomy is evaluated by the store rather than voted on. A refused conditional write reports `ConditionalLost` and wraps `types.ErrPreconditionFailed`, and is never retried internally: the answer is definitive and only the caller knows what the new bytes should be. A precondition on anything but a put is refused with `ErrInvalidPrecondition` rather than dropped — a caller meaning "delete only if unchanged" that gets an unconditional delete has no way to find out. Cache invalidations now carry the ETag of the write that caused them (R4). The payload was `{Key, From}`, so a receiver could not tell an invalidation for a version it had moved past from one for the version it holds, and gossip both retransmits and reorders. A first attempt held one ETag per key and a test caught it: that suppresses a retransmission of the latest version but applies a replay of the one before it, since an older ETag merely differs and ETags carry no order. The ledger is a bounded set of applied (key, ETag) pairs. Tests are the point of this issue and are verified by mutation. `TestMultiNodeCluster` gives each node its own substrate endpoint and asserts exactly one PUT of the key — the assertion it replaced was `result.Success`, which could not tell one PUT from two. Two coordinators racing an If-Match must produce one success and one `ErrPreconditionFailed` with the winner's bytes stored; a CAS chain must accept each reported ETag and refuse every earlier one. Forcing the path unconditional kills all of them, suppressing the ETag kills two, and removing the invalidation dedup or reverting it to latest-per-key each fail a named assertion. The success half of these runs against a real backend rather than `mockBackend`, whose `PutObjectIf` returns `ErrNotSupported` deliberately — a stub cannot both refuse to fake a CAS and serve as the success case for one. Also fixed, both found while verifying the above rather than by inspection: - `TestClusterManager_BasicOperations` slept 3s against a 2s election timeout whose jitter puts the election in [2s, 4s), so it was a coin flip. Observed failing 1 run in 4. It now polls to the upper bound. - `types.Precondition` had no JSON tags, so it crossed the wire as `Absent`/`ETag` beside `key` and `created_at`. Tagged now while the type is unreleased and it is free; a `TestPreconditionJSON` pins both the names and that a zero precondition is omitted entirely. #144 (implement NegotiateConsistency) is closed as not planned — the type it would negotiate over no longer exists, and its rules all keyed on leadership, which confers no read guarantee when the bytes live in the bucket. #129's `NegotiateConsistency` and `ConsistencyLevel` promotion are corrected in a comment. The Python SDK's three unloadable cluster timeout keys, surfaced while verifying the strict loader, are filed as #385 rather than folded in here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #284. Also closes #144 as not planned (done on the issue), and comments a correction onto #129.
The breaking change, first
cluster.consistency_levelandcluster.cache_replicationare removed from the config file. The loader decodes strictly, so a config that still sets either fails at startup naming the key and the line. That is intended rather than a regression — the alternative is accepting a setting that selects nothing.Migration: delete the lines. There is no replacement value to set.
consistency_level's replacement is per-operation (DistributedOperation.Precondition), andcache_replicationwas read by no code in the repository at all. A deployment that deletes the line gets the behaviour it already had, whichever value it had set.ClusterManager.InvalidateCacheKey(key)also becomesInvalidateCacheKey(key, etag). No production caller existed.What went, and why each was not fixable in place
ConsistencyLeveland its three constants. All three issued the same unconditionalPutObjectand differed only in how many nodes issued it, so what an operator picked changed the request count and not the guarantee.ConsistencyStrongfanned the identical bytes at the identical key to every target node and called majority success "linearizable" — every node writes the same key in the same bucket, S3 holds the single copy, so N-1 of those PUTs were billed requests that changed nothing, and a majority reporting success said only that a majority could reach S3.Deleted rather than cut down to two levels. Under CAS the distinguishing fact is whether the operation carries a precondition, and a
types.Preconditionfield already says that; a two-name enum beside it would be a second encoding ofPrecondition.IsZero().CacheReplicator. Its worker sent N-1 peers a PUT of an object's own bytes back to the same key in the same bucket. When gossip was not running — which was every unit test — it sent nothing and added the byte count toBytesReplicatedanyway. The one test covering it assertedc.replicator != nil, and that assertion is what let it survive: proving a field was assigned proves nothing about the subsystem, and the assignment was the only part of it that worked. Real cache warming is #141.The proposal machinery.
broadcastProposalslept 100ms and then voted for its own proposal, so a majority of one was always found andexecuteProposalcalledSetLeader. A node cannot be made leader by being named — the election path reaches the same setter having actually contested it. #133 was closed as not-the-direction with this stub still in the tree; #284's acceptance criteria said delete rather than fix.Three of five
EntryTypeconstants.EntryTypeConfigChange,EntryTypeOperationandEntryTypeSnapshothad no producer anywhere — verified by grep, not assumed.applyLogEntrywas a five-arm switch with every arm empty; with those gone the remaining branches were indistinguishable, so it collapsed to a log line. The surviving constants' strings are unchanged, so an entry of a removed type arriving from an older peer still decodes and applies as the no-op it always was.What replaced it
Evaluated by the store, not voted on. A refused conditional write reports
ConditionalLostinOperationResult.Conditionaland wrapstypes.ErrPreconditionFailed, and is never retried internally: the answer is definitive, and the recovery is to re-read, recompute and CAS again, which only the caller can do. A precondition attached to anything but a put is refused withErrInvalidPreconditionrather than silently dropped — a caller that means "delete only if unchanged" and gets an unconditional delete has no way to find out.OperationResult.ETagcarries the new version so a CAS loop can chain without a re-read.Cache invalidations carry that ETag (R4). The gossip payload was
{Key, From}and carried no version, so a receiver could not tell an invalidation for a version it had already moved past from one for the version it holds — and gossip both retransmits and reorders, so that is the normal case. A first attempt held one ETag per key, and a test caught it: that suppresses a retransmission of the latest version but applies a replay of the one before it, since an older ETag merely differs and ETags carry no order to compare. The ledger is a bounded set of applied(key, ETag)pairs.It deliberately does not claim to know the cached bytes are newer than an incoming invalidation.
types.Cachestores bytes at offsets with no version alongside them, so there is nothing to compare against; that needs #129'sKeyAnnouncementplumbing and #141's warming work, and is not guessed at here.Tests — the point of the issue, verified by mutation
TestMultiNodeCluster: exactly 1 PUT of the key, counted across one substrate endpoint per nodeIf-Match→ one success, oneErrPreconditionFailed, winner's bytes storedThe write-count assertion replaced
result.Successon aConsistencyStrongwrite, which could not tell one PUT from two. Writes are summed across endpoints rather than checked per-node, because routing is the load balancer's choice — pinning it would assert the routing instead of the request count.The success half of the never-disagree test runs against a real
testawsbackend rather than the package'smockBackend, whosePutObjectIfreturnsErrNotSupporteddeliberately: a stub cannot both refuse to fake a CAS and serve as the success case for one.Two defects found while verifying, fixed here
TestClusterManager_BasicOperationswas a coin flip. It slept exactly 3s againstElectionTimeout: 2s, whose jitter puts the first election in[2s, 4s). Observed failing 1 run in 4; now polls to the upper bound. Three consecutive-race -tags=distributedruns green after.types.Preconditionhad no JSON tags, so it crossed the wire asAbsent/ETagbesidekeyandcreated_at. Tagged while the type is unreleased and it is free rather than a wire break later;TestPreconditionJSONpins the names and that a zero precondition is omitted entirely.Verification
Coverage on the changed packages:
internal/distributed80.6%,internal/config91.3%,pkg/types100%.Out of scope, filed rather than absorbed
Verifying that the strict loader genuinely rejects a stale
consistency_level(it does, naming key and line) surfaced that the Python SDK'sto_yamlemits threeclustertimeout keys the Go schema has never had — they live on the disjointinternal/distributed.ClusterConfig(#139) — so that block fails at load independently of this change. Filed as #385.