Search in sources :

Example 1 with UploadTask

use of org.apache.flink.changelog.fs.StateChangeUploader.UploadTask in project flink by apache.

the class BatchingStateChangeUploaderTest method testRetry.

/**
 * Test integration with {@link RetryingExecutor}.
 */
@Test
public void testRetry() throws Exception {
    final int maxAttempts = 5;
    try (BatchingStateChangeUploader store = new BatchingStateChangeUploader(0, 0, MAX_BYTES_IN_FLIGHT, RetryPolicy.fixed(maxAttempts, 0, 0), new TestingStateChangeUploader() {

        final AtomicInteger currentAttempt = new AtomicInteger(0);

        @Override
        public void upload(UploadTask uploadTask) throws IOException {
            if (currentAttempt.getAndIncrement() < maxAttempts - 1) {
                throw new IOException();
            } else {
                uploadTask.complete(emptyList());
            }
        }
    }, new DirectScheduledExecutorService(), new RetryingExecutor(new DirectScheduledExecutorService(), createUnregisteredChangelogStorageMetricGroup().getAttemptsPerUpload()), createUnregisteredChangelogStorageMetricGroup())) {
        CompletableFuture<List<UploadResult>> completionFuture = new CompletableFuture<>();
        store.upload(new UploadTask(getChanges(4), completionFuture::complete, (unused, throwable) -> completionFuture.completeExceptionally(throwable)));
        completionFuture.get();
    }
}
Also used : BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) Arrays(java.util.Arrays) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ExceptionUtils.rethrow(org.apache.flink.util.ExceptionUtils.rethrow) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ExceptionUtils.findThrowable(org.apache.flink.util.ExceptionUtils.findThrowable) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assert.fail(org.junit.Assert.fail) UnregisteredChangelogStorageMetricGroup.createUnregisteredChangelogStorageMetricGroup(org.apache.flink.changelog.fs.UnregisteredChangelogStorageMetricGroup.createUnregisteredChangelogStorageMetricGroup) StateChange(org.apache.flink.runtime.state.changelog.StateChange) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) UploadTask(org.apache.flink.changelog.fs.StateChangeUploader.UploadTask) UUID(java.util.UUID) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Collectors(java.util.stream.Collectors) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) SequenceNumber(org.apache.flink.runtime.state.changelog.SequenceNumber) Assert.assertEquals(org.junit.Assert.assertEquals) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) IOException(java.io.IOException) UploadTask(org.apache.flink.changelog.fs.StateChangeUploader.UploadTask) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Test(org.junit.Test)

Example 2 with UploadTask

use of org.apache.flink.changelog.fs.StateChangeUploader.UploadTask in project flink by apache.

the class FsStateChangelogWriter method persistInternal.

private CompletableFuture<ChangelogStateHandleStreamImpl> persistInternal(SequenceNumber from) throws IOException {
    synchronized (lock) {
        ensureCanPersist(from);
        rollover();
        Map<SequenceNumber, StateChangeSet> toUpload = drainTailMap(notUploaded, from);
        NavigableMap<SequenceNumber, UploadResult> readyToReturn = uploaded.tailMap(from, true);
        LOG.debug("collected readyToReturn: {}, toUpload: {}", readyToReturn, toUpload);
        SequenceNumberRange range = SequenceNumberRange.generic(from, activeSequenceNumber);
        if (range.size() == readyToReturn.size()) {
            checkState(toUpload.isEmpty());
            return completedFuture(buildHandle(keyGroupRange, readyToReturn, 0L));
        } else {
            CompletableFuture<ChangelogStateHandleStreamImpl> future = new CompletableFuture<>();
            uploadCompletionListeners.add(new UploadCompletionListener(keyGroupRange, range, readyToReturn, future));
            if (!toUpload.isEmpty()) {
                uploader.upload(new UploadTask(toUpload.values(), this::handleUploadSuccess, this::handleUploadFailure));
            }
            return future;
        }
    }
}
Also used : ChangelogStateHandleStreamImpl(org.apache.flink.runtime.state.changelog.ChangelogStateHandleStreamImpl) CompletableFuture(java.util.concurrent.CompletableFuture) UploadTask(org.apache.flink.changelog.fs.StateChangeUploader.UploadTask) SequenceNumberRange(org.apache.flink.runtime.state.changelog.SequenceNumberRange) SequenceNumber(org.apache.flink.runtime.state.changelog.SequenceNumber)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)2 UploadTask (org.apache.flink.changelog.fs.StateChangeUploader.UploadTask)2 SequenceNumber (org.apache.flink.runtime.state.changelog.SequenceNumber)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Random (java.util.Random)1 UUID (java.util.UUID)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 UnregisteredChangelogStorageMetricGroup.createUnregisteredChangelogStorageMetricGroup (org.apache.flink.changelog.fs.UnregisteredChangelogStorageMetricGroup.createUnregisteredChangelogStorageMetricGroup)1 ManuallyTriggeredScheduledExecutorService (org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService)1