qqeasonchen opened a new pull request, #5368:
URL: https://github.com/apache/eventmesh/pull/5368

   ## What this PR does
   
   Closes #5357 — Phase 0 enforcement of the production-HA plan (#5354): 
**`EventMeshFrame` becomes deeply immutable.** A frame that can be mutated 
after publish lets two concurrent dispatchers race on the same instance; the 
attribute map was also aliased from codec accumulators at construction.
   
   ### 1. `EventMeshFrame` changes
   
   | Aspect | Before | After |
   |---|---|---|
   | Constructor | `this.attrs = attrs` — aliases the caller's map (codec 
accumulators could mutate a live frame) | deep copy (`new 
LinkedHashMap<>(attrs)`); null map/data normalized |
   | `attributes()` | returns the internal mutable map | 
`Collections.unmodifiableMap(attrs)` |
   | Derivation | mutate the returned map | new `withAttribute(name, value)` — 
derives a new frame with one attribute set (null removes); source unchanged |
   
   ### 2. Call-site migration
   
   Verified by grep over **all 72 `attributes()` usages** — production code had 
**zero** mutation sites; exactly 3 test files mutated the returned map:
   
   - `RestartCursorAlignmentTest` / `MqCursorRecordingTest`: POP-cursor 
stamping now chains `withAttribute`
   - `FrameProtocolConversionTest.framePopCkStampedForDeferredAck`: converted 
from a *mutability* test to an *immutability* test (asserts `withAttribute` 
derives a stamped frame, source unchanged, `attributes().put` throws 
`UnsupportedOperationException`)
   
   ### 3. ArchUnit guardrail (14 → 15 rules)
   
   - **`ruleEventMeshFrameImmutable`** — only 
`org.apache.eventmesh.common.wire..` may implement `EventMeshFrame*` types, so 
no other class can grow frame-mutating APIs.
   
   ### Verification (full local CI parity, Temurin 21.0.11)
   
   ```
   :eventmesh-architecture-guard:test + :eventmesh-common:test + 
:eventmesh-runtime:test  BUILD SUCCESSFUL
   checkstyleMain/Test ×3 modules (maxWarnings=0)                               
           BUILD SUCCESSFUL
   ./gradlew clean build dist jacocoTestReport (CI task set)                    
          BUILD SUCCESSFUL (11m12s)
   ```
   
   ### Relations
   
   - Closes #5357 (Phase 0, P0)
   - Parent: #5354 · Plan: `docs/architecture-review/production-ha-plan.md` (PR 
#5366)
   - Blocks: #5361 (`FrameLimits` builds on the immutable API)
   
   Co-authored-by: qqeasonchen <[email protected]>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to