Search in sources :

Example 1 with AlreadyRunningException

use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project pulsar by apache.

the class PersistentTopic method triggerOffload.

public synchronized void triggerOffload(MessageIdImpl messageId) throws AlreadyRunningException {
    if (currentOffload.isDone()) {
        CompletableFuture<MessageIdImpl> promise = currentOffload = new CompletableFuture<>();
        log.info("[{}] Starting offload operation at messageId {}", topic, messageId);
        getManagedLedger().asyncOffloadPrefix(PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId()), new OffloadCallback() {

            @Override
            public void offloadComplete(Position pos, Object ctx) {
                PositionImpl impl = (PositionImpl) pos;
                log.info("[{}] Completed successfully offload operation at messageId {}", topic, messageId);
                promise.complete(new MessageIdImpl(impl.getLedgerId(), impl.getEntryId(), -1));
            }

            @Override
            public void offloadFailed(ManagedLedgerException exception, Object ctx) {
                log.warn("[{}] Failed offload operation at messageId {}", topic, messageId, exception);
                promise.completeExceptionally(exception);
            }
        }, null);
    } else {
        throw new AlreadyRunningException("Offload already in progress");
    }
}
Also used : AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) OffloadCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OffloadCallback) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) Position(org.apache.bookkeeper.mledger.Position) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) BatchMessageIdImpl(org.apache.pulsar.client.impl.BatchMessageIdImpl) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl)

Example 2 with AlreadyRunningException

use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project pulsar by yahoo.

the class PersistentTopicsBase method internalTriggerCompactionNonPartitionedTopic.

