-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PIP-2: Introduce non-persistent topics #538
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a282cff
Introduce non-persistent topic and tests
rdhabalia 5c0f42b
Make broker configurable to own non-persistent topic
rdhabalia 9e80ccf
add producer/sub message-drop stats
rdhabalia c363bcc
cleanup and rename variable name
rdhabalia 670ed2f
fix: cli topic-name validation + update-stats
rdhabalia 9989b6f
added abstract parent class dispatcher and replicator
rdhabalia 77e5c76
fix: reflection test
rdhabalia 2d211af
added non-persistent stats classes
rdhabalia 669e7a9
add non-persistent topic stats documentation
rdhabalia 50fdd31
formating + batch-number counting for msg-drop + ack-publish on same …
rdhabalia 883af92
replace semaphore with counter for maxNonPersistentPendingMessages
rdhabalia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import java.net.URI; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import javax.servlet.ServletContext; | ||
import javax.ws.rs.WebApplicationException; | ||
|
@@ -36,17 +37,21 @@ | |
import org.apache.pulsar.broker.cache.LocalZooKeeperCacheService; | ||
import org.apache.pulsar.broker.web.PulsarWebResource; | ||
import org.apache.pulsar.broker.web.RestException; | ||
import org.apache.pulsar.common.naming.DestinationDomain; | ||
import org.apache.pulsar.common.naming.DestinationName; | ||
import org.apache.pulsar.common.naming.NamespaceBundle; | ||
import org.apache.pulsar.common.naming.NamespaceBundleFactory; | ||
import org.apache.pulsar.common.naming.NamespaceBundles; | ||
import org.apache.pulsar.common.naming.NamespaceName; | ||
import org.apache.pulsar.common.partition.PartitionedTopicMetadata; | ||
import org.apache.pulsar.common.policies.data.BundlesData; | ||
import org.apache.pulsar.common.policies.data.ClusterData; | ||
import org.apache.pulsar.common.policies.data.Policies; | ||
import org.apache.pulsar.common.policies.data.PropertyAdmin; | ||
import org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies; | ||
import org.apache.pulsar.common.util.ObjectMapperFactory; | ||
import org.apache.pulsar.zookeeper.ZooKeeperCache; | ||
import org.apache.pulsar.zookeeper.ZooKeeperCache.Deserializer; | ||
import org.apache.pulsar.zookeeper.ZooKeeperChildrenCache; | ||
import org.apache.pulsar.zookeeper.ZooKeeperDataCache; | ||
import org.apache.zookeeper.CreateMode; | ||
|
@@ -64,6 +69,7 @@ public abstract class AdminResource extends PulsarWebResource { | |
private static final Logger log = LoggerFactory.getLogger(AdminResource.class); | ||
private static final String POLICIES_READONLY_FLAG_PATH = "/admin/flags/policies-readonly"; | ||
public static final String LOAD_SHEDDING_UNLOAD_DISABLED_FLAG_PATH = "/admin/flags/load-shedding-unload-disabled"; | ||
public static final String PARTITIONED_TOPIC_PATH_ZNODE = "partitioned-topics"; | ||
|
||
protected ZooKeeper globalZk() { | ||
return pulsar().getGlobalZkCache().getZooKeeper(); | ||
|
@@ -97,12 +103,10 @@ protected void zkCreateOptimistic(String path, byte[] content) throws Exception | |
* Get the domain of the destination (whether it's queue or topic) | ||
*/ | ||
protected String domain() { | ||
if (uri.getPath().startsWith("queues/")) { | ||
return "queue"; | ||
} else if (uri.getPath().startsWith("topics/")) { | ||
return "topic"; | ||
} else if (uri.getPath().startsWith("persistent/")) { | ||
if (uri.getPath().startsWith("persistent/")) { | ||
return "persistent"; | ||
} else if (uri.getPath().startsWith("non-persistent/")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side note: should we remove |
||
return "non-persistent"; | ||
} else { | ||
throw new RestException(Status.INTERNAL_SERVER_ERROR, "domain() invoked from wrong resource"); | ||
} | ||
|
@@ -281,4 +285,69 @@ protected ZooKeeperDataCache<NamespaceIsolationPolicies> namespaceIsolationPolic | |
return pulsar().getConfigurationCache().namespaceIsolationPoliciesCache(); | ||
} | ||
|
||
protected PartitionedTopicMetadata getPartitionedTopicMetadata(String property, String cluster, String namespace, | ||
String destination, boolean authoritative) { | ||
DestinationName dn = DestinationName.get(domain(), property, cluster, namespace, destination); | ||
validateClusterOwnership(dn.getCluster()); | ||
|
||
try { | ||
checkConnect(dn); | ||
} catch (WebApplicationException e) { | ||
validateAdminAccessOnProperty(dn.getProperty()); | ||
} catch (Exception e) { | ||
// unknown error marked as internal server error | ||
log.warn("Unexpected error while authorizing lookup. destination={}, role={}. Error: {}", destination, | ||
clientAppId(), e.getMessage(), e); | ||
throw new RestException(e); | ||
} | ||
|
||
String path = path(PARTITIONED_TOPIC_PATH_ZNODE, property, cluster, namespace, domain(), | ||
dn.getEncodedLocalName()); | ||
PartitionedTopicMetadata partitionMetadata = fetchPartitionedTopicMetadata(pulsar(), path); | ||
|
||
if (log.isDebugEnabled()) { | ||
log.debug("[{}] Total number of partitions for topic {} is {}", clientAppId(), dn, | ||
partitionMetadata.partitions); | ||
} | ||
return partitionMetadata; | ||
} | ||
|
||
protected static PartitionedTopicMetadata fetchPartitionedTopicMetadata(PulsarService pulsar, String path) { | ||
try { | ||
return fetchPartitionedTopicMetadataAsync(pulsar, path).get(); | ||
} catch (Exception e) { | ||
if (e.getCause() instanceof RestException) { | ||
throw (RestException) e; | ||
} | ||
throw new RestException(e); | ||
} | ||
} | ||
|
||
protected static CompletableFuture<PartitionedTopicMetadata> fetchPartitionedTopicMetadataAsync(PulsarService pulsar, | ||
String path) { | ||
CompletableFuture<PartitionedTopicMetadata> metadataFuture = new CompletableFuture<>(); | ||
try { | ||
// gets the number of partitions from the zk cache | ||
pulsar.getGlobalZkCache().getDataAsync(path, new Deserializer<PartitionedTopicMetadata>() { | ||
@Override | ||
public PartitionedTopicMetadata deserialize(String key, byte[] content) throws Exception { | ||
return jsonMapper().readValue(content, PartitionedTopicMetadata.class); | ||
} | ||
}).thenAccept(metadata -> { | ||
// if the partitioned topic is not found in zk, then the topic is not partitioned | ||
if (metadata.isPresent()) { | ||
metadataFuture.complete(metadata.get()); | ||
} else { | ||
metadataFuture.complete(new PartitionedTopicMetadata()); | ||
} | ||
}).exceptionally(ex -> { | ||
metadataFuture.completeExceptionally(ex); | ||
return null; | ||
}); | ||
} catch (Exception e) { | ||
metadataFuture.completeExceptionally(e); | ||
} | ||
return metadataFuture; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, for non-persistent topics we want to create
Entry
with specific ledgerId-entryId and payload so, it can be pass to other entities (eg: dispatcher, consumer) as those entities APIs requires aEntry
wrapper to pass payload/msgId information.