Fixed - failed Redis Master node is not shutdown properly. #1746

pull/1792/head
Nikita Koksharov 6 years ago
parent de1f34498a
commit 9e3e9fe547

@ -76,7 +76,7 @@ public class ClientConnectionsEntry {
}
public boolean isMasterForRead() {
return getFreezeReason() == FreezeReason.SYSTEM && getConfig().getReadMode() == ReadMode.MASTER_SLAVE;
return getFreezeReason() == FreezeReason.SYSTEM && getConfig().getReadMode() == ReadMode.MASTER_SLAVE && getNodeType() == NodeType.MASTER;
}
public void setNodeType(NodeType nodeType) {

@ -188,6 +188,10 @@ public class MasterSlaveEntry {
}
private boolean slaveDown(ClientConnectionsEntry entry) {
if (entry.isMasterForRead()) {
return false;
}
// add master as slave if no more slaves available
if (!config.checkSkipSlavesInit() && slaveBalancer.getAvailableClients() == 0) {
if (slaveBalancer.unfreeze(masterEntry.getClient().getAddr(), FreezeReason.SYSTEM)) {
@ -201,12 +205,24 @@ public class MasterSlaveEntry {
connection.closeAsync();
reattachBlockingQueue(connection);
}
while (true) {
RedisConnection connection = entry.pollConnection();
if (connection == null) {
break;
}
}
entry.getAllConnections().clear();
for (RedisPubSubConnection connection : entry.getAllSubscribeConnections()) {
connection.closeAsync();
connectionManager.getSubscribeService().reattachPubSub(connection);
}
while (true) {
RedisConnection connection = entry.pollSubscribeConnection();
if (connection == null) {
break;
}
}
entry.getAllSubscribeConnections().clear();
return true;
@ -436,6 +452,8 @@ public class MasterSlaveEntry {
slaveBalancer.changeType(oldMaster.getClient().getAddr(), NodeType.SLAVE);
slaveBalancer.changeType(newMasterClient.getAddr(), NodeType.MASTER);
// freeze in slaveBalancer
slaveDown(oldMaster.getClient().getAddr(), FreezeReason.MANAGER);
// more than one slave available, so master can be removed from slaves
if (!config.checkSkipSlavesInit()

@ -164,7 +164,11 @@ public class LoadBalancerManager {
synchronized (connectionEntry) {
// only RECONNECT freeze reason could be replaced
if (connectionEntry.getFreezeReason() == null
|| connectionEntry.getFreezeReason() == FreezeReason.RECONNECT) {
|| connectionEntry.getFreezeReason() == FreezeReason.RECONNECT
|| (freezeReason == FreezeReason.MANAGER
&& connectionEntry.getFreezeReason() != FreezeReason.MANAGER
&& connectionEntry.getNodeType() == NodeType.SLAVE
)) {
connectionEntry.setFreezed(true);
connectionEntry.setFreezeReason(freezeReason);
return connectionEntry;

Loading…
Cancel
Save