protected void internalTriggerCompactionNonPartitionedTopic(AsyncResponse asyncResponse, boolean authoritative) {
    validateTopicOwnershipAsync(topicName, authoritative).thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.COMPACT)).thenCompose(__ -> getTopicReferenceAsync(topicName)).thenAccept(topic -> {
        try {
            ((PersistentTopic) topic).triggerCompaction();
            asyncResponse.resume(Response.noContent().build());
        } catch (AlreadyRunningException e) {
            resumeAsyncResponseExceptionally(asyncResponse, new RestException(Status.CONFLICT, e.getMessage()));
            return;
        } catch (Exception e) {
            log.error("[{}] Failed to trigger compaction on topic {}", clientAppId(), topicName, e);
            resumeAsyncResponseExceptionally(asyncResponse, new RestException(e));
            return;
        }
    }).exceptionally(ex -> {
        // If the exception is not redirect exception we need to log it.
        if (!isRedirectException(ex)) {
            log.error("[{}] Failed to trigger compaction for {}", clientAppId(), topicName, ex);
        }
        resumeAsyncResponseExceptionally(asyncResponse, ex);
        return null;
    });
}
Also used : Version(com.github.zafarkhaja.semver.Version) SubscriptionStats(org.apache.pulsar.common.policies.data.SubscriptionStats) ManagedLedgerOfflineBacklog(org.apache.bookkeeper.mledger.impl.ManagedLedgerOfflineBacklog) Topic(org.apache.pulsar.broker.service.Topic) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) LedgerOffloader(org.apache.bookkeeper.mledger.LedgerOffloader) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) StringUtils(org.apache.commons.lang3.StringUtils) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) TopicOperation(org.apache.pulsar.common.policies.data.TopicOperation) PolicyOperation(org.apache.pulsar.common.policies.data.PolicyOperation) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceOperation(org.apache.pulsar.common.policies.data.NamespaceOperation) DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl) PersistentOfflineTopicStats(org.apache.pulsar.common.policies.data.PersistentOfflineTopicStats) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) SystemTopicNames.isTransactionCoordinatorAssign(org.apache.pulsar.common.naming.SystemTopicNames.isTransactionCoordinatorAssign) AsyncResponse(javax.ws.rs.container.AsyncResponse) Set(java.util.Set) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) OffloadProcessStatus(org.apache.pulsar.client.admin.OffloadProcessStatus) MessageMetadata(org.apache.pulsar.common.api.proto.MessageMetadata) WebApplicationException(javax.ws.rs.WebApplicationException) PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) Subscription(org.apache.pulsar.broker.service.Subscription) TopicStats(org.apache.pulsar.common.policies.data.TopicStats) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) ArrayList(java.util.ArrayList) Commands(org.apache.pulsar.common.protocol.Commands) SubType(org.apache.pulsar.common.api.proto.CommandSubscribe.SubType) Lists(com.google.common.collect.Lists) DateFormatter(org.apache.pulsar.common.util.DateFormatter) BiConsumer(java.util.function.BiConsumer) NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) DispatchRate(org.apache.pulsar.common.policies.data.DispatchRate) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo) IOException(java.io.IOException) PulsarService(org.apache.pulsar.broker.PulsarService) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) SubscriptionInvalidCursorPosition(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionInvalidCursorPosition) AuthorizationService(org.apache.pulsar.broker.authorization.AuthorizationService) AdminResource(org.apache.pulsar.broker.admin.AdminResource) LoggerFactory(org.slf4j.LoggerFactory) KeyValue(org.apache.pulsar.common.api.proto.KeyValue) TopicStatsImpl(org.apache.pulsar.common.policies.data.stats.TopicStatsImpl) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) SubscriptionPolicies(org.apache.pulsar.common.policies.data.SubscriptionPolicies) MessageImpl(org.apache.pulsar.client.impl.MessageImpl) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) AuthAction(org.apache.pulsar.common.policies.data.AuthAction) AuthPolicies(org.apache.pulsar.common.policies.data.AuthPolicies) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) BrokerEntryMetadata(org.apache.pulsar.common.api.proto.BrokerEntryMetadata) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) PartitionedTopicInternalStats(org.apache.pulsar.common.policies.data.PartitionedTopicInternalStats) SchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy) OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletionException(java.util.concurrent.CompletionException) StreamingOutput(javax.ws.rs.core.StreamingOutput) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AuthenticationDataSource(org.apache.pulsar.broker.authentication.AuthenticationDataSource) PulsarByteBufAllocator(org.apache.pulsar.common.allocator.PulsarByteBufAllocator) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl) BacklogQuotaImpl(org.apache.pulsar.common.policies.data.impl.BacklogQuotaImpl) Base64(java.util.Base64) List(java.util.List) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Response(javax.ws.rs.core.Response) EncryptionKeys(org.apache.pulsar.common.api.proto.EncryptionKeys) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) PolicyName(org.apache.pulsar.common.policies.data.PolicyName) PartitionedTopicStatsImpl(org.apache.pulsar.common.policies.data.stats.PartitionedTopicStatsImpl) Optional(java.util.Optional) IntStream(java.util.stream.IntStream) CompressionCodec(org.apache.pulsar.common.compression.CompressionCodec) TopicName(org.apache.pulsar.common.naming.TopicName) Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerInfoCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ManagedLedgerInfoCallback) BacklogQuota(org.apache.pulsar.common.policies.data.BacklogQuota) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuf(io.netty.buffer.ByteBuf) LongRunningProcessStatus(org.apache.pulsar.client.admin.LongRunningProcessStatus) CompressionCodecProvider(org.apache.pulsar.common.compression.CompressionCodecProvider) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) Status(javax.ws.rs.core.Response.Status) PartitionedManagedLedgerInfo(org.apache.pulsar.common.naming.PartitionedManagedLedgerInfo) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) PersistentReplicator(org.apache.pulsar.broker.service.persistent.PersistentReplicator) Logger(org.slf4j.Logger) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TopicPolicies(org.apache.pulsar.common.policies.data.TopicPolicies) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) Policies(org.apache.pulsar.common.policies.data.Policies) TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) MessageId(org.apache.pulsar.client.api.MessageId) SystemTopicNames.isTransactionInternalName(org.apache.pulsar.common.naming.SystemTopicNames.isTransactionInternalName) TransactionCoordinatorID(org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) RestException(org.apache.pulsar.broker.web.RestException) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) RestException(org.apache.pulsar.broker.web.RestException) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) CompletionException(java.util.concurrent.CompletionException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException)

