Search in sources :

Example 1 with TopicBusyException

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

the class NonPersistentTopic method delete.

private CompletableFuture<Void> delete(boolean failIfHasSubscriptions) {
    CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
    lock.writeLock().lock();
    try {
        if (isFenced) {
            log.warn("[{}] Topic is already being closed or deleted", topic);
            deleteFuture.completeExceptionally(new TopicFencedException("Topic is already fenced"));
            return deleteFuture;
        }
        if (USAGE_COUNT_UPDATER.get(this) == 0) {
            isFenced = true;
            List<CompletableFuture<Void>> futures = Lists.newArrayList();
            if (failIfHasSubscriptions) {
                if (!subscriptions.isEmpty()) {
                    isFenced = false;
                    deleteFuture.completeExceptionally(new TopicBusyException("Topic has subscriptions"));
                    return deleteFuture;
                }
            } else {
                subscriptions.forEach((s, sub) -> futures.add(sub.delete()));
            }
            FutureUtil.waitForAll(futures).whenComplete((v, ex) -> {
                if (ex != null) {
                    log.error("[{}] Error deleting topic", topic, ex);
                    isFenced = false;
                    deleteFuture.completeExceptionally(ex);
                } else {
                    brokerService.removeTopicFromCache(topic);
                    log.info("[{}] Topic deleted", topic);
                    deleteFuture.complete(null);
                }
            });
        } else {
            deleteFuture.completeExceptionally(new TopicBusyException("Topic has " + USAGE_COUNT_UPDATER.get(this) + " connected producers/consumers"));
        }
    } finally {
        lock.writeLock().unlock();
    }
    return deleteFuture;
}
Also used : TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) CompletableFuture(java.util.concurrent.CompletableFuture) TopicFencedException(org.apache.pulsar.broker.service.BrokerServiceException.TopicFencedException)

Example 2 with TopicBusyException

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

the class PersistentTopicsBase method internalDeleteTopic.

protected void internalDeleteTopic(boolean authoritative) {
    validateAdminOperationOnTopic(authoritative);
    Topic topic = getTopicReference(topicName);
    // v2 topics have a global name so check if the topic is replicated.
    if (topic.isReplicated()) {
        // Delete is disallowed on global topic
        log.error("[{}] Delete topic is forbidden on global namespace {}", clientAppId(), topicName);
        throw new RestException(Status.FORBIDDEN, "Delete forbidden on global namespace");
    }
    try {
        topic.delete().get();
        log.info("[{}] Successfully removed topic {}", clientAppId(), topicName);
    } catch (Exception e) {
        Throwable t = e.getCause();
        log.error("[{}] Failed to get delete topic {}", clientAppId(), topicName, t);
        if (t instanceof TopicBusyException) {
            throw new RestException(Status.PRECONDITION_FAILED, "Topic has active producers/subscriptions");
        } else {
            throw new RestException(t);
        }
    }
}
Also used : TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) RestException(org.apache.pulsar.broker.web.RestException) Topic(org.apache.pulsar.broker.service.Topic) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) RestException(org.apache.pulsar.broker.web.RestException) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) WebApplicationException(javax.ws.rs.WebApplicationException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException)

Example 3 with TopicBusyException

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

the class PersistentTopic method delete.

/**
 * Delete the managed ledger associated with this topic
 *
 * @param failIfHasSubscriptions
 *            Flag indicating whether delete should succeed if topic still has unconnected subscriptions. Set to
 *            false when called from admin API (it will delete the subs too), and set to true when called from GC
 *            thread
 *
 * @return Completable future indicating completion of delete operation Completed exceptionally with:
 *         IllegalStateException if topic is still active ManagedLedgerException if ledger delete operation fails
 */
