Search in sources :

Example 6 with UploadTask

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

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.StateChangeUploadScheduler.UploadTask) SequenceNumberRange(org.apache.flink.runtime.state.changelog.SequenceNumberRange) SequenceNumber(org.apache.flink.runtime.state.changelog.SequenceNumber)

Example 7 with UploadTask

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

the class BatchingStateChangeUploadSchedulerTest method testUploadTimeout.

@Test
public void testUploadTimeout() throws Exception {
    AtomicReference<List<SequenceNumber>> failed = new AtomicReference<>();
    UploadTask upload = new UploadTask(getChanges(4), unused -> {
    }, (sqn, error) -> failed.set(sqn));
    ManuallyTriggeredScheduledExecutorService executorService = new ManuallyTriggeredScheduledExecutorService();
    try (BatchingStateChangeUploadScheduler store = scheduler(1, executorService, new BlockingUploader(), 1)) {
        store.upload(upload);
        Deadline deadline = Deadline.fromNow(Duration.ofMinutes(5));
        while (!upload.finished.get() && deadline.hasTimeLeft()) {
            executorService.triggerScheduledTasks();
            executorService.triggerAll();
            Thread.sleep(10);
        }
    }
    assertTrue(upload.finished.get());
    assertEquals(upload.changeSets.stream().map(StateChangeSet::getSequenceNumber).collect(Collectors.toSet()), new HashSet<>(failed.get()));
}
Also used : UploadTask(org.apache.flink.changelog.fs.StateChangeUploadScheduler.UploadTask) ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) Deadline(org.apache.flink.api.common.time.Deadline) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

UploadTask (org.apache.flink.changelog.fs.StateChangeUploadScheduler.UploadTask)7 ArrayList (java.util.ArrayList)3 Collections.emptyList (java.util.Collections.emptyList)3 Collections.singletonList (java.util.Collections.singletonList)3 List (java.util.List)3 Map (java.util.Map)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Deadline (org.apache.flink.api.common.time.Deadline)3 ManuallyTriggeredScheduledExecutorService (org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 FSDataOutputStream (org.apache.flink.core.fs.FSDataOutputStream)2 SequenceNumber (org.apache.flink.runtime.state.changelog.SequenceNumber)2 FileStateHandle (org.apache.flink.runtime.state.filesystem.FileStateHandle)2 BufferedOutputStream (java.io.BufferedOutputStream)1 OutputStream (java.io.OutputStream)1