Repository navigation
Use atomic Swoole Table operations for shared framework state - #128
Conversation
Record which single-row operations can run under the native bucket lock and where cache flushes, paired presence transitions and grouped rate limits still need coordination across rows. Document the failure modes, caller contracts and regression cases for each driver.
Declare the five native methods missing from the bundled Table stub so applications and framework packages can analyze conditional writes and atomic deletions. Use the existing common stub loader and preserve the extension's parameter names and return types.
Collect keys before deleting them so a flush visits every collision row while holding the writer barrier. Compare the observed expiry or lock payload during stale cleanup, and compare the full eviction candidate at deletion so a concurrent hit can save it. Update only existing rows for LRU hits and touches. Distinguish failed allocations from contention and successful counter writes, while keeping ordinary cache write exceptions available to failover. Cover both flush families, interval refresh, races and table exhaustion with real tables.
Explain when an add with a positive TTL or a lock acquisition returns false, and when the Swoole store throws because it cannot allocate a row. Describe what callers can rely on when a counter returns a value.
Consume smoothing markers in one operation and condition throttle renewals on the observed timestamp. Distinguish duplicate inserts from capacity failures even when Swoole warnings are disabled. Reserve both presence rows before publishing either count, and check the connection cap before incrementing under the app stripe. This keeps first and last member events paired and prevents a rejected connection from temporarily occupying a slot. Cover competing clears, renewals, slot releases and exhausted tables.
Handle the native allocation result at the write boundary so framework warning conversion cannot bypass rollback, pruning and retry. Read each distinct group key once and preserve whether the physical row existed. Prune only rows that still have the expired deadline observed by the scan. Keep the key stripe during deletion so pruning cooperates with group rollback. Exercise exhaustion with production warning handling and verify that a renewed window survives maintenance.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
@coderabbitai review |
Action performed
|
PR Summary by QodoUse atomic Swoole Table operations for shared framework state
AI Description
Merge Risk
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link |
[High impact] The PR appears safe to merge; no actionable new issues were found. SummaryUses atomic Swoole Table operations to protect shared cache, Reverb, and rate-limit state.
No actionable new issues or rule violations were found. Tests were not run during this review. Reviews (2) · Last reviewed commit: "Document how flushing a large Swoole cac..." · Reviewed by Greptile |
Record how conditional writes expose allocation failures under both Swoole warning settings. Distinguish live cache hits from reads that need a stripe to remove an expired item during a flush.
…modes Handle the native allocation warning at the checked write so add, counter updates, and lock acquisition report the logical key and the table settings an operator can adjust. Ordinary writes still pass native exceptions through to cache failover. Exercise the three conditional operations on a full table with warnings enabled and disabled under the framework error handler.
Explain when a competing write or expired-item cleanup can reach the one-second lock timeout. This gives operators a reason to schedule large flushes during low traffic.
|
I updated the PR description with the contribution type, the two flush regression cases, their results before and after the fix, and the local verification commands. |
Contribution type
Problem and change
This PR fixes races using the atomic row operations in Swoole 6.3 in the Swoole cache, Reverb, and the rate limiter. The framework already requires a version of Swoole that provides these methods.
Cache
A flush could report success and leave entries behind. Swoole iterates through colliding keys by position. Deleting one row during the scan moves the next row into its place, and the iterator can skip it. Both cache and lock flushes now collect the matching keys first, then delete them while writers are still excluded.
Stale cleanup compares the expiration or lock payload it observed before deleting a row. Eviction also checks that the whole row still matches at the point of deletion. This matters because a cache hit can update the eviction metadata after the candidate has been selected. LRU hits and TTL updates now modify existing rows without creating new ones.
When the table fills up, a conditional write can fail even though the key is free. The Swoole store now distinguishes that failure from an existing cache entry or a held lock. These failures now identify the cache key or lock name and the configuration that controls table capacity, whether Swoole displays warnings or runs quietly. A counter returns its new value only after the write succeeds. Ordinary write exceptions still reach cache failover.
Reverb
Consuming a webhook smoothing marker now reads its timestamp and removes it in one call. Throttle acquisition can insert a missing marker or replace an expired timestamp only if it still matches. If another worker clears or renews the marker, the caller reads it again. A full table still follows the existing error-reporting path.
Connection admission now checks the cap before incrementing the count, under the same lock. Previously, a rejected connection could temporarily occupy a slot and cause a second connection to be refused even after a slot had been released. Presence subscriptions continue to update the channel and member counts together so both transitions belong to the right connection.
Rate limiter
If a group of limits runs out of table space partway through a write, the store restores earlier charges before releasing the locks. Previously the framework's warning handler could throw before that rollback ran. Group admission now reads each distinct key once, and pruning deletes a candidate only if its expired deadline still matches.
Regression coverage
CacheSwooleStoreTest::testFlushDeletesUserRowsAndPreservesControlRowsandtestFlushLocksDeletesLockRowsAndPreservesCacheAndIntervalRowsexercise real collision chains. With the previous implementation, both flushes reported success and left rows they were supposed to remove. With this change, only the expected rows remain.testConditionalWriteReportsAllocationFailurefills a real table. Before the diagnostic fix, displaying Swoole warnings produced an exception containing only the hashed key. The same operations now report the logical key in both warning modes.Verification
composer lint:fixandcomposer analysepassed from the repository root. The cache, Reverb, and rate limiter suites passed, including the forked concurrency tests and the two-worker Reverb integration tests. The focused command for the cache change also passed:composer test:parallel -- --processes=4 --filter='Cache(SwooleStore(Concurrency)?|FailoverStore)Test' tests/CacheSummary by cubic
Uses Swoole 6.3's atomic row operations to eliminate races in the cache, Reverb shared state, and the rate limiter.
Cache
rows/conflict_proportionsettings, behaving the same whether Swoole warnings are enabled or disabled.addand lock acquisition returnfalseversus throw, and note that a flush can make competing writes hit the one-second lock timeout.Reverb and rate limiter
Written for commit dfcfa0d. Summary will update on new commits.
Note
Use atomic Swoole Table operations for shared framework state
add,cmpset,cmpdel,getdel,update) across the cache, rate limiter, and Reverb shared state. Compound mutations still coordinate through row stripes, held by callers.addRow, retries throttle compare-and-set with a fresh read, and checks the connection-slot limit before incrementing. Adds PHPStan stubs in Table.stub.SwooleStore::add,increment, andacquireLockin both cache stores, and counter allocation in Reverb, must handle RuntimeException. Tests cover both Swoole warning modes.Macroscope summarized dfcfa0d.
Summary by CodeRabbit
falseand when insufficient table capacity raises an exception.