-
Notifications
You must be signed in to change notification settings - Fork 0
feat(word): harden distributed single-flight with redisson and redis client unification #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dc69300
feat(word): add redis single-flight dedup for AI analysis
SolfE eb0e5b6
test(word): add single-flight unit and redis integration coverage
SolfE 98c386c
fix(word): avoid invalid-word poisoning on single-flight timeout
SolfE c839037
fix(word): prevent invalid-word poisoning on single-flight replay fai…
SolfE aebd089
tune word single-flight ttl defaults
SolfE cd84b0a
migrate single-flight lock path to redisson
SolfE 04dafa2
migrate redis infra from lettuce to redisson+jedis
SolfE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
41 changes: 6 additions & 35 deletions
41
src/main/java/com/linglevel/api/common/ratelimit/bucket4j/Bucket4jConfig.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,51 +1,22 @@ | ||
| package com.linglevel.api.common.ratelimit.bucket4j; | ||
|
|
||
| import io.github.bucket4j.distributed.proxy.ProxyManager; | ||
| import io.github.bucket4j.redis.lettuce.cas.LettuceBasedProxyManager; | ||
| import io.lettuce.core.RedisClient; | ||
| import io.lettuce.core.RedisURI; | ||
| import io.lettuce.core.api.StatefulRedisConnection; | ||
| import io.lettuce.core.codec.ByteArrayCodec; | ||
| import io.lettuce.core.codec.RedisCodec; | ||
| import io.lettuce.core.codec.StringCodec; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import io.github.bucket4j.redis.redisson.Bucket4jRedisson; | ||
| import org.redisson.Redisson; | ||
| import org.redisson.api.RedissonClient; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| /** | ||
| * Bucket4j configuration for rate limiting with Redis backend. | ||
| */ | ||
| @Configuration | ||
| public class Bucket4jConfig { | ||
|
|
||
| @Value("${spring.data.redis.host}") | ||
| private String host; | ||
|
|
||
| @Value("${spring.data.redis.port}") | ||
| private int port; | ||
|
|
||
| @Value("${spring.data.redis.ssl.enabled}") | ||
| private boolean ssl; | ||
|
|
||
| @Bean | ||
| public ProxyManager<String> proxyManager() { | ||
| RedisURI.Builder uriBuilder = RedisURI.builder() | ||
| .withHost(host) | ||
| .withPort(port) | ||
| .withTimeout(Duration.ofSeconds(10)); | ||
|
|
||
| if (ssl) { | ||
| uriBuilder.withSsl(true); | ||
| } | ||
|
|
||
| RedisClient redisClient = RedisClient.create(uriBuilder.build()); | ||
| StatefulRedisConnection<String, byte[]> connection = redisClient.connect( | ||
| RedisCodec.of(StringCodec.UTF8, ByteArrayCodec.INSTANCE) | ||
| ); | ||
|
|
||
| return LettuceBasedProxyManager.builderFor(connection) | ||
| public ProxyManager<String> proxyManager(RedissonClient redissonClient) { | ||
| Redisson redisson = (Redisson) redissonClient; | ||
| return Bucket4jRedisson.casBasedBuilder(redisson.getCommandExecutor()) | ||
| .build(); | ||
| } | ||
| } |
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
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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/linglevel/api/word/service/WordSingleFlightLeaderFailureException.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.linglevel.api.word.service; | ||
|
|
||
| public class WordSingleFlightLeaderFailureException extends RuntimeException { | ||
|
|
||
| public WordSingleFlightLeaderFailureException(String message) { | ||
| super(message); | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/linglevel/api/word/service/WordSingleFlightProperties.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.linglevel.api.word.service; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @Component | ||
| @ConfigurationProperties(prefix = "word.single-flight") | ||
| public class WordSingleFlightProperties { | ||
|
|
||
| private boolean enabled = true; | ||
|
|
||
| private long lockTtlMs = 20_000; | ||
|
|
||
| private long waitTimeoutMs = 5_000; | ||
|
|
||
| private long resultTtlMs = 60_000; | ||
|
|
||
| private String promptVersion = "v1"; | ||
|
|
||
| private String model = "default"; | ||
|
|
||
| private String schemaVersion = "v2"; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.