BewareMyPower commented on a change in pull request #8244:
URL: https://github.com/apache/pulsar/pull/8244#discussion_r506959623
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataTeardown.java
##########
@@ -107,5 +135,77 @@ public static void deleteZkNodeRecursively(ZooKeeper
zooKeeper, String path) thr
}
}
+ private static List<String> getChildren(ZooKeeper zooKeeper, String path) {
+ try {
+ return zooKeeper.getChildren(path, null);
+ } catch (InterruptedException | KeeperException e) {
+ if (e instanceof KeeperException.NoNodeException) {
+ return new ArrayList<>();
+ }
+ log.error("Failed to get children of {}: {}", path, e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static byte[] getData(ZooKeeper zooKeeper, String path) {
+ try {
+ return zooKeeper.getData(path, null, null);
+ } catch (KeeperException | InterruptedException e) {
+ log.error("Failed to get data from {}: {}", path, e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static void deleteLedger(BookKeeper bookKeeper, long ledgerId) {
+ try {
+ bookKeeper.deleteLedger(ledgerId);
+ if (log.isDebugEnabled()) {
+ log.debug("Delete ledger id: {}", ledgerId);
+ }
+ } catch (InterruptedException | BKException e) {
+ log.error("Failed to delete ledger {}: {}", ledgerId, e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static void deleteManagedLedgers(ZooKeeper zooKeeper,
ManagedLedgerFactory managedLedgerFactory) {
+ final String managedLedgersRoot = "/managed-ledgers";
+ getChildren(zooKeeper, managedLedgersRoot).forEach(tenant -> {
+ final String tenantRoot = managedLedgersRoot + "/" + tenant;
+ getChildren(zooKeeper, tenantRoot).forEach(namespace -> {
+ final String namespaceRoot = String.join("/", tenantRoot,
namespace, "persistent");
+ getChildren(zooKeeper, namespaceRoot).forEach(topic -> {
+ final TopicName topicName = TopicName.get(String.join("/",
tenant, namespace, topic));
+ try {
+
managedLedgerFactory.delete(topicName.getPersistenceNamingEncoding());
+ } catch (InterruptedException | ManagedLedgerException e) {
+ log.error("Failed to delete ledgers of {}: {}",
topicName, e);
+ throw new RuntimeException(e);
+ }
+ });
+ });
+ });
+ }
+
+ private static void deleteSchemaLedgers(ZooKeeper zooKeeper, BookKeeper
bookKeeper) {
+ final String schemaLedgersRoot = "/schemas";
Review comment:
Schema's ledgers are managed by `BookkeeperSchemaStorage`, but it's
coupled with `PulsarService` currently because it's a part of `pulsar-broker`,
not an independent module like `managed-ledger`. So it uses `PulsarService`'s
BK client now. The change needs some refactor of schema storage.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]