public NamespaceBundle getBundle(NamespaceName nsname, Range<Long> hashRange) { return new NamespaceBundle(nsname, hashRange, this); }
@Override public String toString() { return getKey(this.nsname, this.keyRange); }
public void validateBundle(NamespaceBundle nsBundle) throws Exception { int idx = Arrays.binarySearch(partitions, nsBundle.getLowerEndpoint()); checkArgument(idx >= 0, "Cannot find bundle in the bundles list"); checkArgument(nsBundle.getUpperEndpoint().equals(bundles.get(idx).getUpperEndpoint()), "Invalid upper boundary for bundle"); }
public Map<String, NamespaceOwnershipStatus> getOwnedNameSpacesStatus() throws Exception { NamespaceIsolationPolicies nsIsolationPolicies = this.getLocalNamespaceIsolationPolicies(); Map<String, NamespaceOwnershipStatus> ownedNsStatus = new HashMap<String, NamespaceOwnershipStatus>(); for (OwnedBundle nsObj : this.ownershipCache.getOwnedBundles().values()) { NamespaceOwnershipStatus nsStatus = this.getNamespaceOwnershipStatus(nsObj, nsIsolationPolicies.getPolicyByNamespace(nsObj.getNamespaceBundle().getNamespaceObject())); ownedNsStatus.put(nsObj.getNamespaceBundle().toString(), nsStatus); } return ownedNsStatus; }
public static final String path(NamespaceBundle suname) { // The ephemeral node path for new namespaces should always have bundle name appended return OWNER_INFO_ROOT + "/" + suname.toString(); }
nsBundle.getBundleRange(), subscription);
throws Exception { checkNotNull(targetBundle, "can't split null bundle"); checkNotNull(targetBundle.getNamespaceObject(), "namespace must be present"); NamespaceName nsname = targetBundle.getNamespaceObject(); NamespaceBundles sourceBundle = bundlesCache.synchronous().get(nsname); int splitPartition = -1; for (int i = 0; i < lastIndex; i++) { final Range<Long> range = targetBundle.getKeyRange(); if (sourceBundle.partitions[i] == range.lowerEndpoint() && (range.upperEndpoint() == sourceBundle.partitions[i + 1])) {
LOG.info("Loading all topics on bundle: {}", bundle); NamespaceName nsName = bundle.getNamespaceObject(); List<CompletableFuture<Topic>> persistentTopics = Lists.newArrayList(); long topicLoadStart = System.nanoTime(); try { DestinationName dn = DestinationName.get(topic); if (bundle.includes(dn)) { CompletableFuture<Topic> future = brokerService.getTopic(topic); if (future != null) {
@Override public int compareTo(NamespaceBundle other) { if (this.nsname.toString().compareTo(other.nsname.toString()) != 0) { return this.nsname.toString().compareTo(other.nsname.toString()); } if (equals(other)) { // completely the same range, return true return 0; } try { /** * <code>Range.insersection()</code> will throw <code>IllegalArgumentException</code> when two ranges are * not connected at all, which is a OK case for our comparison. <code>checkState</code> here is to ensure * that the two ranges we are comparing don't have overlaps. */ checkState(this.keyRange.intersection(other.keyRange).isEmpty(), "Can't compare two key ranges with non-empty intersection set"); } catch (IllegalArgumentException iae) { // OK if two ranges are not connected at all } catch (IllegalStateException ise) { // It is not OK if the intersection is not empty throw new IllegalArgumentException(ise.getMessage(), ise); } // Now we are sure that two bundles don't have overlap return this.keyRange.lowerEndpoint().compareTo(other.keyRange.lowerEndpoint()); }
public void removeOwnedServiceUnit(NamespaceBundle nsBundle) throws Exception { ownershipCache.removeOwnership(nsBundle).get(cacheTimeOutInSec, SECONDS); bundleFactory.invalidateBundleCache(nsBundle.getNamespaceObject()); }
/** * Unload all the topic served by the broker service under the given service unit * * @param serviceUnit * @return */ public CompletableFuture<Integer> unloadServiceUnit(NamespaceBundle serviceUnit) { CompletableFuture<Integer> result = new CompletableFuture<Integer>(); List<CompletableFuture<Void>> closeFutures = Lists.newArrayList(); topics.forEach((name, topicFuture) -> { DestinationName topicName = DestinationName.get(name); if (serviceUnit.includes(topicName)) { // Topic needs to be unloaded log.info("[{}] Unloading topic", topicName); closeFutures.add(topicFuture.thenCompose(Topic::close)); } }); CompletableFuture<Void> aggregator = FutureUtil.waitForAll(closeFutures); aggregator.thenAccept(res -> result.complete(closeFutures.size())).exceptionally(ex -> { result.completeExceptionally(ex); return null; }); return result; }
/** * Get resource quota for a specified service unit. * * @param suName * identifier of the <code>ServiceUnit</code> * * @return the <code>ResourceQuota</code>. */ public ResourceQuota getQuota(NamespaceBundle suName) { String suNameStr = (suName == null) ? null : suName.toString(); return this.getQuota(suNameStr); }
public void refreshTopicToStatsMaps(NamespaceBundle oldBundle) { checkNotNull(oldBundle); try { // retrieve all topics under existing old bundle List<PersistentTopic> topics = getAllTopicsFromNamespaceBundle(oldBundle.getNamespaceObject().toString(), oldBundle.toString()); if (!isEmpty(topics)) { // add topic under new split bundles which already updated into NamespaceBundleFactory.bundleCache topics.stream().forEach(t -> { addTopicToStatsMaps(DestinationName.get(t.getName()), t); }); // remove old bundle from the map synchronized (multiLayerTopicsMap) { multiLayerTopicsMap.get(oldBundle.getNamespaceObject().toString()).remove(oldBundle.toString()); } } } catch (Exception e) { log.warn("Got exception while refreshing topicStats map", e); } }
nsBundle.getBundleRange());
NamespaceBundle destinationBundle = (NamespaceBundle) pulsar().getNamespaceService() .getBundle(DestinationName.get(destination)); if (bundle.equals(destinationBundle)) { throw new RestException(Status.CONFLICT, "Cannot delete non empty bundle");
/** * Set resource quota for a specified <code>ServiceUnit</code>. * * @param suName * identifier of the <code>ServiceUnit</code> * @param quota * <code>ResourceQuota</code> to set. */ public void setQuota(NamespaceBundle suName, ResourceQuota quota) throws Exception { String suNameStr = (suName == null) ? null : suName.toString(); this.setQuota(suNameStr, quota); }
checkNotNull(splittedBundles.getRight()); checkArgument(splittedBundles.getRight().size() == 2, "bundle has to be split in two bundles"); NamespaceName nsname = bundle.getNamespaceObject(); try { String msg1 = format( "failed to disable bundle %s under namespace [%s] with error %s", nsname.toString(), bundle.toString(), e.getMessage()); LOG.warn(msg1, e); future.completeExceptionally(new ServiceUnitNotReadyException(msg1)); String msg = format("bundle %s not found under namespace", bundle.toString()); future.completeExceptionally(new ServiceUnitNotReadyException(msg));
nsName.toString(), nsBundle.getBundleRange(), subscription);
fullBundle = new NamespaceBundle(nsname, Range.range(FULL_LOWER_BOUND, BoundType.CLOSED, FULL_UPPER_BOUND, BoundType.CLOSED), factory); bundles.add(new NamespaceBundle(nsname, newRange, factory)); lowerBound = upperBound;
/** * Remove resource quota for a specified <code>ServiceUnit</code> to use the default quota. * * @param suName * identifier of the <code>ServiceUnit</code> */ public void unsetQuota(NamespaceBundle suName) throws Exception { String suNameStr = (suName == null) ? null : suName.toString(); this.unsetQuota(suNameStr); } }