Example 3 with AlreadyRunningException

use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project incubator-pulsar by apache.

the class PersistentTopicsBase method internalTriggerCompactionNonPartitionedTopic.

protected void internalTriggerCompactionNonPartitionedTopic(AsyncResponse asyncResponse, boolean authoritative) {
    validateTopicOwnershipAsync(topicName, authoritative).thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.COMPACT)).thenCompose(__ -> getTopicReferenceAsync(topicName)).thenAccept(topic -> {
        try {
            ((PersistentTopic) topic).triggerCompaction();
            asyncResponse.resume(Response.noContent().build());
        } catch (AlreadyRunningException e) {
            resumeAsyncResponseExceptionally(asyncResponse, new RestException(Status.CONFLICT, e.getMessage()));
            return;
        } catch (Exception e) {
            log.error("[{}] Failed to trigger compaction on topic {}", clientAppId(), topicName, e);
            resumeAsyncResponseExceptionally(asyncResponse, new RestException(e));
            return;
        }
    }).exceptionally(ex -> {
        // If the exception is not redirect exception we need to log it.
        if (!isRedirectException(ex)) {
            log.error("[{}] Failed to trigger compaction for {}", clientAppId(), topicName, ex);
        }
        resumeAsyncResponseExceptionally(asyncResponse, ex);
        return null;
    });
}
Also used : Version(com.github.zafarkhaja.semver.Version) SubscriptionStats(org.apache.pulsar.common.policies.data.SubscriptionStats) ManagedLedgerOfflineBacklog(org.apache.bookkeeper.mledger.impl.ManagedLedgerOfflineBacklog) Topic(org.apache.pulsar.broker.service.Topic) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) LedgerOffloader(org.apache.bookkeeper.mledger.LedgerOffloader) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) StringUtils(org.apache.commons.lang3.StringUtils) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) TopicOperation(org.apache.pulsar.common.policies.data.TopicOperation) PolicyOperation(org.apache.pulsar.common.policies.data.PolicyOperation) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceOperation(org.apache.pulsar.common.policies.data.NamespaceOperation) DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl) PersistentOfflineTopicStats(org.apache.pulsar.common.policies.data.PersistentOfflineTopicStats) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) SystemTopicNames.isTransactionCoordinatorAssign(org.apache.pulsar.common.naming.SystemTopicNames.isTransactionCoordinatorAssign) AsyncResponse(javax.ws.rs.container.AsyncResponse) Set(java.util.Set) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) OffloadProcessStatus(org.apache.pulsar.client.admin.OffloadProcessStatus) MessageMetadata(org.apache.pulsar.common.api.proto.MessageMetadata) WebApplicationException(javax.ws.rs.WebApplicationException) PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) Subscription(org.apache.pulsar.broker.service.Subscription) TopicStats(org.apache.pulsar.common.policies.data.TopicStats) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) ArrayList(java.util.ArrayList) Commands(org.apache.pulsar.common.protocol.Commands) SubType(org.apache.pulsar.common.api.proto.CommandSubscribe.SubType) Lists(com.google.common.collect.Lists) DateFormatter(org.apache.pulsar.common.util.DateFormatter) BiConsumer(java.util.function.BiConsumer) NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) DispatchRate(org.apache.pulsar.common.policies.data.DispatchRate) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo) IOException(java.io.IOException) PulsarService(org.apache.pulsar.broker.PulsarService) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) SubscriptionInvalidCursorPosition(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionInvalidCursorPosition) AuthorizationService(org.apache.pulsar.broker.authorization.AuthorizationService) AdminResource(org.apache.pulsar.broker.admin.AdminResource) LoggerFactory(org.slf4j.LoggerFactory) KeyValue(org.apache.pulsar.common.api.proto.KeyValue) TopicStatsImpl(org.apache.pulsar.common.policies.data.stats.TopicStatsImpl) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) SubscriptionPolicies(org.apache.pulsar.common.policies.data.SubscriptionPolicies) MessageImpl(org.apache.pulsar.client.impl.MessageImpl) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) AuthAction(org.apache.pulsar.common.policies.data.AuthAction) AuthPolicies(org.apache.pulsar.common.policies.data.AuthPolicies) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) BrokerEntryMetadata(org.apache.pulsar.common.api.proto.BrokerEntryMetadata) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) PartitionedTopicInternalStats(org.apache.pulsar.common.policies.data.PartitionedTopicInternalStats) SchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy) OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletionException(java.util.concurrent.CompletionException) StreamingOutput(javax.ws.rs.core.StreamingOutput) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AuthenticationDataSource(org.apache.pulsar.broker.authentication.AuthenticationDataSource) PulsarByteBufAllocator(org.apache.pulsar.common.allocator.PulsarByteBufAllocator) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl) BacklogQuotaImpl(org.apache.pulsar.common.policies.data.impl.BacklogQuotaImpl) Base64(java.util.Base64) List(java.util.List) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Response(javax.ws.rs.core.Response) EncryptionKeys(org.apache.pulsar.common.api.proto.EncryptionKeys) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) PolicyName(org.apache.pulsar.common.policies.data.PolicyName) PartitionedTopicStatsImpl(org.apache.pulsar.common.policies.data.stats.PartitionedTopicStatsImpl) Optional(java.util.Optional) IntStream(java.util.stream.IntStream) CompressionCodec(org.apache.pulsar.common.compression.CompressionCodec) TopicName(org.apache.pulsar.common.naming.TopicName) Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerInfoCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ManagedLedgerInfoCallback) BacklogQuota(org.apache.pulsar.common.policies.data.BacklogQuota) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuf(io.netty.buffer.ByteBuf) LongRunningProcessStatus(org.apache.pulsar.client.admin.LongRunningProcessStatus) CompressionCodecProvider(org.apache.pulsar.common.compression.CompressionCodecProvider) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) Status(javax.ws.rs.core.Response.Status) PartitionedManagedLedgerInfo(org.apache.pulsar.common.naming.PartitionedManagedLedgerInfo) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) PersistentReplicator(org.apache.pulsar.broker.service.persistent.PersistentReplicator) Logger(org.slf4j.Logger) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TopicPolicies(org.apache.pulsar.common.policies.data.TopicPolicies) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) Policies(org.apache.pulsar.common.policies.data.Policies) TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) MessageId(org.apache.pulsar.client.api.MessageId) SystemTopicNames.isTransactionInternalName(org.apache.pulsar.common.naming.SystemTopicNames.isTransactionInternalName) TransactionCoordinatorID(org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) RestException(org.apache.pulsar.broker.web.RestException) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) RestException(org.apache.pulsar.broker.web.RestException) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) CompletionException(java.util.concurrent.CompletionException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException)

