|
|
@ -139,25 +139,28 @@ public class MasterSlaveEntry {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
masterEntry = new ClientConnectionsEntry(
|
|
|
|
masterEntry = new ClientConnectionsEntry(
|
|
|
|
client,
|
|
|
|
client,
|
|
|
|
config.getMasterConnectionMinimumIdleSize(),
|
|
|
|
config.getMasterConnectionMinimumIdleSize(),
|
|
|
|
config.getMasterConnectionPoolSize(),
|
|
|
|
config.getMasterConnectionPoolSize(),
|
|
|
|
config.getSubscriptionConnectionMinimumIdleSize(),
|
|
|
|
config.getSubscriptionConnectionMinimumIdleSize(),
|
|
|
|
config.getSubscriptionConnectionPoolSize(),
|
|
|
|
config.getSubscriptionConnectionPoolSize(),
|
|
|
|
connectionManager,
|
|
|
|
connectionManager,
|
|
|
|
NodeType.MASTER);
|
|
|
|
NodeType.MASTER);
|
|
|
|
|
|
|
|
|
|
|
|
CountableListener<RedisClient> listener = new CountableListener<RedisClient>(result, client);
|
|
|
|
|
|
|
|
RFuture<Void> writeFuture = writeConnectionPool.add(masterEntry);
|
|
|
|
|
|
|
|
listener.incCounter();
|
|
|
|
|
|
|
|
writeFuture.addListener(listener);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (config.getSubscriptionMode() == SubscriptionMode.MASTER) {
|
|
|
|
int counter = 1;
|
|
|
|
RFuture<Void> pubSubFuture = pubSubConnectionPool.add(masterEntry);
|
|
|
|
if (config.getSubscriptionMode() == SubscriptionMode.MASTER) {
|
|
|
|
listener.incCounter();
|
|
|
|
counter++;
|
|
|
|
pubSubFuture.addListener(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CountableListener<RedisClient> listener = new CountableListener<RedisClient>(result, client, counter);
|
|
|
|
|
|
|
|
RFuture<Void> writeFuture = writeConnectionPool.add(masterEntry);
|
|
|
|
|
|
|
|
writeFuture.addListener(listener);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (config.getSubscriptionMode() == SubscriptionMode.MASTER) {
|
|
|
|
|
|
|
|
RFuture<Void> pubSubFuture = pubSubConnectionPool.add(masterEntry);
|
|
|
|
|
|
|
|
pubSubFuture.addListener(listener);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -465,19 +468,22 @@ public class MasterSlaveEntry {
|
|
|
|
&& slaveBalancer.getAvailableClients() > 1) {
|
|
|
|
&& slaveBalancer.getAvailableClients() > 1) {
|
|
|
|
slaveDown(newMasterClient.getAddr(), FreezeReason.SYSTEM);
|
|
|
|
slaveDown(newMasterClient.getAddr(), FreezeReason.SYSTEM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
connectionManager.shutdownAsync(oldMaster.getClient());
|
|
|
|
oldMaster.getClient().shutdownAsync();
|
|
|
|
log.info("master {} has changed to {}", oldMaster.getClient().getAddr(), masterEntry.getClient().getAddr());
|
|
|
|
log.info("master {} has changed to {}", oldMaster.getClient().getAddr(), masterEntry.getClient().getAddr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void shutdownMasterAsync() {
|
|
|
|
public RFuture<Void> shutdownAsync() {
|
|
|
|
if (!active.compareAndSet(true, false)) {
|
|
|
|
if (!active.compareAndSet(true, false)) {
|
|
|
|
return;
|
|
|
|
return RedissonPromise.<Void>newSucceededFuture(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
connectionManager.shutdownAsync(masterEntry.getClient());
|
|
|
|
RPromise<Void> result = new RedissonPromise<Void>();
|
|
|
|
slaveBalancer.shutdownAsync();
|
|
|
|
CountableListener<Void> listener = new CountableListener<Void>(result, null, 2);
|
|
|
|
|
|
|
|
masterEntry.getClient().shutdownAsync().addListener(listener);
|
|
|
|
|
|
|
|
slaveBalancer.shutdownAsync().addListener(listener);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RFuture<RedisConnection> connectionWriteOp(RedisCommand<?> command) {
|
|
|
|
public RFuture<RedisConnection> connectionWriteOp(RedisCommand<?> command) {
|
|
|
@ -526,15 +532,6 @@ public class MasterSlaveEntry {
|
|
|
|
slaveBalancer.returnConnection(connection);
|
|
|
|
slaveBalancer.returnConnection(connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void shutdown() {
|
|
|
|
|
|
|
|
if (!active.compareAndSet(true, false)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
masterEntry.getClient().shutdown();
|
|
|
|
|
|
|
|
slaveBalancer.shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void addSlotRange(Integer range) {
|
|
|
|
public void addSlotRange(Integer range) {
|
|
|
|
slots.add(range);
|
|
|
|
slots.add(range);
|
|
|
|
}
|
|
|
|
}
|
|
|
|