mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
* fix(kinesis): serialize shard record appends under concurrent producers
Concurrent PutItem->Kinesis CDC forwarding raced on a plain ArrayList in
KinesisShard, silently dropping ~1-3% of change records under load (rows
persisted in DynamoDB, no stream event emitted, no error).
- KinesisShard: encapsulate records behind a monitor; getRecords() returns a
snapshot; add addRecord()/recordCount(); null-safe setRecords().
- KinesisService: per-stream lock across sequence allocation + shard select +
append + store.put (fixes lost updates, sequence-vs-append ordering, and
stale-snapshot WAL replay); split/merge and deleteStream run under the same
lock with an in-lock re-resolve, closing the delete-vs-append resurrection
race; iteratorStartIndex uses recordCount().
- fix(dynamodb): KinesisStreamingForwarder no longer swallows forwarding
failures as a WARN-and-drop; logs ERROR with stack trace and increments a
forwardFailures counter (no rethrow: forwarding runs post-commit, and the
TTL sweep forwards mid-loop before persisting).
- Tests: concurrent CDC end-to-end, service-layer stress with sequence-order
and AFTER_SEQUENCE_NUMBER continuation, deterministic mutual-exclusion, WAL
persistence/reload, TTL happy + failure-isolation, delete-vs-append.
* fix(kinesis): make shard-list reads safe under concurrent resharding
Follow-up to the CDC record-loss fix, closing the reader-vs-reshard race and a
related shard-id defect.
- KinesisStream.shards -> volatile CopyOnWriteArrayList (+ null-safe setter):
lock-free shard readers (getRecords/peekRecords/getRecordsForAccount/
iterators/inspection) get CME-free snapshots while split/merge (under the
per-stream lock) append. The list is only ever add()-ed, so COWAL is a
drop-in; shard counts are tiny so copy-on-write cost is negligible.
- KinesisJsonHandler.paginateShards: snapshot (List.copyOf) before subList --
a COWAL subList is not snapshot-safe and could still throw CME on ListShards
during a concurrent reshard.
- splitShard: publish both children with a single atomic addAll, and derive
distinct child ids from the base size (previously both children got the same
id on a single-shard split, and a reader could observe a half-built
{parent, child1} topology with a hash-range gap).
Known residual (documented): parent-shard close is not fully atomic w.r.t. the
children add for lock-free readers; producers are unaffected.
Tests: reader-mid-iteration survives split; ListShards page survives concurrent
split; no half-published topology observable (RepeatedTest); child-id
uniqueness + hash-range tiling.
* fix(kinesis): serialize stream metadata writes with deleteStream
Every metadata action did a read-modify-write on the stored stream without the
per-stream monitor: resolve, mutate, store.put. The store hands back the live
instance, so a write that overlapped deleteStream could persist the stale
pre-delete instance after the locked delete had already removed it, resurrecting
the stream, or clobber a stream since recreated under the same name. On the WAL
backend that trailing put also appends a PUT entry after the DELETE, so the
resurrection survives replay.
Ten paths were exposed: updateStreamMode, addTagsToStream, removeTagsFromStream,
startStreamEncryption, stopStreamEncryption, increaseStreamRetentionPeriod,
decreaseStreamRetentionPeriod, enableEnhancedMonitoring,
disableEnhancedMonitoring and updateMaxRecordSize. Each now takes the same
monitor the append and split/merge paths take, and resolves the stream inside it,
so a stream deleted in the meantime surfaces ResourceNotFoundException instead of
being re-persisted. Validation order and the same-value no-op short-circuits are
unchanged, so no client-visible behaviour moves.
The monitor lookup moves behind lockFor, which carries the two-part contract
(hold the monitor, and resolve inside it) and the reason monitors are never
removed from the map. createStream is deliberately left alone: it builds a fresh
instance rather than retaining a resolved one, so it has no stale state to
re-persist and cannot resurrect a deleted stream.
Tests: all ten actions driven through the same interleaving, each wedged inside
its in-lock resolve while a concurrent deleteStream must block on the shared
monitor. That proves the delete lands after the persist and the stream stays
gone. Reverting either half of the fix on a single action fails only that case.
* style: remove em dashes from lines this branch adds
AGENTS.md, Documentation Style: "No em-dashes anywhere, in any content. Use
colons, commas, or periods." Twelve lines added by this branch used one, three
of them in files the branch creates, which also trips the doc-style workflow
since that job scans newly added files.
Scoped strictly to lines this branch adds. Pre-existing em dashes on untouched
lines are left alone, including three in KinesisService and KinesisJsonHandler
that main already carries. A few clauses are reworded rather than resegmented
where a bare colon or comma read badly.