mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 20:48:06 +01:00
Combine the read/write breakers for Redis clusters.
This commit is contained in:
committed by
Jon Chambers
parent
ae0f8df11b
commit
5717dc294e
@@ -41,11 +41,11 @@ public class LockingRateLimiter extends RateLimiter {
|
||||
}
|
||||
|
||||
private void releaseLock(String key) {
|
||||
cacheCluster.useWriteCluster(connection -> connection.sync().del(getLockName(key)));
|
||||
cacheCluster.useCluster(connection -> connection.sync().del(getLockName(key)));
|
||||
}
|
||||
|
||||
private boolean acquireLock(String key) {
|
||||
return cacheCluster.withWriteCluster(connection -> connection.sync().set(getLockName(key), "L", SetArgs.Builder.nx().ex(10))) != null;
|
||||
return cacheCluster.withCluster(connection -> connection.sync().set(getLockName(key), "L", SetArgs.Builder.nx().ex(10))) != null;
|
||||
}
|
||||
|
||||
private String getLockName(String key) {
|
||||
|
||||
@@ -85,14 +85,14 @@ public class RateLimiter {
|
||||
}
|
||||
|
||||
public void clear(String key) {
|
||||
cacheCluster.useWriteCluster(connection -> connection.sync().del(getBucketName(key)));
|
||||
cacheCluster.useCluster(connection -> connection.sync().del(getBucketName(key)));
|
||||
}
|
||||
|
||||
private void setBucket(String key, LeakyBucket bucket) {
|
||||
try {
|
||||
final String serialized = bucket.serialize(mapper);
|
||||
|
||||
cacheCluster.useWriteCluster(connection -> connection.sync().setex(getBucketName(key), (int) Math.ceil((bucketSize / leakRatePerMillis) / 1000), serialized));
|
||||
cacheCluster.useCluster(connection -> connection.sync().setex(getBucketName(key), (int) Math.ceil((bucketSize / leakRatePerMillis) / 1000), serialized));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class RateLimiter {
|
||||
|
||||
private LeakyBucket getBucket(String key) {
|
||||
try {
|
||||
final String serialized = cacheCluster.withReadCluster(connection -> connection.sync().get(getBucketName(key)));
|
||||
final String serialized = cacheCluster.withCluster(connection -> connection.sync().get(getBucketName(key)));
|
||||
|
||||
if (serialized != null) {
|
||||
return LeakyBucket.fromSerialized(mapper, serialized);
|
||||
|
||||
Reference in New Issue
Block a user