private CompletableFuture<Void> delete(boolean failIfHasSubscriptions) {
    CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
    lock.writeLock().lock();
    try {
        if (isFenced) {
            log.warn("[{}] Topic is already being closed or deleted", topic);
            deleteFuture.completeExceptionally(new TopicFencedException("Topic is already fenced"));
            return deleteFuture;
        }
        if (USAGE_COUNT_UPDATER.get(this) == 0) {
            isFenced = true;
            List<CompletableFuture<Void>> futures = Lists.newArrayList();
            if (failIfHasSubscriptions) {
                if (!subscriptions.isEmpty()) {
                    isFenced = false;
                    deleteFuture.completeExceptionally(new TopicBusyException("Topic has subscriptions"));
                    return deleteFuture;
                }
            } else {
                subscriptions.forEach((s, sub) -> futures.add(sub.delete()));
            }
            FutureUtil.waitForAll(futures).whenComplete((v, ex) -> {
                if (ex != null) {
                    log.error("[{}] Error deleting topic", topic, ex);
                    isFenced = false;
                    deleteFuture.completeExceptionally(ex);
                } else {
                    ledger.asyncDelete(new AsyncCallbacks.DeleteLedgerCallback() {

                        @Override
                        public void deleteLedgerComplete(Object ctx) {
                            brokerService.removeTopicFromCache(topic);
                            log.info("[{}] Topic deleted", topic);
                            deleteFuture.complete(null);
                        }

                        @Override
                        public void deleteLedgerFailed(ManagedLedgerException exception, Object ctx) {
                            isFenced = false;
                            log.error("[{}] Error deleting topic", topic, exception);
                            deleteFuture.completeExceptionally(new PersistenceException(exception));
                        }
                    }, null);
                }
            });
        } else {
            deleteFuture.completeExceptionally(new TopicBusyException("Topic has " + USAGE_COUNT_UPDATER.get(this) + " connected producers/consumers"));
        }
    } finally {
        lock.writeLock().unlock();
    }
    return deleteFuture;
}
Also used : TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) TopicFencedException(org.apache.pulsar.broker.service.BrokerServiceException.TopicFencedException) PersistenceException(org.apache.pulsar.broker.service.BrokerServiceException.PersistenceException) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks)

Example 4 with TopicBusyException

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

the class AbstractReplicator method disconnect.

public synchronized CompletableFuture<Void> disconnect(boolean failIfHasBacklog) {
    if (failIfHasBacklog && getNumberOfEntriesInBacklog() > 0) {
        CompletableFuture<Void> disconnectFuture = new CompletableFuture<>();
        disconnectFuture.completeExceptionally(new TopicBusyException("Cannot close a replicator with backlog"));
        log.debug("[{}][{} -> {}] Replicator disconnect failed since topic has backlog", topicName, localCluster, remoteCluster);
        return disconnectFuture;
    }
    if (STATE_UPDATER.get(this) == State.Stopping) {
        // which will at some point change the state to stopped
        return CompletableFuture.completedFuture(null);
    }
    if (producer != null && (STATE_UPDATER.compareAndSet(this, State.Starting, State.Stopping) || STATE_UPDATER.compareAndSet(this, State.Started, State.Stopping))) {
        log.info("[{}][{} -> {}] Disconnect replicator at position {} with backlog {}", topicName, localCluster, remoteCluster, getReplicatorReadPosition(), getNumberOfEntriesInBacklog());
        return closeProducerAsync();
    }
    STATE_UPDATER.set(this, State.Stopped);
    return CompletableFuture.completedFuture(null);
}
Also used : TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) CompletableFuture(java.util.concurrent.CompletableFuture)

Aggregations

TopicBusyException (org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)2 TopicFencedException (org.apache.pulsar.broker.service.BrokerServiceException.TopicFencedException)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)1 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)1 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)1 PersistenceException (org.apache.pulsar.broker.service.BrokerServiceException.PersistenceException)1 SubscriptionBusyException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)1 Topic (org.apache.pulsar.broker.service.Topic)1 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)1 RestException (org.apache.pulsar.broker.web.RestException)1 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)1 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)1 PreconditionFailedException (org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)1 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)1 KeeperException (org.apache.zookeeper.KeeperException)1