HDFS-9389. Add maintenance states to AdminStates. (Ming Ma via lei)

(cherry picked from commit a2774debf7)
This commit is contained in:
Lei Xu 2016-05-12 15:42:54 -07:00
parent bb95a5e18f
commit 782441d47e
4 changed files with 88 additions and 5 deletions

View File

@ -59,7 +59,9 @@ public class DatanodeInfo extends DatanodeID implements Node {
public enum AdminStates { public enum AdminStates {
NORMAL("In Service"), NORMAL("In Service"),
DECOMMISSION_INPROGRESS("Decommission In Progress"), DECOMMISSION_INPROGRESS("Decommission In Progress"),
DECOMMISSIONED("Decommissioned"); DECOMMISSIONED("Decommissioned"),
ENTERING_MAINTENANCE("Entering Maintenance"),
IN_MAINTENANCE("In Maintenance");
final String value; final String value;
@ -376,6 +378,10 @@ public class DatanodeInfo extends DatanodeID implements Node {
buffer.append("Decommissioned\n"); buffer.append("Decommissioned\n");
} else if (isDecommissionInProgress()) { } else if (isDecommissionInProgress()) {
buffer.append("Decommission in progress\n"); buffer.append("Decommission in progress\n");
} else if (isInMaintenance()) {
buffer.append("In maintenance\n");
} else if (isEnteringMaintenance()) {
buffer.append("Entering maintenance\n");
} else { } else {
buffer.append("Normal\n"); buffer.append("Normal\n");
} }
@ -428,6 +434,10 @@ public class DatanodeInfo extends DatanodeID implements Node {
buffer.append(" DD"); buffer.append(" DD");
} else if (isDecommissionInProgress()) { } else if (isDecommissionInProgress()) {
buffer.append(" DP"); buffer.append(" DP");
} else if (isInMaintenance()) {
buffer.append(" IM");
} else if (isEnteringMaintenance()) {
buffer.append(" EM");
} else { } else {
buffer.append(" IN"); buffer.append(" IN");
} }
@ -486,6 +496,53 @@ public class DatanodeInfo extends DatanodeID implements Node {
adminState = AdminStates.DECOMMISSIONED; adminState = AdminStates.DECOMMISSIONED;
} }
/**
* Put a node to maintenance mode.
*/
public void startMaintenance() {
adminState = AdminStates.ENTERING_MAINTENANCE;
}
/**
* Put a node to maintenance mode.
*/
public void setInMaintenance() {
adminState = AdminStates.IN_MAINTENANCE;
}
/**
* Take the node out of maintenance mode.
*/
public void stopMaintenance() {
adminState = null;
}
/**
* Returns true if the node is is entering_maintenance
*/
public boolean isEnteringMaintenance() {
return adminState == AdminStates.ENTERING_MAINTENANCE;
}
/**
* Returns true if the node is in maintenance
*/
public boolean isInMaintenance() {
return adminState == AdminStates.IN_MAINTENANCE;
}
/**
* Returns true if the node is entering or in maintenance
*/
public boolean isMaintenance() {
return (adminState == AdminStates.ENTERING_MAINTENANCE ||
adminState == AdminStates.IN_MAINTENANCE);
}
public boolean isInService() {
return getAdminState() == AdminStates.NORMAL;
}
/** /**
* Retrieves the admin state of this node. * Retrieves the admin state of this node.
*/ */

View File

@ -264,6 +264,10 @@ public class PBHelperClient {
case DECOMMISSION_INPROGRESS: case DECOMMISSION_INPROGRESS:
return DatanodeInfoProto.AdminState.DECOMMISSION_INPROGRESS; return DatanodeInfoProto.AdminState.DECOMMISSION_INPROGRESS;
case DECOMMISSIONED: return DatanodeInfoProto.AdminState.DECOMMISSIONED; case DECOMMISSIONED: return DatanodeInfoProto.AdminState.DECOMMISSIONED;
case ENTERING_MAINTENANCE:
return DatanodeInfoProto.AdminState.ENTERING_MAINTENANCE;
case IN_MAINTENANCE:
return DatanodeInfoProto.AdminState.IN_MAINTENANCE;
default: return DatanodeInfoProto.AdminState.NORMAL; default: return DatanodeInfoProto.AdminState.NORMAL;
} }
} }
@ -589,6 +593,10 @@ public class PBHelperClient {
return AdminStates.DECOMMISSION_INPROGRESS; return AdminStates.DECOMMISSION_INPROGRESS;
case DECOMMISSIONED: case DECOMMISSIONED:
return AdminStates.DECOMMISSIONED; return AdminStates.DECOMMISSIONED;
case ENTERING_MAINTENANCE:
return AdminStates.ENTERING_MAINTENANCE;
case IN_MAINTENANCE:
return AdminStates.IN_MAINTENANCE;
case NORMAL: case NORMAL:
default: default:
return AdminStates.NORMAL; return AdminStates.NORMAL;

View File

@ -92,6 +92,8 @@ message DatanodeInfoProto {
NORMAL = 0; NORMAL = 0;
DECOMMISSION_INPROGRESS = 1; DECOMMISSION_INPROGRESS = 1;
DECOMMISSIONED = 2; DECOMMISSIONED = 2;
ENTERING_MAINTENANCE = 3;
IN_MAINTENANCE = 4;
} }
optional AdminState adminState = 10 [default = NORMAL]; optional AdminState adminState = 10 [default = NORMAL];

