private boolean topicNameValid(String topicName) { checkArgument(TopicName.isValid(topicName), "Invalid topic name:" + topicName); checkArgument(!topics.containsKey(topicName), "Topics already contains topic:" + topicName); if (this.namespaceName != null) { checkArgument(TopicName.get(topicName).getNamespace().toString().equals(this.namespaceName.toString()), "Topic " + topicName + " not in same namespace with Topics"); } return true; }
private static boolean topicNamesValid(Collection<String> topics) { checkState(topics != null && topics.size() >= 1, "topics should should contain more than 1 topic"); final String namespace = TopicName.get(topics.stream().findFirst().get()).getNamespace(); Optional<String> result = topics.stream() .filter(topic -> { boolean topicInvalid = !TopicName.isValid(topic); if (topicInvalid) { return true; } String newNamespace = TopicName.get(topic).getNamespace(); if (!namespace.equals(newNamespace)) { return true; } else { return false; } }).findFirst(); if (result.isPresent()) { log.warn("[{}] Received invalid topic name. {}/{}", result.get()); return false; } // check topic names are unique HashSet<String> set = new HashSet<>(topics); if (set.size() == topics.size()) { return true; } else { log.warn("Topic names not unique. unique/all : {}/{}", set.size(), topics.size()); return false; } }
private void put(TopicName topicName, PendingBookieOpsStats bookieOpsStats) { String namespace = topicName.getNamespace(); if (!nsBookieClientStatsMap.containsKey(namespace)) { Map<String, PendingBookieOpsStats> destBookieClientStatsMap = Maps.newTreeMap(); destBookieClientStatsMap.put(topicName.toString(), bookieOpsStats); nsBookieClientStatsMap.put(namespace, destBookieClientStatsMap); } else { nsBookieClientStatsMap.get(namespace).put(topicName.toString(), bookieOpsStats); } } }
private boolean topicNameValid(String topicName) { checkArgument(TopicName.isValid(topicName), "Invalid topic name:" + topicName); checkArgument(!topics.containsKey(topicName), "Topics already contains topic:" + topicName); if (this.namespaceName != null) { checkArgument(TopicName.get(topicName).getNamespace().toString().equals(this.namespaceName.toString()), "Topic " + topicName + " not in same namespace with Topics"); } return true; }
void checkTopicNsOwnership(final String topic) throws RuntimeException { TopicName topicName = TopicName.get(topic); boolean ownedByThisInstance; try { ownedByThisInstance = pulsar.getNamespaceService().isServiceUnitOwned(topicName); } catch (Exception e) { log.debug(String.format("Failed to check the ownership of the topic: %s", topicName), e); throw new RuntimeException(new ServerMetadataException(e)); } if (!ownedByThisInstance) { String msg = String.format("Namespace bundle for topic (%s) not served by this instance. Please redo the lookup. " + "Request is denied: namespace=%s", topic, topicName.getNamespace()); log.warn(msg); throw new RuntimeException(new ServiceUnitNotReadyException(msg)); } }
private CompletableFuture<Boolean> isDeduplicationEnabled() { TopicName name = TopicName.get(topic.getName()); return pulsar.getConfigurationCache().policiesCache() .getAsync(AdminResource.path(POLICIES, name.getNamespace())).thenApply(policies -> { // If namespace policies have the field set, it will override the broker-level setting if (policies.isPresent() && policies.get().deduplicationEnabled != null) { return policies.get().deduplicationEnabled; } return pulsar.getConfiguration().isBrokerDeduplicationEnabled(); }); }
/** * * @param topic * needing quota enforcement check * @return determine if quota enforcement needs to be done for topic */ public boolean isBacklogExceeded(PersistentTopic topic) { TopicName topicName = TopicName.get(topic.getName()); long backlogQuotaLimitInBytes = getBacklogQuotaManager().getBacklogQuotaLimit(topicName.getNamespace()); if (log.isDebugEnabled()) { log.debug("[{}] - backlog quota limit = [{}]", topic.getName(), backlogQuotaLimitInBytes); } // check if backlog exceeded quota long storageSize = topic.getBacklogSize(); if (log.isDebugEnabled()) { log.debug("[{}] Storage size = [{}], limit [{}]", topic.getName(), storageSize, backlogQuotaLimitInBytes); } return (storageSize >= backlogQuotaLimitInBytes); }
public static String partitionedTopicPath(TopicName name) { return adminPath(PARTITIONED_TOPIC_PATH_ZNODE, name.getNamespace(), name.getDomain().value(), name.getEncodedLocalName()); }
/** * * @return Backlog quota for topic */ @Override public BacklogQuota getBacklogQuota() { TopicName topicName = TopicName.get(this.getName()); String namespace = topicName.getNamespace(); String policyPath = AdminResource.path(POLICIES, namespace); BacklogQuota backlogQuota = brokerService.getBacklogQuotaManager().getBacklogQuota(namespace, policyPath); return backlogQuota; }
@Override public void checkMessageExpiry() { TopicName name = TopicName.get(topic); Policies policies; try { policies = brokerService.pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, name.getNamespace())) .orElseThrow(() -> new KeeperException.NoNodeException()); if (policies.message_ttl_in_seconds != 0) { subscriptions.forEach((subName, sub) -> sub.expireMessages(policies.message_ttl_in_seconds)); replicators.forEach((region, replicator) -> ((PersistentReplicator)replicator).expireMessages(policies.message_ttl_in_seconds)); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("[{}] Error getting policies", topic); } } }
public NonPersistentTopic(String topic, BrokerService brokerService) { this.topic = topic; this.brokerService = brokerService; this.producers = new ConcurrentOpenHashSet<Producer>(16, 1); this.subscriptions = new ConcurrentOpenHashMap<>(16, 1); this.replicators = new ConcurrentOpenHashMap<>(16, 1); this.isFenced = false; this.replicatorPrefix = brokerService.pulsar().getConfiguration().getReplicatorPrefix(); this.executor = brokerService.getTopicOrderedExecutor(); USAGE_COUNT_UPDATER.set(this, 0); this.lastActive = System.nanoTime(); try { Policies policies = brokerService.pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topic).getNamespace())) .orElseThrow(() -> new KeeperException.NoNodeException()); isEncryptionRequired = policies.encryption_required; } catch (Exception e) { log.warn("[{}] Error getting policies {} and isEncryptionRequired will be set to false", topic, e.getMessage()); isEncryptionRequired = false; } }
protected boolean isConsumersExceededOnTopic() { Policies policies; try { policies = topic.getBrokerService().pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topicName).getNamespace())) .orElseGet(() -> new Policies()); } catch (Exception e) { policies = new Policies(); } final int maxConsumersPerTopic = policies.max_consumers_per_topic > 0 ? policies.max_consumers_per_topic : serviceConfig.getMaxConsumersPerTopic(); if (maxConsumersPerTopic > 0 && maxConsumersPerTopic <= topic.getNumberOfConsumers()) { return true; } return false; }
protected boolean isConsumersExceededOnSubscription() { Policies policies; try { policies = topic.getBrokerService().pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topicName).getNamespace())) .orElseGet(() -> new Policies()); } catch (Exception e) { policies = new Policies(); } final int maxConsumersPerSubscription = policies.max_consumers_per_subscription > 0 ? policies.max_consumers_per_subscription : serviceConfig.getMaxConsumersPerSubscription(); if (maxConsumersPerSubscription > 0 && maxConsumersPerSubscription <= consumers.size()) { return true; } return false; }
protected boolean isConsumersExceededOnTopic() { Policies policies; try { policies = topic.getBrokerService().pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topicName).getNamespace())) .orElseGet(() -> new Policies()); } catch (Exception e) { policies = new Policies(); } final int maxConsumersPerTopic = policies.max_consumers_per_topic > 0 ? policies.max_consumers_per_topic : serviceConfig.getMaxConsumersPerTopic(); if (maxConsumersPerTopic > 0 && maxConsumersPerTopic <= topic.getNumberOfConsumers()) { return true; } return false; }
private void addTopicToStatsMaps(TopicName topicName, Topic topic) { try { NamespaceBundle namespaceBundle = pulsar.getNamespaceService().getBundle(topicName); if (namespaceBundle != null) { synchronized (multiLayerTopicsMap) { String serviceUnit = namespaceBundle.toString(); multiLayerTopicsMap // .computeIfAbsent(topicName.getNamespace(), k -> new ConcurrentOpenHashMap<>()) // .computeIfAbsent(serviceUnit, k -> new ConcurrentOpenHashMap<>()) // .put(topicName.toString(), topic); } } invalidateOfflineTopicStatCache(topicName); } catch (Exception e) { log.warn("Got exception when retrieving bundle name during create persistent topic", e); } }
protected boolean isConsumersExceededOnSubscription() { Policies policies; try { policies = topic.getBrokerService().pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topicName).getNamespace())) .orElseGet(() -> new Policies()); } catch (Exception e) { policies = new Policies(); } final int maxConsumersPerSubscription = policies.max_consumers_per_subscription > 0 ? policies.max_consumers_per_subscription : serviceConfig.getMaxConsumersPerSubscription(); if (maxConsumersPerSubscription > 0 && maxConsumersPerSubscription <= consumers.size()) { return true; } return false; }
private boolean isProducersExceeded() { Policies policies; try { policies = brokerService.pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topic).getNamespace())) .orElseGet(() -> new Policies()); } catch (Exception e) { policies = new Policies(); } final int maxProducers = policies.max_producers_per_topic > 0 ? policies.max_producers_per_topic : brokerService.pulsar().getConfiguration().getMaxProducersPerTopic(); if (maxProducers > 0 && maxProducers <= producers.size()) { return true; } return false; }
private boolean isProducersExceeded() { Policies policies; try { policies = brokerService.pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topic).getNamespace())) .orElseGet(() -> new Policies()); } catch (Exception e) { policies = new Policies(); } final int maxProducers = policies.max_producers_per_topic > 0 ? policies.max_producers_per_topic : brokerService.pulsar().getConfiguration().getMaxProducersPerTopic(); if (maxProducers > 0 && maxProducers <= producers.size()) { return true; } return false; }
private boolean isConsumersExceededOnTopic() { Policies policies; try { policies = topic.getBrokerService().pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topic.getName()).getNamespace())) .orElseGet(() -> new Policies()); } catch (Exception e) { policies = new Policies(); } final int maxConsumersPerTopic = policies.max_consumers_per_topic > 0 ? policies.max_consumers_per_topic : serviceConfig.getMaxConsumersPerTopic(); if (maxConsumersPerTopic > 0 && maxConsumersPerTopic <= topic.getNumberOfConsumers()) { return true; } return false; }
private boolean isConsumersExceededOnSubscription() { Policies policies; try { policies = topic.getBrokerService().pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topic.getName()).getNamespace())) .orElseGet(() -> new Policies()); } catch (Exception e) { policies = new Policies(); } final int maxConsumersPerSubscription = policies.max_consumers_per_subscription > 0 ? policies.max_consumers_per_subscription : serviceConfig.getMaxConsumersPerSubscription(); if (maxConsumersPerSubscription > 0 && maxConsumersPerSubscription <= consumerList.size()) { return true; } return false; }