Example 4 with AlreadyRunningException

use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project incubator-pulsar by apache.

the class PersistentTopicsBase method internalTriggerOffload.

protected void internalTriggerOffload(AsyncResponse asyncResponse, boolean authoritative, MessageIdImpl messageId) {
    validateTopicOwnershipAsync(topicName, authoritative).thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.OFFLOAD)).thenCompose(__ -> getTopicReferenceAsync(topicName)).thenAccept(topic -> {
        try {
            ((PersistentTopic) topic).triggerOffload(messageId);
            asyncResponse.resume(Response.noContent().build());
        } catch (AlreadyRunningException e) {
            resumeAsyncResponseExceptionally(asyncResponse, new RestException(Status.CONFLICT, e.getMessage()));
            return;
        } catch (Exception e) {
            log.warn("Unexpected error triggering offload", e);
            resumeAsyncResponseExceptionally(asyncResponse, new RestException(e));
            return;
        }
    }).exceptionally(ex -> {
        // If the exception is not redirect exception we need to log it.
        if (!isRedirectException(ex)) {
            log.error("[{}] Failed to trigger offload for {}", clientAppId(), topicName, ex);
        }
        resumeAsyncResponseExceptionally(asyncResponse, ex);
        return null;
    });
}
Also used : Version(com.github.zafarkhaja.semver.Version) SubscriptionStats(org.apache.pulsar.common.policies.data.SubscriptionStats) ManagedLedgerOfflineBacklog(org.apache.bookkeeper.mledger.impl.ManagedLedgerOfflineBacklog) Topic(org.apache.pulsar.broker.service.Topic) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) LedgerOffloader(org.apache.bookkeeper.mledger.LedgerOffloader) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) StringUtils(org.apache.commons.lang3.StringUtils) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) TopicOperation(org.apache.pulsar.common.policies.data.TopicOperation) PolicyOperation(org.apache.pulsar.common.policies.data.PolicyOperation) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceOperation(org.apache.pulsar.common.policies.data.NamespaceOperation) DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl) PersistentOfflineTopicStats(org.apache.pulsar.common.policies.data.PersistentOfflineTopicStats) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) SystemTopicNames.isTransactionCoordinatorAssign(org.apache.pulsar.common.naming.SystemTopicNames.isTransactionCoordinatorAssign) AsyncResponse(javax.ws.rs.container.AsyncResponse) Set(java.util.Set) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) OffloadProcessStatus(org.apache.pulsar.client.admin.OffloadProcessStatus) MessageMetadata(org.apache.pulsar.common.api.proto.MessageMetadata) WebApplicationException(javax.ws.rs.WebApplicationException) PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) Subscription(org.apache.pulsar.broker.service.Subscription) TopicStats(org.apache.pulsar.common.policies.data.TopicStats) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) ArrayList(java.util.ArrayList) Commands(org.apache.pulsar.common.protocol.Commands) SubType(org.apache.pulsar.common.api.proto.CommandSubscribe.SubType) Lists(com.google.common.collect.Lists) DateFormatter(org.apache.pulsar.common.util.DateFormatter) BiConsumer(java.util.function.BiConsumer) NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) DispatchRate(org.apache.pulsar.common.policies.data.DispatchRate) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo) IOException(java.io.IOException) PulsarService(org.apache.pulsar.broker.PulsarService) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) SubscriptionInvalidCursorPosition(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionInvalidCursorPosition) AuthorizationService(org.apache.pulsar.broker.authorization.AuthorizationService) AdminResource(org.apache.pulsar.broker.admin.AdminResource) LoggerFactory(org.slf4j.LoggerFactory) KeyValue(org.apache.pulsar.common.api.proto.KeyValue) TopicStatsImpl(org.apache.pulsar.common.policies.data.stats.TopicStatsImpl) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) SubscriptionPolicies(org.apache.pulsar.common.policies.data.SubscriptionPolicies) MessageImpl(org.apache.pulsar.client.impl.MessageImpl) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) AuthAction(org.apache.pulsar.common.policies.data.AuthAction) AuthPolicies(org.apache.pulsar.common.policies.data.AuthPolicies) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) BrokerEntryMetadata(org.apache.pulsar.common.api.proto.BrokerEntryMetadata) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) PartitionedTopicInternalStats(org.apache.pulsar.common.policies.data.PartitionedTopicInternalStats) SchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy) OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletionException(java.util.concurrent.CompletionException) StreamingOutput(javax.ws.rs.core.StreamingOutput) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AuthenticationDataSource(org.apache.pulsar.broker.authentication.AuthenticationDataSource) PulsarByteBufAllocator(org.apache.pulsar.common.allocator.PulsarByteBufAllocator) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl) BacklogQuotaImpl(org.apache.pulsar.common.policies.data.impl.BacklogQuotaImpl) Base64(java.util.Base64) List(java.util.List) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Response(javax.ws.rs.core.Response) EncryptionKeys(org.apache.pulsar.common.api.proto.EncryptionKeys) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) PolicyName(org.apache.pulsar.common.policies.data.PolicyName) PartitionedTopicStatsImpl(org.apache.pulsar.common.policies.data.stats.PartitionedTopicStatsImpl) Optional(java.util.Optional) IntStream(java.util.stream.IntStream) CompressionCodec(org.apache.pulsar.common.compression.CompressionCodec) TopicName(org.apache.pulsar.common.naming.TopicName) Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerInfoCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ManagedLedgerInfoCallback) BacklogQuota(org.apache.pulsar.common.policies.data.BacklogQuota) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuf(io.netty.buffer.ByteBuf) LongRunningProcessStatus(org.apache.pulsar.client.admin.LongRunningProcessStatus) CompressionCodecProvider(org.apache.pulsar.common.compression.CompressionCodecProvider) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) Status(javax.ws.rs.core.Response.Status) PartitionedManagedLedgerInfo(org.apache.pulsar.common.naming.PartitionedManagedLedgerInfo) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) PersistentReplicator(org.apache.pulsar.broker.service.persistent.PersistentReplicator) Logger(org.slf4j.Logger) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TopicPolicies(org.apache.pulsar.common.policies.data.TopicPolicies) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) Policies(org.apache.pulsar.common.policies.data.Policies) TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) MessageId(org.apache.pulsar.client.api.MessageId) SystemTopicNames.isTransactionInternalName(org.apache.pulsar.common.naming.SystemTopicNames.isTransactionInternalName) TransactionCoordinatorID(org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) RestException(org.apache.pulsar.broker.web.RestException) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) RestException(org.apache.pulsar.broker.web.RestException) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) CompletionException(java.util.concurrent.CompletionException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException)

