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 all commits
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,46 @@
package org.zalando.nakadi.domain;

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

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* If the amount of children in /nakadi/locks is so high that it can't be fetched by zookeeper client - then
* this class should be run with VM parameter -Djute.maxbuffer=BUFFER_SIZE_BYTES where BUFFER_SIZE_BYTES should
* be the value that will fit the list of nodes, for example 41943040 (40 MB)
*/
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);

System.out.println(locks.size() + "Waiting 70 seconds before fetching list of subscriptions...");
Thread.sleep(70000); // we need to wait here to avoid deletion of locks for just started subscriptions

final Set<String> subscriptions = new HashSet<>(zk.getChildren(contextPath + "/nakadi/subscriptions", false));
System.out.println(locks.size() + " locks, " + subscriptions.size() + " subscriptions");

int notExists = 0;
for (int i = 0; i < locks.size(); i++) {
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(((i + 1) * 100 / locks.size()) + "%");
}
System.out.println("Exist: " + (locks.size() - notExists) + ", Removed: " + notExists);
}

}