Search in sources :

Example 1 with Nonnegative

use of javax.annotation.Nonnegative in project flink by apache.

the class LocalStateForwardingTest method testReportingFromTaskStateManagerToResponderAndTaskLocalStateStore.

/**
 * This tests that state that was reported to the {@link
 * org.apache.flink.runtime.state.TaskStateManager} is also reported to {@link
 * org.apache.flink.runtime.taskmanager.CheckpointResponder} and {@link
 * TaskLocalStateStoreImpl}.
 */
@Test
public void testReportingFromTaskStateManagerToResponderAndTaskLocalStateStore() throws Exception {
    final JobID jobID = new JobID();
    final AllocationID allocationID = new AllocationID();
    final ExecutionAttemptID executionAttemptID = new ExecutionAttemptID();
    final CheckpointMetaData checkpointMetaData = new CheckpointMetaData(42L, 4711L);
    final CheckpointMetrics checkpointMetrics = new CheckpointMetrics();
    final int subtaskIdx = 42;
    JobVertexID jobVertexID = new JobVertexID();
    TaskStateSnapshot jmSnapshot = new TaskStateSnapshot();
    TaskStateSnapshot tmSnapshot = new TaskStateSnapshot();
    final AtomicBoolean jmReported = new AtomicBoolean(false);
    final AtomicBoolean tmReported = new AtomicBoolean(false);
    TestCheckpointResponder checkpointResponder = new TestCheckpointResponder() {

        @Override
        public void acknowledgeCheckpoint(JobID lJobID, ExecutionAttemptID lExecutionAttemptID, long lCheckpointId, CheckpointMetrics lCheckpointMetrics, TaskStateSnapshot lSubtaskState) {
            Assert.assertEquals(jobID, lJobID);
            Assert.assertEquals(executionAttemptID, lExecutionAttemptID);
            Assert.assertEquals(checkpointMetaData.getCheckpointId(), lCheckpointId);
            Assert.assertEquals(checkpointMetrics, lCheckpointMetrics);
            jmReported.set(true);
        }
    };
    Executor executor = Executors.directExecutor();
    LocalRecoveryDirectoryProviderImpl directoryProvider = new LocalRecoveryDirectoryProviderImpl(temporaryFolder.newFolder(), jobID, jobVertexID, subtaskIdx);
    LocalRecoveryConfig localRecoveryConfig = new LocalRecoveryConfig(directoryProvider);
    TaskLocalStateStore taskLocalStateStore = new TaskLocalStateStoreImpl(jobID, allocationID, jobVertexID, subtaskIdx, localRecoveryConfig, executor) {

        @Override
        public void storeLocalState(@Nonnegative long checkpointId, @Nullable TaskStateSnapshot localState) {
            Assert.assertEquals(tmSnapshot, localState);
            tmReported.set(true);
        }
    };
    StateChangelogStorage<?> stateChangelogStorage = new InMemoryStateChangelogStorage();
    TaskStateManagerImpl taskStateManager = new TaskStateManagerImpl(jobID, executionAttemptID, taskLocalStateStore, stateChangelogStorage, null, checkpointResponder);
    taskStateManager.reportTaskStateSnapshots(checkpointMetaData, checkpointMetrics, jmSnapshot, tmSnapshot);
    Assert.assertTrue("Reporting for JM state was not called.", jmReported.get());
    Assert.assertTrue("Reporting for TM state was not called.", tmReported.get());
}
Also used : TaskStateManagerImpl(org.apache.flink.runtime.state.TaskStateManagerImpl) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) TaskLocalStateStore(org.apache.flink.runtime.state.TaskLocalStateStore) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) CheckpointMetrics(org.apache.flink.runtime.checkpoint.CheckpointMetrics) LocalRecoveryDirectoryProviderImpl(org.apache.flink.runtime.state.LocalRecoveryDirectoryProviderImpl) LocalRecoveryConfig(org.apache.flink.runtime.state.LocalRecoveryConfig) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) Executor(java.util.concurrent.Executor) InMemoryStateChangelogStorage(org.apache.flink.runtime.state.changelog.inmemory.InMemoryStateChangelogStorage) TaskLocalStateStoreImpl(org.apache.flink.runtime.state.TaskLocalStateStoreImpl) Nonnegative(javax.annotation.Nonnegative) TestCheckpointResponder(org.apache.flink.runtime.taskmanager.TestCheckpointResponder) JobID(org.apache.flink.api.common.JobID) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 2 with Nonnegative

use of javax.annotation.Nonnegative in project jackrabbit-oak by apache.

the class NodeDocumentCache method invalidateOutdated.

/**
 * Invalidate document with given keys iff their modification stamps are
 * different as passed in the map.
 *
 * @param modStamps map where key is the document id and the value is the
 *                  modification stamps.
 * @return number of invalidated entries
 */
@Nonnegative
public int invalidateOutdated(@Nonnull Map<String, ModificationStamp> modStamps) {
    int invalidatedCount = 0;
    for (Entry<String, ModificationStamp> e : modStamps.entrySet()) {
        String id = e.getKey();
        ModificationStamp stamp = e.getValue();
        NodeDocument doc = getIfPresent(id);
        if (doc == null) {
            continue;
        }
        if (!Objects.equal(stamp.modCount, doc.getModCount()) || !Objects.equal(stamp.modified, doc.getModified())) {
            invalidate(id);
            invalidatedCount++;
        }
    }
    return invalidatedCount;
}
Also used : NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Nonnegative(javax.annotation.Nonnegative)

Aggregations

Nonnegative (javax.annotation.Nonnegative)2 Executor (java.util.concurrent.Executor)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Nullable (javax.annotation.Nullable)1 JobID (org.apache.flink.api.common.JobID)1 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)1 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)1 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)1 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)1 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)1 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)1 LocalRecoveryConfig (org.apache.flink.runtime.state.LocalRecoveryConfig)1 LocalRecoveryDirectoryProviderImpl (org.apache.flink.runtime.state.LocalRecoveryDirectoryProviderImpl)1 TaskLocalStateStore (org.apache.flink.runtime.state.TaskLocalStateStore)1 TaskLocalStateStoreImpl (org.apache.flink.runtime.state.TaskLocalStateStoreImpl)1 TaskStateManagerImpl (org.apache.flink.runtime.state.TaskStateManagerImpl)1 InMemoryStateChangelogStorage (org.apache.flink.runtime.state.changelog.inmemory.InMemoryStateChangelogStorage)1 TestCheckpointResponder (org.apache.flink.runtime.taskmanager.TestCheckpointResponder)1 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)1 Test (org.junit.Test)1