Search in sources :

Example 1 with EventProcessorGroup

use of io.pravega.controller.eventProcessor.EventProcessorGroup in project pravega by pravega.

the class ControllerEventProcessors method handleOrphanedReaders.

private CompletableFuture<Void> handleOrphanedReaders(final EventProcessorGroup<? extends ControllerEvent> group, final Supplier<Set<String>> processes) {
    return withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> {
        try {
            return group.getProcesses();
        } catch (CheckpointStoreException e) {
            if (e.getType().equals(CheckpointStoreException.Type.NoNode)) {
                return Collections.<String>emptySet();
            }
            throw new CompletionException(e);
        }
    }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor).thenComposeAsync(groupProcesses -> withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> {
        try {
            return new ImmutablePair<>(processes.get(), groupProcesses);
        } catch (Exception e) {
            log.error(String.format("Error fetching current processes%s", group.toString()), e);
            throw new CompletionException(e);
        }
    }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor)).thenComposeAsync(pair -> {
        Set<String> activeProcesses = pair.getLeft();
        Set<String> registeredProcesses = pair.getRight();
        if (registeredProcesses == null || registeredProcesses.isEmpty()) {
            return CompletableFuture.completedFuture(null);
        }
        if (activeProcesses != null) {
            registeredProcesses.removeAll(activeProcesses);
        }
        List<CompletableFuture<Void>> futureList = new ArrayList<>();
        for (String process : registeredProcesses) {
            futureList.add(withRetriesAsync(() -> CompletableFuture.runAsync(() -> {
                try {
                    group.notifyProcessFailure(process);
                } catch (CheckpointStoreException e) {
                    log.error(String.format("Error notifying failure of process=%s in event processor group %s", process, group.toString()), e);
                    throw new CompletionException(e);
                }
            }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor));
        }
        return Futures.allOf(futureList);
    });
}
Also used : CommitEvent(io.pravega.shared.controller.event.CommitEvent) Retry(io.pravega.common.util.Retry) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) CheckpointStore(io.pravega.controller.store.checkpoint.CheckpointStore) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) CheckpointStoreException(io.pravega.controller.store.checkpoint.CheckpointStoreException) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) AbortRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.AbortRequestHandler) AutoScaleTask(io.pravega.controller.server.eventProcessor.requesthandlers.AutoScaleTask) RETRYABLE_PREDICATE(io.pravega.controller.util.RetryHelper.RETRYABLE_PREDICATE) ExceptionHandler(io.pravega.controller.eventProcessor.ExceptionHandler) RetryHelper.withRetriesAsync(io.pravega.controller.util.RetryHelper.withRetriesAsync) EventProcessorConfig(io.pravega.controller.eventProcessor.EventProcessorConfig) SealStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) ScaleOperationTask(io.pravega.controller.server.eventProcessor.requesthandlers.ScaleOperationTask) ControllerEvent(io.pravega.shared.controller.event.ControllerEvent) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ConcurrentEventProcessor(io.pravega.controller.eventProcessor.impl.ConcurrentEventProcessor) EventProcessorSystemImpl(io.pravega.controller.eventProcessor.impl.EventProcessorSystemImpl) Config(io.pravega.controller.util.Config) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) ClientFactory(io.pravega.client.ClientFactory) Controller(io.pravega.client.stream.impl.Controller) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) TruncateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.TruncateStreamTask) SegmentHelper(io.pravega.controller.server.SegmentHelper) EventProcessorGroupConfigImpl(io.pravega.controller.eventProcessor.impl.EventProcessorGroupConfigImpl) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) AbortEvent(io.pravega.shared.controller.event.AbortEvent) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) Serializer(io.pravega.client.stream.Serializer) LoggerHelpers(io.pravega.common.LoggerHelpers) FailoverSweeper(io.pravega.controller.fault.FailoverSweeper) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) EventProcessorSystem(io.pravega.controller.eventProcessor.EventProcessorSystem) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) DeleteStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteStreamTask) EventProcessorGroup(io.pravega.controller.eventProcessor.EventProcessorGroup) StreamRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.StreamRequestHandler) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) CheckpointStoreException(io.pravega.controller.store.checkpoint.CheckpointStoreException) CheckpointStoreException(io.pravega.controller.store.checkpoint.CheckpointStoreException) CompletionException(java.util.concurrent.CompletionException)

Example 2 with EventProcessorGroup

