Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

ARUHA-2328: added tmp script for removing locks of deleted subscriptions; #1057

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.zalando.nakadi.domain;

import org.apache.zookeeper.ZKUtil;
import org.apache.zookeeper.ZooKeeper;

import java.util.List;

public class SubscriptionLocksCleaner {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document additional VM arguments that should be used to run this thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


public static void main(String args[]) throws Exception {
ZooKeeper zk = new ZooKeeper("localhost:2181", 30000, event -> {
});

final String contextPath = "/staging";

final List<String> locks = zk.getChildren(contextPath + "/nakadi/locks", false);
final List<String> subscriptions = zk.getChildren(contextPath + "/nakadi/subscriptions", false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10000 subscriptions, 100000 locks. It makes sense to use HashSet for subscriptions

System.out.println(locks.size() + " locks, " + subscriptions.size() + " subscriptions");

int notExists = 0;
for (int i = 0; i < locks.size(); i++) {
System.out.println((i * 100 / (locks.size() - 1)) + "%");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Division by zero

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it reports 100 before executing action


String lockName = locks.get(i);
final String subscriptionId = lockName.substring(13);

if (!subscriptions.contains(subscriptionId)) {
ZKUtil.deleteRecursive(zk, contextPath + "/nakadi/locks/" + lockName);
System.out.println("Removed lock for " + subscriptionId + " as it doesn't exist");
notExists++;
}
}
System.out.println("Exist: " + (locks.size() - notExists) + ", Removed: " + notExists);
}

}