|
@@ -18,6 +18,7 @@
|
|
|
|
|
|
package org.apache.hadoop.yarn.server.resourcemanager.recovery;
|
|
|
|
|
|
+import java.util.EnumSet;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.Map;
|
|
@@ -26,6 +27,7 @@ import java.util.TreeMap;
|
|
|
|
|
|
import javax.crypto.SecretKey;
|
|
|
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
|
@@ -88,7 +90,8 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
public static final Log LOG = LogFactory.getLog(RMStateStore.class);
|
|
|
|
|
|
private enum RMStateStoreState {
|
|
|
- DEFAULT
|
|
|
+ ACTIVE,
|
|
|
+ FENCED
|
|
|
};
|
|
|
|
|
|
private static final StateMachineFactory<RMStateStore,
|
|
@@ -99,17 +102,27 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
RMStateStoreState,
|
|
|
RMStateStoreEventType,
|
|
|
RMStateStoreEvent>(
|
|
|
- RMStateStoreState.DEFAULT)
|
|
|
- .addTransition(RMStateStoreState.DEFAULT, RMStateStoreState.DEFAULT,
|
|
|
+ RMStateStoreState.ACTIVE)
|
|
|
+ .addTransition(RMStateStoreState.ACTIVE, RMStateStoreState.ACTIVE,
|
|
|
RMStateStoreEventType.STORE_APP, new StoreAppTransition())
|
|
|
- .addTransition(RMStateStoreState.DEFAULT, RMStateStoreState.DEFAULT,
|
|
|
+ .addTransition(RMStateStoreState.ACTIVE, RMStateStoreState.ACTIVE,
|
|
|
RMStateStoreEventType.UPDATE_APP, new UpdateAppTransition())
|
|
|
- .addTransition(RMStateStoreState.DEFAULT, RMStateStoreState.DEFAULT,
|
|
|
+ .addTransition(RMStateStoreState.ACTIVE, RMStateStoreState.ACTIVE,
|
|
|
RMStateStoreEventType.REMOVE_APP, new RemoveAppTransition())
|
|
|
- .addTransition(RMStateStoreState.DEFAULT, RMStateStoreState.DEFAULT,
|
|
|
+ .addTransition(RMStateStoreState.ACTIVE, RMStateStoreState.ACTIVE,
|
|
|
RMStateStoreEventType.STORE_APP_ATTEMPT, new StoreAppAttemptTransition())
|
|
|
- .addTransition(RMStateStoreState.DEFAULT, RMStateStoreState.DEFAULT,
|
|
|
- RMStateStoreEventType.UPDATE_APP_ATTEMPT, new UpdateAppAttemptTransition());
|
|
|
+ .addTransition(RMStateStoreState.ACTIVE, RMStateStoreState.ACTIVE,
|
|
|
+ RMStateStoreEventType.UPDATE_APP_ATTEMPT, new UpdateAppAttemptTransition())
|
|
|
+ .addTransition(RMStateStoreState.ACTIVE, RMStateStoreState.FENCED,
|
|
|
+ RMStateStoreEventType.FENCED)
|
|
|
+ .addTransition(RMStateStoreState.FENCED, RMStateStoreState.FENCED,
|
|
|
+ EnumSet.of(
|
|
|
+ RMStateStoreEventType.STORE_APP,
|
|
|
+ RMStateStoreEventType.UPDATE_APP,
|
|
|
+ RMStateStoreEventType.REMOVE_APP,
|
|
|
+ RMStateStoreEventType.STORE_APP_ATTEMPT,
|
|
|
+ RMStateStoreEventType.UPDATE_APP_ATTEMPT,
|
|
|
+ RMStateStoreEventType.FENCED));
|
|
|
|
|
|
private final StateMachine<RMStateStoreState,
|
|
|
RMStateStoreEventType,
|
|
@@ -432,6 +445,11 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
dispatcher.getEventHandler().handle(new RMStateUpdateAppEvent(appState));
|
|
|
}
|
|
|
|
|
|
+ public synchronized void updateFencedState() {
|
|
|
+ this.stateMachine.doTransition(RMStateStoreEventType.FENCED,
|
|
|
+ new RMStateStoreEvent(RMStateStoreEventType.FENCED));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Blocking API
|
|
|
* Derived classes must implement this method to store the state of an
|
|
@@ -494,6 +512,10 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
public synchronized void storeRMDelegationTokenAndSequenceNumber(
|
|
|
RMDelegationTokenIdentifier rmDTIdentifier, Long renewDate,
|
|
|
int latestSequenceNumber) {
|
|
|
+ if(isFencedState()) {
|
|
|
+ LOG.info("State store is in Fenced state. Can't store RM Delegation Token.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
storeRMDelegationTokenAndSequenceNumberState(rmDTIdentifier, renewDate,
|
|
|
latestSequenceNumber);
|
|
@@ -516,6 +538,10 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
*/
|
|
|
public synchronized void removeRMDelegationToken(
|
|
|
RMDelegationTokenIdentifier rmDTIdentifier, int sequenceNumber) {
|
|
|
+ if(isFencedState()) {
|
|
|
+ LOG.info("State store is in Fenced state. Can't remove RM Delegation Token.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
removeRMDelegationTokenState(rmDTIdentifier);
|
|
|
} catch (Exception e) {
|
|
@@ -537,6 +563,10 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
public synchronized void updateRMDelegationTokenAndSequenceNumber(
|
|
|
RMDelegationTokenIdentifier rmDTIdentifier, Long renewDate,
|
|
|
int latestSequenceNumber) {
|
|
|
+ if(isFencedState()) {
|
|
|
+ LOG.info("State store is in Fenced state. Can't update RM Delegation Token.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
updateRMDelegationTokenAndSequenceNumberInternal(rmDTIdentifier, renewDate,
|
|
|
latestSequenceNumber);
|
|
@@ -558,6 +588,11 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
* RMDTSecretManager call this to store the state of a master key
|
|
|
*/
|
|
|
public synchronized void storeRMDTMasterKey(DelegationKey delegationKey) {
|
|
|
+ if(isFencedState()) {
|
|
|
+ LOG.info("State store is in Fenced state. Can't store RM Delegation " +
|
|
|
+ "Token Master key.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
storeRMDTMasterKeyState(delegationKey);
|
|
|
} catch (Exception e) {
|
|
@@ -577,6 +612,11 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
* RMDTSecretManager call this to remove the state of a master key
|
|
|
*/
|
|
|
public synchronized void removeRMDTMasterKey(DelegationKey delegationKey) {
|
|
|
+ if(isFencedState()) {
|
|
|
+ LOG.info("State store is in Fenced state. Can't remove RM Delegation " +
|
|
|
+ "Token Master key.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
removeRMDTMasterKeyState(delegationKey);
|
|
|
} catch (Exception e) {
|
|
@@ -647,6 +687,11 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
}
|
|
|
return credentials;
|
|
|
}
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ synchronized boolean isFencedState() {
|
|
|
+ return (RMStateStoreState.FENCED == this.stateMachine.getCurrentState());
|
|
|
+ }
|
|
|
|
|
|
// Dispatcher related code
|
|
|
protected void handleStoreEvent(RMStateStoreEvent event) {
|
|
@@ -665,6 +710,7 @@ public abstract class RMStateStore extends AbstractService {
|
|
|
*/
|
|
|
protected void notifyStoreOperationFailed(Exception failureCause) {
|
|
|
if (failureCause instanceof StoreFencedException) {
|
|
|
+ updateFencedState();
|
|
|
Thread standByTransitionThread =
|
|
|
new Thread(new StandByTransitionThread());
|
|
|
standByTransitionThread.setName("StandByTransitionThread Handler");
|