YARN-7585. NodeManager should go unhealthy when state store throws DBException. Contributed by Wilfred Spiegelenburg.
(cherry picked from commit 7f515f57ede74dae787994f37bfafd5d20c9aa4c)
This commit is contained in:
parent
056b54c62c
commit
655154cb45
@ -456,6 +456,7 @@ protected void serviceInit(Configuration conf) throws Exception {
|
|||||||
// so that we make sure everything is up before registering with RM.
|
// so that we make sure everything is up before registering with RM.
|
||||||
addService(nodeStatusUpdater);
|
addService(nodeStatusUpdater);
|
||||||
((NMContext) context).setNodeStatusUpdater(nodeStatusUpdater);
|
((NMContext) context).setNodeStatusUpdater(nodeStatusUpdater);
|
||||||
|
nmStore.setNodeStatusUpdater(nodeStatusUpdater);
|
||||||
|
|
||||||
// Do secure login before calling init for added services.
|
// Do secure login before calling init for added services.
|
||||||
try {
|
try {
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
|
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
|
||||||
import org.apache.hadoop.yarn.server.api.records.MasterKey;
|
import org.apache.hadoop.yarn.server.api.records.MasterKey;
|
||||||
import org.apache.hadoop.yarn.server.api.records.impl.pb.MasterKeyPBImpl;
|
import org.apache.hadoop.yarn.server.api.records.impl.pb.MasterKeyPBImpl;
|
||||||
|
import org.apache.hadoop.yarn.server.nodemanager.NodeStatusUpdater;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ResourceMappings;
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ResourceMappings;
|
||||||
import org.apache.hadoop.yarn.server.records.Version;
|
import org.apache.hadoop.yarn.server.records.Version;
|
||||||
@ -158,6 +159,7 @@ public class NMLeveldbStateStoreService extends NMStateStoreService {
|
|||||||
|
|
||||||
private DB db;
|
private DB db;
|
||||||
private boolean isNewlyCreated;
|
private boolean isNewlyCreated;
|
||||||
|
private boolean isHealthy;
|
||||||
private Timer compactionTimer;
|
private Timer compactionTimer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -172,6 +174,8 @@ public NMLeveldbStateStoreService() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startStorage() throws IOException {
|
protected void startStorage() throws IOException {
|
||||||
|
// Assume that we're healthy when we start
|
||||||
|
isHealthy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -190,6 +194,36 @@ public boolean isNewlyCreated() {
|
|||||||
return isNewlyCreated;
|
return isNewlyCreated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the state store throws an error after recovery has been performed
|
||||||
|
* then we can not trust it any more to reflect the NM state. We need to
|
||||||
|
* mark the store and node unhealthy.
|
||||||
|
* Errors during the recovery will cause a service failure and thus a NM
|
||||||
|
* start failure. Do not need to mark the store unhealthy for those.
|
||||||
|
* @param dbErr Exception
|
||||||
|
*/
|
||||||
|
private void markStoreUnHealthy(DBException dbErr) {
|
||||||
|
// Always log the error here, we might not see the error in the caller
|
||||||
|
LOG.error("Statestore exception: ", dbErr);
|
||||||
|
// We have already been marked unhealthy so no need to do it again.
|
||||||
|
if (!isHealthy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Mark unhealthy, an out of band heartbeat will be sent and the state
|
||||||
|
// will remain unhealthy (not recoverable).
|
||||||
|
// No need to close the store: does not make any difference at this point.
|
||||||
|
isHealthy = false;
|
||||||
|
// We could get here before the nodeStatusUpdater is set
|
||||||
|
NodeStatusUpdater nsu = getNodeStatusUpdater();
|
||||||
|
if (nsu != null) {
|
||||||
|
nsu.reportException(dbErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean isHealthy() {
|
||||||
|
return isHealthy;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RecoveredContainerState> loadContainersState()
|
public List<RecoveredContainerState> loadContainersState()
|
||||||
@ -362,6 +396,7 @@ public void storeContainer(ContainerId containerId, int containerVersion,
|
|||||||
db.write(batch);
|
db.write(batch);
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -386,6 +421,7 @@ public void storeContainerQueued(ContainerId containerId) throws IOException {
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), EMPTY_VALUE);
|
db.put(bytes(key), EMPTY_VALUE);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -401,6 +437,7 @@ private void removeContainerQueued(ContainerId containerId)
|
|||||||
try {
|
try {
|
||||||
db.delete(bytes(key));
|
db.delete(bytes(key));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -416,6 +453,7 @@ public void storeContainerPaused(ContainerId containerId) throws IOException {
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), EMPTY_VALUE);
|
db.put(bytes(key), EMPTY_VALUE);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -432,6 +470,7 @@ public void removeContainerPaused(ContainerId containerId)
|
|||||||
try {
|
try {
|
||||||
db.delete(bytes(key));
|
db.delete(bytes(key));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -449,6 +488,7 @@ public void storeContainerDiagnostics(ContainerId containerId,
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), bytes(diagnostics.toString()));
|
db.put(bytes(key), bytes(diagnostics.toString()));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,6 +507,7 @@ public void storeContainerLaunched(ContainerId containerId)
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), EMPTY_VALUE);
|
db.put(bytes(key), EMPTY_VALUE);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -496,6 +537,7 @@ public void storeContainerUpdateToken(ContainerId containerId,
|
|||||||
batch.close();
|
batch.close();
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -512,6 +554,7 @@ public void storeContainerKilled(ContainerId containerId)
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), EMPTY_VALUE);
|
db.put(bytes(key), EMPTY_VALUE);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -528,6 +571,7 @@ public void storeContainerCompleted(ContainerId containerId,
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), bytes(Integer.toString(exitCode)));
|
db.put(bytes(key), bytes(Integer.toString(exitCode)));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -540,6 +584,7 @@ public void storeContainerRemainingRetryAttempts(ContainerId containerId,
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), bytes(Integer.toString(remainingRetryAttempts)));
|
db.put(bytes(key), bytes(Integer.toString(remainingRetryAttempts)));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -552,6 +597,7 @@ public void storeContainerWorkDir(ContainerId containerId,
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), bytes(workDir));
|
db.put(bytes(key), bytes(workDir));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -564,6 +610,7 @@ public void storeContainerLogDir(ContainerId containerId,
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), bytes(logDir));
|
db.put(bytes(key), bytes(logDir));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -597,6 +644,7 @@ public void removeContainer(ContainerId containerId)
|
|||||||
batch.close();
|
batch.close();
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -646,6 +694,7 @@ public void storeApplication(ApplicationId appId,
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), p.toByteArray());
|
db.put(bytes(key), p.toByteArray());
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -667,6 +716,7 @@ public void removeApplication(ApplicationId appId)
|
|||||||
batch.close();
|
batch.close();
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -823,6 +873,7 @@ public void startResourceLocalization(String user, ApplicationId appId,
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), proto.toByteArray());
|
db.put(bytes(key), proto.toByteArray());
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -846,6 +897,7 @@ public void finishResourceLocalization(String user, ApplicationId appId,
|
|||||||
batch.close();
|
batch.close();
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -869,6 +921,7 @@ public void removeLocalizedResource(String user, ApplicationId appId,
|
|||||||
batch.close();
|
batch.close();
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -934,6 +987,7 @@ public void storeDeletionTask(int taskId,
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), taskProto.toByteArray());
|
db.put(bytes(key), taskProto.toByteArray());
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -944,6 +998,7 @@ public void removeDeletionTask(int taskId) throws IOException {
|
|||||||
try {
|
try {
|
||||||
db.delete(bytes(key));
|
db.delete(bytes(key));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1017,6 +1072,7 @@ public void removeNMTokenApplicationMasterKey(
|
|||||||
try {
|
try {
|
||||||
db.delete(bytes(key));
|
db.delete(bytes(key));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1031,6 +1087,7 @@ private void storeMasterKey(String dbKey, MasterKey key)
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(dbKey), pb.getProto().toByteArray());
|
db.put(bytes(dbKey), pb.getProto().toByteArray());
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1104,6 +1161,7 @@ public void storeContainerToken(ContainerId containerId, Long expTime)
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), bytes(expTime.toString()));
|
db.put(bytes(key), bytes(expTime.toString()));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1115,6 +1173,7 @@ public void removeContainerToken(ContainerId containerId)
|
|||||||
try {
|
try {
|
||||||
db.delete(bytes(key));
|
db.delete(bytes(key));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1165,6 +1224,7 @@ public void storeLogDeleter(ApplicationId appId, LogDeleterProto proto)
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(key), proto.toByteArray());
|
db.put(bytes(key), proto.toByteArray());
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1175,6 +1235,7 @@ public void removeLogDeleter(ApplicationId appId) throws IOException {
|
|||||||
try {
|
try {
|
||||||
db.delete(bytes(key));
|
db.delete(bytes(key));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1207,6 +1268,7 @@ public void storeAssignedResources(Container container,
|
|||||||
batch.close();
|
batch.close();
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1370,6 +1432,7 @@ public void storeAMRMProxyNextMasterKey(MasterKey key) throws IOException {
|
|||||||
try {
|
try {
|
||||||
db.delete(bytes(dbkey));
|
db.delete(bytes(dbkey));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -1384,6 +1447,7 @@ public void storeAMRMProxyAppContextEntry(ApplicationAttemptId attempt,
|
|||||||
try {
|
try {
|
||||||
db.put(bytes(fullkey), data);
|
db.put(bytes(fullkey), data);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1395,6 +1459,7 @@ public void removeAMRMProxyAppContextEntry(ApplicationAttemptId attempt,
|
|||||||
try {
|
try {
|
||||||
db.delete(bytes(fullkey));
|
db.delete(bytes(fullkey));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1418,6 +1483,7 @@ public void removeAMRMProxyAppContext(ApplicationAttemptId attempt)
|
|||||||
candidates.add(key);
|
candidates.add(key);
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (iter != null) {
|
if (iter != null) {
|
||||||
@ -1431,6 +1497,7 @@ public void removeAMRMProxyAppContext(ApplicationAttemptId attempt)
|
|||||||
db.delete(bytes(key));
|
db.delete(bytes(key));
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
markStoreUnHealthy(e);
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1552,6 +1619,11 @@ DB getDB() {
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void setDB(DB testDb) {
|
||||||
|
this.db = testDb;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1) Versioning scheme: major.minor. For e.g. 1.0, 1.1, 1.2...1.25, 2.0 etc.
|
* 1) Versioning scheme: major.minor. For e.g. 1.0, 1.1, 1.2...1.25, 2.0 etc.
|
||||||
* 2) Any incompatible change of state-store is a major upgrade, and any
|
* 2) Any incompatible change of state-store is a major upgrade, and any
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
import org.apache.hadoop.yarn.proto.YarnServerNodemanagerRecoveryProtos.LogDeleterProto;
|
import org.apache.hadoop.yarn.proto.YarnServerNodemanagerRecoveryProtos.LogDeleterProto;
|
||||||
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
|
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
|
||||||
import org.apache.hadoop.yarn.server.api.records.MasterKey;
|
import org.apache.hadoop.yarn.server.api.records.MasterKey;
|
||||||
|
import org.apache.hadoop.yarn.server.nodemanager.NodeStatusUpdater;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
|
||||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ResourceMappings;
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ResourceMappings;
|
||||||
|
|
||||||
@ -51,10 +52,20 @@
|
|||||||
@Unstable
|
@Unstable
|
||||||
public abstract class NMStateStoreService extends AbstractService {
|
public abstract class NMStateStoreService extends AbstractService {
|
||||||
|
|
||||||
|
private NodeStatusUpdater nodeStatusUpdater = null;
|
||||||
|
|
||||||
public NMStateStoreService(String name) {
|
public NMStateStoreService(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected NodeStatusUpdater getNodeStatusUpdater() {
|
||||||
|
return nodeStatusUpdater;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNodeStatusUpdater(NodeStatusUpdater nodeStatusUpdater) {
|
||||||
|
this.nodeStatusUpdater = nodeStatusUpdater;
|
||||||
|
}
|
||||||
|
|
||||||
public static class RecoveredApplicationsState {
|
public static class RecoveredApplicationsState {
|
||||||
List<ContainerManagerApplicationProto> applications;
|
List<ContainerManagerApplicationProto> applications;
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
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.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.isNull;
|
import static org.mockito.Mockito.isNull;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.timeout;
|
import static org.mockito.Mockito.timeout;
|
||||||
@ -89,10 +90,12 @@
|
|||||||
import org.apache.hadoop.yarn.server.security.BaseNMTokenSecretManager;
|
import org.apache.hadoop.yarn.server.security.BaseNMTokenSecretManager;
|
||||||
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
|
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
|
||||||
import org.iq80.leveldb.DB;
|
import org.iq80.leveldb.DB;
|
||||||
|
import org.iq80.leveldb.DBException;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public class TestNMLeveldbStateStoreService {
|
public class TestNMLeveldbStateStoreService {
|
||||||
private static final File TMP_DIR = new File(
|
private static final File TMP_DIR = new File(
|
||||||
@ -1185,6 +1188,38 @@ public void testStateStoreForResourceMapping() throws IOException {
|
|||||||
resourceMappings.getAssignedResources("numa").equals(numaRes));
|
resourceMappings.getAssignedResources("numa").equals(numaRes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStateStoreNodeHealth() throws IOException {
|
||||||
|
// keep the working DB clean, break a temp DB
|
||||||
|
DB keepDB = stateStore.getDB();
|
||||||
|
DB myMocked = mock(DB.class);
|
||||||
|
stateStore.setDB(myMocked);
|
||||||
|
|
||||||
|
ApplicationId appId = ApplicationId.newInstance(1234, 1);
|
||||||
|
ApplicationAttemptId appAttemptId =
|
||||||
|
ApplicationAttemptId.newInstance(appId, 1);
|
||||||
|
DBException toThrow = new DBException();
|
||||||
|
Mockito.doThrow(toThrow).when(myMocked).
|
||||||
|
put(any(byte[].class), any(byte[].class));
|
||||||
|
// write some data
|
||||||
|
try {
|
||||||
|
// chosen a simple method could be any of the "void" methods
|
||||||
|
ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1);
|
||||||
|
stateStore.storeContainerKilled(containerId);
|
||||||
|
} catch (IOException ioErr) {
|
||||||
|
// Cause should be wrapped DBException
|
||||||
|
assertTrue(ioErr.getCause() instanceof DBException);
|
||||||
|
// check the store is marked unhealthy
|
||||||
|
assertFalse("Statestore should have been unhealthy",
|
||||||
|
stateStore.isHealthy());
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
// restore the working DB
|
||||||
|
stateStore.setDB(keepDB);
|
||||||
|
}
|
||||||
|
Assert.fail("Expected exception not thrown");
|
||||||
|
}
|
||||||
|
|
||||||
private StartContainerRequest storeMockContainer(ContainerId containerId)
|
private StartContainerRequest storeMockContainer(ContainerId containerId)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// create a container request
|
// create a container request
|
||||||
|
Loading…
x
Reference in New Issue
Block a user