use of io.pravega.controller.eventProcessor.EventProcessorGroup in project pravega by pravega.

the class ControllerEventProcessorsTest method testHandleOrphaned.

@Test(timeout = 10000)
public void testHandleOrphaned() {
    Controller localController = mock(Controller.class);
    CheckpointStore checkpointStore = mock(CheckpointStore.class);
    StreamMetadataStore streamStore = mock(StreamMetadataStore.class);
    HostControllerStore hostStore = mock(HostControllerStore.class);
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    StreamMetadataTasks streamMetadataTasks = mock(StreamMetadataTasks.class);
    StreamTransactionMetadataTasks streamTransactionMetadataTasks = mock(StreamTransactionMetadataTasks.class);
    executor = Executors.newSingleThreadScheduledExecutor();
    ControllerEventProcessorConfig config = ControllerEventProcessorConfigImpl.withDefault();
    EventProcessorSystem system = mock(EventProcessorSystem.class);
    EventProcessorGroup<ControllerEvent> processor = new EventProcessorGroup<ControllerEvent>() {

        @Override
        public void notifyProcessFailure(String process) throws CheckpointStoreException {
        }

        @Override
        public EventStreamWriter<ControllerEvent> getWriter() {
            return null;
        }

        @Override
        public Set<String> getProcesses() throws CheckpointStoreException {
            return Sets.newHashSet("host1", "host2");
        }

        @Override
        public Service startAsync() {
            return null;
        }

        @Override
        public boolean isRunning() {
            return false;
        }

        @Override
        public State state() {
            return null;
        }

        @Override
        public Service stopAsync() {
            return null;
        }

        @Override
        public void awaitRunning() {
        }

        @Override
        public void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException {
        }

        @Override
        public void awaitTerminated() {
        }

        @Override
        public void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException {
        }

        @Override
        public Throwable failureCause() {
            return null;
        }

        @Override
        public void addListener(Listener listener, Executor executor) {
        }

        @Override
        public void close() throws Exception {
        }
    };
    try {
        when(system.createEventProcessorGroup(any(), any())).thenReturn(processor);
    } catch (CheckpointStoreException e) {
        e.printStackTrace();
    }
    ControllerEventProcessors processors = new ControllerEventProcessors("host1", config, localController, checkpointStore, streamStore, hostStore, SegmentHelperMock.getSegmentHelperMock(), connectionFactory, streamMetadataTasks, system, executor);
    processors.startAsync();
    processors.awaitRunning();
    assertTrue(Futures.await(processors.sweepFailedProcesses(() -> Sets.newHashSet("host1"))));
    assertTrue(Futures.await(processors.handleFailedProcess("host1")));
    processors.shutDown();
}
Also used : EventProcessorSystem(io.pravega.controller.eventProcessor.EventProcessorSystem) EventProcessorGroup(io.pravega.controller.eventProcessor.EventProcessorGroup) CheckpointStore(io.pravega.controller.store.checkpoint.CheckpointStore) Controller(io.pravega.client.stream.impl.Controller) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) ControllerEvent(io.pravega.shared.controller.event.ControllerEvent) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) Executor(java.util.concurrent.Executor) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) TimeUnit(java.util.concurrent.TimeUnit) CheckpointStoreException(io.pravega.controller.store.checkpoint.CheckpointStoreException) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Test(org.junit.Test)

Aggregations

ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)2 Controller (io.pravega.client.stream.impl.Controller)2 EventProcessorGroup (io.pravega.controller.eventProcessor.EventProcessorGroup)2 EventProcessorSystem (io.pravega.controller.eventProcessor.EventProcessorSystem)2 CheckpointStore (io.pravega.controller.store.checkpoint.CheckpointStore)2 CheckpointStoreException (io.pravega.controller.store.checkpoint.CheckpointStoreException)2 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)2 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)2 StreamMetadataTasks (io.pravega.controller.task.Stream.StreamMetadataTasks)2 StreamTransactionMetadataTasks (io.pravega.controller.task.Stream.StreamTransactionMetadataTasks)2 ControllerEvent (io.pravega.shared.controller.event.ControllerEvent)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AbstractIdleService (com.google.common.util.concurrent.AbstractIdleService)1 ClientFactory (io.pravega.client.ClientFactory)1 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)1 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)1 Serializer (io.pravega.client.stream.Serializer)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)1 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)1