View File

@ -27,6 +27,7 @@ import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.MiniDFSNNTopology; import org.apache.hadoop.hdfs.MiniDFSNNTopology;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager;
@ -56,6 +57,7 @@ import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
@ -93,6 +95,12 @@ public class TestNameNodeMXBean {
dd.setUpgradeDomain(upgradeDomain); dd.setUpgradeDomain(upgradeDomain);
String dnXferAddrWithUpgradeDomainSet = dd.getXferAddr(); String dnXferAddrWithUpgradeDomainSet = dd.getXferAddr();
// Put the second DN to maintenance state.
DatanodeDescriptor maintenanceNode = dm.getDatanode(
cluster.getDataNodes().get(1).getDatanodeId());
maintenanceNode.setInMaintenance();
String dnXferAddrInMaintenance = maintenanceNode.getXferAddr();
FSNamesystem fsn = cluster.getNameNode().namesystem; FSNamesystem fsn = cluster.getNameNode().namesystem;
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
@ -151,6 +159,10 @@ public class TestNameNodeMXBean {
} else { } else {
assertTrue(liveNode.get("upgradeDomain").equals(upgradeDomain)); assertTrue(liveNode.get("upgradeDomain").equals(upgradeDomain));
} }
// "adminState" is set to maintenance only for the specific dn.
boolean inMaintenance = liveNode.get("adminState").equals(
DatanodeInfo.AdminStates.IN_MAINTENANCE.toString());
assertFalse(xferAddr.equals(dnXferAddrInMaintenance) ^ inMaintenance);
} }
assertEquals(fsn.getLiveNodes(), alivenodeinfo); assertEquals(fsn.getLiveNodes(), alivenodeinfo);
// get attribute deadnodeinfo // get attribute deadnodeinfo
@ -164,7 +176,8 @@ public class TestNameNodeMXBean {
// get attribute NameJournalStatus // get attribute NameJournalStatus
String nameJournalStatus = (String) (mbs.getAttribute(mxbeanName, String nameJournalStatus = (String) (mbs.getAttribute(mxbeanName,
"NameJournalStatus")); "NameJournalStatus"));
assertEquals("Bad value for NameJournalStatus", fsn.getNameJournalStatus(), nameJournalStatus); assertEquals("Bad value for NameJournalStatus",
fsn.getNameJournalStatus(), nameJournalStatus);
// get attribute JournalTransactionInfo // get attribute JournalTransactionInfo
String journalTxnInfo = (String) mbs.getAttribute(mxbeanName, String journalTxnInfo = (String) mbs.getAttribute(mxbeanName,
"JournalTransactionInfo"); "JournalTransactionInfo");
@ -172,11 +185,13 @@ public class TestNameNodeMXBean {
journalTxnInfo); journalTxnInfo);
// get attribute "CompileInfo" // get attribute "CompileInfo"
String compileInfo = (String) mbs.getAttribute(mxbeanName, "CompileInfo"); String compileInfo = (String) mbs.getAttribute(mxbeanName, "CompileInfo");
assertEquals("Bad value for CompileInfo", fsn.getCompileInfo(), compileInfo); assertEquals("Bad value for CompileInfo", fsn.getCompileInfo(),
compileInfo);
// get attribute CorruptFiles // get attribute CorruptFiles
String corruptFiles = (String) (mbs.getAttribute(mxbeanName, String corruptFiles = (String) (mbs.getAttribute(mxbeanName,
"CorruptFiles")); "CorruptFiles"));
assertEquals("Bad value for CorruptFiles", fsn.getCorruptFiles(), corruptFiles); assertEquals("Bad value for CorruptFiles", fsn.getCorruptFiles(),
corruptFiles);
// get attribute NameDirStatuses // get attribute NameDirStatuses
String nameDirStatuses = (String) (mbs.getAttribute(mxbeanName, String nameDirStatuses = (String) (mbs.getAttribute(mxbeanName,
"NameDirStatuses")); "NameDirStatuses"));
@ -188,7 +203,8 @@ public class TestNameNodeMXBean {
File nameDir = new File(nameDirUri); File nameDir = new File(nameDirUri);
System.out.println("Checking for the presence of " + nameDir + System.out.println("Checking for the presence of " + nameDir +
" in active name dirs."); " in active name dirs.");
assertTrue(statusMap.get("active").containsKey(nameDir.getAbsolutePath())); assertTrue(statusMap.get("active").containsKey(
nameDir.getAbsolutePath()));
} }
assertEquals(2, statusMap.get("active").size()); assertEquals(2, statusMap.get("active").size());
assertEquals(0, statusMap.get("failed").size()); assertEquals(0, statusMap.get("failed").size());