Feature - TransactionalOperation.syncSlaves setting added #4083

pull/4099/head
Nikita Koksharov 3 years ago
parent e7cc8fd81b
commit 733c427a5b

@ -29,6 +29,7 @@ public final class TransactionOptions {
private int retryAttempts = 3;
private long retryInterval = 1500;
private int syncSlaves = 0;
private long syncTimeout = 5000;
private long timeout = 5000;
@ -87,8 +88,8 @@ public final class TransactionOptions {
* <p>
* Default is <code>1500 milliseconds</code>
*
* @param retryInterval - time interval
* @param retryIntervalUnit - time interval unit
* @param retryInterval time interval
* @param retryIntervalUnit time interval unit
* @return self instance
*/
public TransactionOptions retryInterval(long retryInterval, TimeUnit retryIntervalUnit) {
@ -97,14 +98,13 @@ public final class TransactionOptions {
}
/**
* Synchronization data timeout between Redis master participating in transaction and its slaves.
* <p>
* Default is <code>5000 milliseconds</code>
*
* @param syncTimeout - synchronization timeout
* @param syncUnit - synchronization timeout time unit
* Use {@link #syncSlaves} method instead.
*
* @param syncTimeout synchronization timeout
* @param syncUnit synchronization timeout time unit
* @return self instance
*/
@Deprecated
public TransactionOptions syncSlavesTimeout(long syncTimeout, TimeUnit syncUnit) {
this.syncTimeout = syncUnit.toMillis(syncTimeout);
return this;
@ -113,6 +113,33 @@ public final class TransactionOptions {
return syncTimeout;
}
/**
* Synchronize write operations execution within defined timeout
* across specified amount of Redis slave nodes.
* <p>
* Default slaves value is <code>0</code> which means available slaves
* at the moment of execution and <code>-1</code> means no sync at all.
* <p>
* Default timeout value is <code>5000 milliseconds</code>
* NOTE: Redis 3.0+ required
*
* @param slaves slaves amount for synchronization.
* Default value is <code>0</code> which means available slaves
* at the moment of execution and <code>-1</code> means no sync at all.
* @param timeout synchronization timeout
* @param unit synchronization timeout time unit
* @return self instance
*/
public TransactionOptions syncSlaves(int slaves, long timeout, TimeUnit unit) {
this.syncSlaves = slaves;
this.syncTimeout = unit.toMillis(timeout);
return this;
}
public int getSyncSlaves() {
return syncSlaves;
}
public long getTimeout() {
return timeout;
}

@ -218,6 +218,11 @@ public class RedissonTransaction implements RTransaction {
private BatchOptions createOptions() {
MasterSlaveEntry entry = commandExecutor.getConnectionManager().getEntrySet().iterator().next();
int syncSlaves = entry.getAvailableSlaves();
if (options.getSyncSlaves() == -1) {
syncSlaves = 0;
} else if (options.getSyncSlaves() > 0) {
syncSlaves = options.getSyncSlaves();
}
BatchOptions batchOptions = BatchOptions.defaults()
.syncSlaves(syncSlaves, options.getSyncTimeout(), TimeUnit.MILLISECONDS)

Loading…
Cancel
Save