-
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
Ensure the deletion consistency of topic and schema #14608
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,7 +155,6 @@ | |
import org.apache.pulsar.common.policies.data.TopicPolicies; | ||
import org.apache.pulsar.common.policies.data.TopicType; | ||
import org.apache.pulsar.common.policies.data.stats.TopicStatsImpl; | ||
import org.apache.pulsar.common.protocol.schema.SchemaVersion; | ||
import org.apache.pulsar.common.stats.Metrics; | ||
import org.apache.pulsar.common.util.FieldParser; | ||
import org.apache.pulsar.common.util.FutureUtil; | ||
|
@@ -1013,32 +1012,12 @@ public CompletableFuture<Optional<Topic>> getTopic(final String topic, boolean c | |
} | ||
} | ||
|
||
public CompletableFuture<SchemaVersion> deleteSchemaStorage(String topic) { | ||
Optional<Topic> optTopic = getTopicReference(topic); | ||
if (optTopic.isPresent()) { | ||
return optTopic.get().deleteSchema(); | ||
} else { | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
} | ||
|
||
public CompletableFuture<Void> deleteTopic(String topic, boolean forceDelete) { | ||
return deleteTopic(topic, forceDelete, false); | ||
} | ||
|
||
public CompletableFuture<Void> deleteTopic(String topic, boolean forceDelete, boolean deleteSchema) { | ||
Optional<Topic> optTopic = getTopicReference(topic); | ||
if (optTopic.isPresent()) { | ||
Topic t = optTopic.get(); | ||
if (forceDelete) { | ||
if (deleteSchema) { | ||
return t.deleteSchema().thenCompose(schemaVersion -> { | ||
log.info("Successfully delete topic {}'s schema of version {}", t.getName(), schemaVersion); | ||
return t.deleteForcefully(); | ||
}); | ||
} else { | ||
return t.deleteForcefully(); | ||
} | ||
return t.deleteForcefully(); | ||
} | ||
|
||
// v2 topics have a global name so check if the topic is replicated. | ||
|
@@ -1050,14 +1029,7 @@ public CompletableFuture<Void> deleteTopic(String topic, boolean forceDelete, bo | |
new IllegalStateException("Delete forbidden topic is replicated on clusters " + clusters)); | ||
} | ||
|
||
if (deleteSchema) { | ||
return t.deleteSchema().thenCompose(schemaVersion -> { | ||
log.info("Successfully delete topic {}'s schema of version {}", t.getName(), schemaVersion); | ||
return t.delete(); | ||
}); | ||
Comment on lines
-1054
to
-1057
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. If remove these lines how do we delete the schema? 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. t.delete() will delete schema by default. details: delete() -> delete(boolean,boolean,boolean) -> deleteSchema() |
||
} else { | ||
return t.delete(); | ||
} | ||
return t.delete(); | ||
} | ||
|
||
if (log.isDebugEnabled()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,7 +370,7 @@ public CompletableFuture<Subscription> createSubscription(String subscriptionNam | |
|
||
@Override | ||
public CompletableFuture<Void> delete() { | ||
return delete(false, false, false); | ||
return delete(false, false); | ||
} | ||
|
||
/** | ||
|
@@ -380,11 +380,10 @@ public CompletableFuture<Void> delete() { | |
*/ | ||
@Override | ||
public CompletableFuture<Void> deleteForcefully() { | ||
return delete(false, true, false); | ||
return delete(false, true); | ||
} | ||
|
||
private CompletableFuture<Void> delete(boolean failIfHasSubscriptions, boolean closeIfClientsConnected, | ||
boolean deleteSchema) { | ||
private CompletableFuture<Void> delete(boolean failIfHasSubscriptions, boolean closeIfClientsConnected) { | ||
CompletableFuture<Void> deleteFuture = new CompletableFuture<>(); | ||
|
||
lock.writeLock().lock(); | ||
|
@@ -429,9 +428,8 @@ private CompletableFuture<Void> delete(boolean failIfHasSubscriptions, boolean c | |
} else { | ||
subscriptions.forEach((s, sub) -> futures.add(sub.delete())); | ||
} | ||
if (deleteSchema) { | ||
futures.add(deleteSchema().thenApply(schemaVersion -> null)); | ||
} | ||
|
||
futures.add(deleteSchema().thenApply(schemaVersion -> null)); | ||
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. What happens to topics with multiple versions fo schema? Will all versions be cleaned? 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. Yes, will delete all the versions 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. Hmmm, it's a little confusing for using persistent schema storage for a non-persistent topic, after the broker restart and the producer/consumer will not connect to a non-persistent topic, the non-persistent topic is equivalent to being deleted, In some cases that users using a random name for non-persistent topic, after the application restarts, the topic name will be changes, looks like here will introduce a schema resource leak. |
||
futures.add(deleteTopicPolicies()); | ||
FutureUtil.waitForAll(futures).whenComplete((v, ex) -> { | ||
if (ex != null) { | ||
|
@@ -920,7 +918,7 @@ public void checkGC() { | |
maxInactiveDurationInSec); | ||
} | ||
|
||
stopReplProducers().thenCompose(v -> delete(true, false, true)) | ||
stopReplProducers().thenCompose(v -> delete(true, false)) | ||
.thenCompose(__ -> tryToDeletePartitionedMetadata()) | ||
.thenRun(() -> log.info("[{}] Topic deleted successfully due to inactivity", topic)) | ||
.exceptionally(e -> { | ||
|
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.
If remove these lines, how does the method remove the schema?
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.
internalRemovePartitionsTopicAsync(numPartitions, force) will delete schema by default.