Example 5 with AlreadyRunningException

use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project incubator-pulsar by apache.

the class PersistentTopic method triggerOffload.

public synchronized void triggerOffload(MessageIdImpl messageId) throws AlreadyRunningException {
    if (currentOffload.isDone()) {
        CompletableFuture<MessageIdImpl> promise = currentOffload = new CompletableFuture<>();
        log.info("[{}] Starting offload operation at messageId {}", topic, messageId);
        getManagedLedger().asyncOffloadPrefix(PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId()), new OffloadCallback() {

            @Override
            public void offloadComplete(Position pos, Object ctx) {
                PositionImpl impl = (PositionImpl) pos;
                log.info("[{}] Completed successfully offload operation at messageId {}", topic, messageId);
                promise.complete(new MessageIdImpl(impl.getLedgerId(), impl.getEntryId(), -1));
            }

            @Override
            public void offloadFailed(ManagedLedgerException exception, Object ctx) {
                log.warn("[{}] Failed offload operation at messageId {}", topic, messageId, exception);
                promise.completeExceptionally(exception);
            }
        }, null);
    } else {
        throw new AlreadyRunningException("Offload already in progress");
    }
}
Also used : AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) OffloadCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OffloadCallback) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) Position(org.apache.bookkeeper.mledger.Position) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) BatchMessageIdImpl(org.apache.pulsar.client.impl.BatchMessageIdImpl) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl)

Aggregations

ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)12 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)12 AlreadyRunningException (org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException)12 MessageIdImpl (org.apache.pulsar.client.impl.MessageIdImpl)12 InitialPosition (org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition)12 Lists (com.google.common.collect.Lists)9 Maps (com.google.common.collect.Maps)9 Sets (com.google.common.collect.Sets)9 ByteBuf (io.netty.buffer.ByteBuf)9 ArrayList (java.util.ArrayList)9 Collections (java.util.Collections)9 List (java.util.List)9 Map (java.util.Map)9 Optional (java.util.Optional)9 Set (java.util.Set)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 CompletionException (java.util.concurrent.CompletionException)9 ExecutionException (java.util.concurrent.ExecutionException)9 TimeUnit (java.util.concurrent.TimeUnit)9 Collectors (java.util.stream.Collectors)9