poorbarcode commented on code in PR #18193:
URL: https://github.com/apache/pulsar/pull/18193#discussion_r1005919247
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -2886,30 +2888,38 @@ public CompletableFuture<PartitionedTopicMetadata>
fetchPartitionedTopicMetadata
if (metadata.partitions == 0
&& !topicExists
&& !topicName.isPartitioned()
- &&
pulsar.getBrokerService().isAllowAutoTopicCreation(topicName, policies)
&& pulsar.getBrokerService()
.isDefaultTopicTypePartitioned(topicName, policies)) {
-
- pulsar.getBrokerService()
-
.createDefaultPartitionedTopicAsync(topicName, policies)
- .thenAccept(md ->
future.complete(md))
- .exceptionally(ex -> {
- if (ex.getCause()
- instanceof
MetadataStoreException.AlreadyExistsException) {
- // The partitioned
topic might be created concurrently
-
fetchPartitionedTopicMetadataAsync(topicName)
-
.whenComplete((metadata2, ex2) -> {
- if (ex2 ==
null) {
-
future.complete(metadata2);
- } else {
-
future.completeExceptionally(ex2);
- }
- });
- } else {
-
future.completeExceptionally(ex);
- }
- return null;
- });
+
isAllowAutoTopicCreationAsync(topicName, policies).thenAccept(allowed -> {
Review Comment:
How do we make sure the cache data is not outdated? E.g:
| `broker-1` | `broker-2`|
|---|---|
| | read meta from cache |
| delete topic `tp_test` | |
| write meta | |
| | create `tp_test-partion-0` |
| | cache update |
| | create finish. bingo! |
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/NamespaceResources.java:
##########
@@ -295,6 +296,79 @@ public CompletableFuture<Void>
clearPartitionedTopicTenantAsync(String tenant) {
final String partitionedTopicPath =
joinPath(PARTITIONED_TOPIC_PATH, tenant);
return deleteIfExistsAsync(partitionedTopicPath);
}
+
+ public CompletableFuture<Void>
markPartitionedTopicDeletedAsync(TopicName tn) {
+ if (tn.isPartitioned()) {
+ return CompletableFuture.completedFuture(null);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("markPartitionedTopicDeletedAsync {}", tn);
+ }
+ return updatePartitionedTopicAsync(tn, md -> {
+ md.deleted = true;
+ return md;
+ });
+ }
+
+ public CompletableFuture<Void>
unmarkPartitionedTopicDeletedAsync(TopicName tn) {
+ if (tn.isPartitioned()) {
+ return CompletableFuture.completedFuture(null);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("unmarkPartitionedTopicDeletedAsync {}", tn);
+ }
+ return updatePartitionedTopicAsync(tn, md -> {
+ md.deleted = false;
+ return md;
+ });
+ }
+
+ public CompletableFuture<Boolean>
isPartitionedTopicBeingDeletedAsync(TopicName tn) {
+ if (tn.isPartitioned()) {
+ tn = TopicName.get(tn.getPartitionedTopicName());
+ }
+ return getPartitionedTopicMetadataAsync(tn)
+ .thenApply(mdOpt -> mdOpt.map(partitionedTopicMetadata ->
partitionedTopicMetadata.deleted)
+ .orElse(false));
+ }
+
+ public CompletableFuture<Void> runWithMarkDeleteAsync(TopicName topic,
+
Supplier<CompletableFuture<Void>> supplier) {
+ CompletableFuture<Void> future = new CompletableFuture<>();
+
+
markPartitionedTopicDeletedAsync(topic).whenCompleteAsync((markResult, markExc)
-> {
+ final boolean mdFound;
+ if (markExc != null) {
+ if (markExc.getCause() instanceof
MetadataStoreException.NotFoundException) {
+ mdFound = false;
+ } else {
+ log.error("Failed to mark the topic {} as deleted",
topic, markExc);
+ future.completeExceptionally(markExc);
+ return;
+ }
+ } else {
+ mdFound = true;
+ }
+
+ supplier.get().whenComplete((deleteResult, deleteExc) -> {
+ if (deleteExc != null && mdFound) {
+ unmarkPartitionedTopicDeletedAsync(topic)
Review Comment:
If the broker is down at this point, we should design a mechanism to reset
the meta of this topic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]