Search in sources :

Example 1 with RecoveredLogDeleterState

use of org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService.RecoveredLogDeleterState in project hadoop by apache.

the class NonAggregatingLogHandler method recover.

private void recover() throws IOException {
    if (stateStore.canRecover()) {
        RecoveredLogDeleterState state = stateStore.loadLogDeleterState();
        long now = System.currentTimeMillis();
        for (Map.Entry<ApplicationId, LogDeleterProto> entry : state.getLogDeleterMap().entrySet()) {
            ApplicationId appId = entry.getKey();
            LogDeleterProto proto = entry.getValue();
            long deleteDelayMsec = proto.getDeletionTime() - now;
            if (LOG.isDebugEnabled()) {
                LOG.debug("Scheduling deletion of " + appId + " logs in " + deleteDelayMsec + " msec");
            }
            LogDeleterRunnable logDeleter = new LogDeleterRunnable(proto.getUser(), appId);
            try {
                sched.schedule(logDeleter, deleteDelayMsec, TimeUnit.MILLISECONDS);
            } catch (RejectedExecutionException e) {
                // Handling this event in local thread before starting threads
                // or after calling sched.shutdownNow().
                logDeleter.run();
            }
        }
    }
}
Also used : RecoveredLogDeleterState(org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService.RecoveredLogDeleterState) LogDeleterProto(org.apache.hadoop.yarn.proto.YarnServerNodemanagerRecoveryProtos.LogDeleterProto) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 2 with RecoveredLogDeleterState

use of org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService.RecoveredLogDeleterState in project hadoop by apache.

the class TestNMLeveldbStateStoreService method testLogDeleterStorage.

@Test
public void testLogDeleterStorage() throws IOException {
    // test empty when no state
    RecoveredLogDeleterState state = stateStore.loadLogDeleterState();
    assertTrue(state.getLogDeleterMap().isEmpty());
    // store log deleter state
    final ApplicationId appId1 = ApplicationId.newInstance(1, 1);
    LogDeleterProto proto1 = LogDeleterProto.newBuilder().setUser("user1").setDeletionTime(1234).build();
    stateStore.storeLogDeleter(appId1, proto1);
    // restart state store and verify recovered
    restartStateStore();
    state = stateStore.loadLogDeleterState();
    assertEquals(1, state.getLogDeleterMap().size());
    assertEquals(proto1, state.getLogDeleterMap().get(appId1));
    // store another log deleter
    final ApplicationId appId2 = ApplicationId.newInstance(2, 2);
    LogDeleterProto proto2 = LogDeleterProto.newBuilder().setUser("user2").setDeletionTime(5678).build();
    stateStore.storeLogDeleter(appId2, proto2);
    // restart state store and verify recovered
    restartStateStore();
    state = stateStore.loadLogDeleterState();
    assertEquals(2, state.getLogDeleterMap().size());
    assertEquals(proto1, state.getLogDeleterMap().get(appId1));
    assertEquals(proto2, state.getLogDeleterMap().get(appId2));
    // remove a deleter and verify removed after restart and recovery
    stateStore.removeLogDeleter(appId1);
    restartStateStore();
    state = stateStore.loadLogDeleterState();
    assertEquals(1, state.getLogDeleterMap().size());
    assertEquals(proto2, state.getLogDeleterMap().get(appId2));
    // remove last deleter and verify empty after restart and recovery
    stateStore.removeLogDeleter(appId2);
    restartStateStore();
    state = stateStore.loadLogDeleterState();
    assertTrue(state.getLogDeleterMap().isEmpty());
}
Also used : RecoveredLogDeleterState(org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService.RecoveredLogDeleterState) LogDeleterProto(org.apache.hadoop.yarn.proto.YarnServerNodemanagerRecoveryProtos.LogDeleterProto) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Aggregations

ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 LogDeleterProto (org.apache.hadoop.yarn.proto.YarnServerNodemanagerRecoveryProtos.LogDeleterProto)2 RecoveredLogDeleterState (org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService.RecoveredLogDeleterState)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Test (org.junit.Test)1