From 1c94e615214f933b4d823c552cec75f358ea0f27 Mon Sep 17 00:00:00 2001 From: vstepanov Date: Fri, 7 Jun 2019 11:32:40 +0200 Subject: [PATCH 1/4] ARUHA-2328: added tmp script for removing locks of deleted subscriptions; --- .../domain/SubscriptionLocksCleaner.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java diff --git a/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java b/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java new file mode 100644 index 0000000000..386dc68002 --- /dev/null +++ b/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java @@ -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 { + + public static void main(String args[]) throws Exception { + ZooKeeper zk = new ZooKeeper("localhost:2181", 30000, event -> { + }); + + final String contextPath = "/staging"; + + final List locks = zk.getChildren(contextPath + "/nakadi/locks", false); + final List subscriptions = 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++) { + System.out.println((i * 100 / (locks.size() - 1)) + "%"); + + 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); + } + +} From 4f90759d2ea25609d85253d4cb2df19d4817abcd Mon Sep 17 00:00:00 2001 From: vstepanov Date: Fri, 7 Jun 2019 11:51:58 +0200 Subject: [PATCH 2/4] ARUHA-2328: improved a lot of problems; --- .../zalando/nakadi/domain/SubscriptionLocksCleaner.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java b/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java index 386dc68002..6ad751910e 100644 --- a/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java +++ b/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java @@ -3,7 +3,9 @@ import org.apache.zookeeper.ZKUtil; import org.apache.zookeeper.ZooKeeper; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class SubscriptionLocksCleaner { @@ -14,13 +16,11 @@ public static void main(String args[]) throws Exception { final String contextPath = "/staging"; final List locks = zk.getChildren(contextPath + "/nakadi/locks", false); - final List subscriptions = zk.getChildren(contextPath + "/nakadi/subscriptions", false); + final Set 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++) { - System.out.println((i * 100 / (locks.size() - 1)) + "%"); - String lockName = locks.get(i); final String subscriptionId = lockName.substring(13); @@ -29,6 +29,7 @@ public static void main(String args[]) throws Exception { 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); } From b1eb8a05bf66df4d5c340e76beb1b8d964a751eb Mon Sep 17 00:00:00 2001 From: vstepanov Date: Fri, 7 Jun 2019 13:24:46 +0200 Subject: [PATCH 3/4] ARUHA-2328: improved one more problem; --- .../org/zalando/nakadi/domain/SubscriptionLocksCleaner.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java b/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java index 6ad751910e..fdca389600 100644 --- a/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java +++ b/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java @@ -16,6 +16,10 @@ public static void main(String args[]) throws Exception { final String contextPath = "/staging"; final List 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 subscriptions = new HashSet<>(zk.getChildren(contextPath + "/nakadi/subscriptions", false)); System.out.println(locks.size() + " locks, " + subscriptions.size() + " subscriptions"); From e082c8999aeb1a9b06aa71b2586e2491147e54ee Mon Sep 17 00:00:00 2001 From: vstepanov Date: Tue, 11 Jun 2019 10:45:54 +0200 Subject: [PATCH 4/4] ARUHA-2328: improved one more problem; --- .../org/zalando/nakadi/domain/SubscriptionLocksCleaner.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java b/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java index fdca389600..0cbf95de1a 100644 --- a/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java +++ b/src/test/java/org/zalando/nakadi/domain/SubscriptionLocksCleaner.java @@ -7,6 +7,11 @@ 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 { public static void main(String args[]) throws Exception {