feat:support rate-limit window expiration.#672
Open
SkyeBeFreeman wants to merge 4 commits into
Open
Conversation
5db3c9e to
bcc896d
Compare
b204ecd to
6fd5213
Compare
6fd5213 to
8077188
Compare
Signed-off-by: Haotian Zhang <928016560@qq.com>
…rt conflict - Add StreamResourceTest to reproduce the bug where counters.putIfAbsent fails to replace old DurationBaseCallback after rule revision update, causing server quota responses to be routed to stale windows - Fix WindowExpireAndRecoverTest port conflict in CI by using dynamic port allocation (-1) instead of hardcoded port 10097 - Add debug-level diagnostic logs for rate limit quota synchronization, local usage reporting, mode degradation and period boundary reset Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Haotian Zhang <928016560@qq.com>
95d47b1 to
1c82286
Compare
…piration Concurrency fixes: - AsyncRateLimitConnector: stop overwriting uniqueKey parameter; use streamCounterSet.getNode() when removing from nodeToStream after host switch; switch nodeToStream/uniqueKeyToStream to ConcurrentHashMap since peekStreamCounterSet is called from sync thread - RateLimitExtension.submitSyncTask: replace containsKey+put with atomic computeIfAbsent and stop resetting window status on duplicate (prevents init-state-machine corruption) - RateLimitExtension.submitExpireJob: null out expireFuture before reschedule to avoid stale reference if scheduleWithFixedDelay throws RejectedExecutionException - RateLimitExtension.stopSyncTask: skip cleanTask when syncExecutor.isShutdown() instead of inlining; add peekStreamCounterSet to avoid creating a stream during cleanup - RateLimitWindowSet: short-circuit on expired container in getRateLimitWindow; cleanupContainers/deleteRules use compute for atomic predicate+remove; markExpired before unInit so concurrent reads see DELETED via expired-container short-circuit - StreamResource.handleRateLimitInitResponse: replace putIfAbsent+put with counters.compute (decision and write under one bin lock); status guard now allows both INITIALIZING and INITIALIZED so redoInit responses are not dropped - WindowContainer: AtomicBoolean expired flag set before unInit in checkAndCleanExpiredWindows - RateLimitWindow.unInit: also stopSyncTask for TSF cluster (was skipped due to LOCAL_MODE check) Tests: - StreamResourceTest: counterKey reuse across rule revisions, DELETED window drops response, redoInit accepted in INITIALIZED, hasInit threshold - AsyncRateLimitConnectorTest: uniqueKey overwrite, nodeToStream remove key, peek does not create - RateLimitExtensionStopSyncTaskTest: no stream creation when stream already gone, duplicate submitSyncTask does not reset status nor schedule new - RateLimitWindowSetTest: cleanup vs concurrent add race, getRateLimitWindow expired short-circuit, addLabelToRevision atomicity - RateLimitWindowTsfUnInitTest: TSF window must stop sync task on unInit - SubmitPolarisRemoteSyncTaskTest: drop obsolete duplicate-submit assertion (covered by client-module test) Misc: - @justfortest constructors on RateLimitWindow / StreamResource for unit tests bypassing heavy gRPC / quota-bucket init - unInit javadoc declares container-must-be-marked-expired contract - WindowContainer.checkAndCleanExpiredWindows javadoc clarifies return semantics for mainWindow vs regexSpread modes - AsyncRateLimitConnector class javadoc updated to reflect concurrent access pattern - StreamResource.hasInit log no longer dumps full initRecord at WARN; debug shows full map - StreamResource.handleRateLimitInitResponse: LOG.warn moved out of compute lambda to keep bin-lock critical section short - RateLimitConstants: add STOP_SYNC_CLEAN_DELAY_MS, WINDOW_INDEX_EXPIRE_TIME; restore INIT_WAIT_RESPONSE_TIME literal - Remove unused imports (ServiceRouterConfig, ArrayList) and dead helper mockExpiredWindow Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Haotian Zhang <928016560@qq.com>
d21276e to
d7adef8
Compare
Signed-off-by: Haotian Zhang <928016560@qq.com>
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.
fixes #657