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

   ## What this PR does
   
   Closes #5358 — Phase 0 enforcement of the production-HA plan (#5354): 
**quota acquire must have a guaranteed paired release.** Gauge-style resources 
(CONNECTIONS / SUBSCRIPTIONS / BACKLOG) leak when acquired and never returned; 
today nothing structural prevents the next call site from doing exactly that.
   
   ### 1. New API (`security.gate`)
   
   | Class | Purpose |
   |---|---|
   | **`QuotaHandle`** (new) | `AutoCloseable` release handle. `close()` 
releases exactly once; double-close is a no-op; non-releasable (THROUGHPUT) 
handles don't release — window counters self-expire. |
   | **`SecurityGate.acquire(ctx, frame)`** (new) | Same auth/ACL-first flow as 
`check()`, then returns the paired handle. Throws `QuotaExceededException` 
(new) when exhausted — no slot consumed. |
   | `QuotaExceededException` (new) | HTTP handlers map to `429`. |
   
   Callers wrap gauge work in try-with-resources so release runs on success, 
failure and cancellation alike:
   
   ```java
   try (QuotaHandle h = gate.acquire(ctx, frame)) {
       // gauge-style work (connection / subscription / backlog)
   }
   ```
   
   ### 2. ArchUnit guardrail (15 → 16 rules)
   
   - **`ruleQuotaManagerOnlyFromGate`** — `QuotaManager.tryAcquire/release` may 
only be called from the `security.gate` package. Any direct manager call 
outside the gate bypasses the pairing contract and **fails the build**.
   
   ### 3. Verification (full local CI parity, Temurin 21.0.11)
   
   ```
   QuotaHandleTest (new, 4 cases): close-releases-exactly-once · 
try-with-resources on exception ·
                                    THROUGHPUT no-release · 
exhausted-throws-without-consuming   PASS
   checkstyleMain/Test + guard tests (maxWarnings=0)                            
               BUILD SUCCESSFUL
   ./gradlew clean build dist jacocoTestReport (CI task set)                    
              BUILD SUCCESSFUL (7m59s)
   ```
   
   ### Relations
   
   - Closes #5358 (Phase 0, P0) — completes Phase 0 (all three guardrail issues 
#5356/#5357/#5358 landed)
   - Parent: #5354 · Plan: `docs/architecture-review/production-ha-plan.md` (PR 
#5366)
   - Unblocks #5362 (QuotaHandle + A2A operation classification builds on this 
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