Search in sources :

Example 1 with ServerMetadataException

use of com.yahoo.pulsar.broker.service.BrokerServiceException.ServerMetadataException in project pulsar by yahoo.

the class BrokerService method checkTopicNsOwnership.

void checkTopicNsOwnership(final String topic) throws RuntimeException {
    DestinationName destination = DestinationName.get(topic);
    boolean ownedByThisInstance;
    try {
        ownedByThisInstance = pulsar.getNamespaceService().isServiceUnitOwned(destination);
    } catch (Exception e) {
        log.debug(String.format("Failed to check the ownership of the destination: %s", destination), e);
        throw new RuntimeException(new ServerMetadataException(e));
    }
    if (!ownedByThisInstance) {
        String msg = String.format("Namespace not served by this instance. Please redo the lookup. " + "Request is denied: namespace=%s", destination.getNamespace());
        log.warn(msg);
        throw new RuntimeException(new ServiceUnitNotReadyException(msg));
    }
}
Also used : ServiceUnitNotReadyException(com.yahoo.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException) ServerMetadataException(com.yahoo.pulsar.broker.service.BrokerServiceException.ServerMetadataException) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) PersistenceException(com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PulsarClientException(com.yahoo.pulsar.client.api.PulsarClientException) KeeperException(org.apache.zookeeper.KeeperException) ServerMetadataException(com.yahoo.pulsar.broker.service.BrokerServiceException.ServerMetadataException) IOException(java.io.IOException) ServiceUnitNotReadyException(com.yahoo.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException)

Example 2 with ServerMetadataException

use of com.yahoo.pulsar.broker.service.BrokerServiceException.ServerMetadataException in project pulsar by yahoo.

the class PersistentTopic method checkReplication.

@Override
public CompletableFuture<Void> checkReplication() {
    DestinationName name = DestinationName.get(topic);
    if (!name.isGlobal()) {
        return CompletableFuture.completedFuture(null);
    }
    if (log.isDebugEnabled()) {
        log.debug("[{}] Checking replication status", name);
    }
    Policies policies = null;
    try {
        policies = brokerService.pulsar().getConfigurationCache().policiesCache().get(AdminResource.path("policies", name.getNamespace())).orElseThrow(() -> new KeeperException.NoNodeException());
    } catch (Exception e) {
        CompletableFuture<Void> future = new CompletableFuture<>();
        future.completeExceptionally(new ServerMetadataException(e));
        return future;
    }
    final int newMessageTTLinSeconds = policies.message_ttl_in_seconds;
    Set<String> configuredClusters;
    if (policies.replication_clusters != null) {
        configuredClusters = Sets.newTreeSet(policies.replication_clusters);
    } else {
        configuredClusters = Collections.emptySet();
    }
    String localCluster = brokerService.pulsar().getConfiguration().getClusterName();
    List<CompletableFuture<Void>> futures = Lists.newArrayList();
    // Check for missing replicators
    for (String cluster : configuredClusters) {
        if (cluster.equals(localCluster)) {
            continue;
        }
        if (!replicators.containsKey(cluster)) {
            futures.add(startReplicator(cluster));
        }
    }
    // Check for replicators to be stopped
    replicators.forEach((cluster, replicator) -> {
        // Update message TTL
        replicator.updateMessageTTL(newMessageTTLinSeconds);
        if (!cluster.equals(localCluster)) {
            if (!configuredClusters.contains(cluster)) {
                futures.add(removeReplicator(cluster));
            }
        }
    });
    return FutureUtil.waitForAll(futures);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Policies(com.yahoo.pulsar.common.policies.data.Policies) ServerMetadataException(com.yahoo.pulsar.broker.service.BrokerServiceException.ServerMetadataException) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) NamingException(com.yahoo.pulsar.broker.service.BrokerServiceException.NamingException) TopicBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.TopicBusyException) PersistenceException(com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException) TopicFencedException(com.yahoo.pulsar.broker.service.BrokerServiceException.TopicFencedException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerFencedException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerFencedException) UnsupportedVersionException(com.yahoo.pulsar.broker.service.BrokerServiceException.UnsupportedVersionException) SubscriptionBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) ConsumerBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.ConsumerBusyException) KeeperException(org.apache.zookeeper.KeeperException) BrokerServiceException(com.yahoo.pulsar.broker.service.BrokerServiceException) ServerMetadataException(com.yahoo.pulsar.broker.service.BrokerServiceException.ServerMetadataException)

Aggregations

PersistenceException (com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException)2 ServerMetadataException (com.yahoo.pulsar.broker.service.BrokerServiceException.ServerMetadataException)2 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)2 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)2 KeeperException (org.apache.zookeeper.KeeperException)2 BrokerServiceException (com.yahoo.pulsar.broker.service.BrokerServiceException)1 ConsumerBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.ConsumerBusyException)1 NamingException (com.yahoo.pulsar.broker.service.BrokerServiceException.NamingException)1 ServiceUnitNotReadyException (com.yahoo.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException)1 SubscriptionBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)1 TopicBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.TopicBusyException)1 TopicFencedException (com.yahoo.pulsar.broker.service.BrokerServiceException.TopicFencedException)1 UnsupportedVersionException (com.yahoo.pulsar.broker.service.BrokerServiceException.UnsupportedVersionException)1 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 Policies (com.yahoo.pulsar.common.policies.data.Policies)1 IOException (java.io.IOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ManagedLedgerFencedException (org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerFencedException)1