From f23851e0f76e9b828c4ea0a3ea85c63c3be23fb3 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Fri, 7 Feb 2020 22:45:51 +0530 Subject: [PATCH 1/3] Not doing exist check for node --- pom.xml | 11 ++-- .../ranger/finder/ServiceRegistryUpdater.java | 50 ++++++++++--------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index b6e8989e..c9b3637f 100644 --- a/pom.xml +++ b/pom.xml @@ -7,14 +7,17 @@ com.flipkart.ranger ranger jar - 0.6.1 + 0.6.2-SNAPSHOT - clojars - Clojars repository - https://clojars.org/repo + phonepe-releases + http://artifactory.phonepe.com/content/repositories/releases + + phonepe-snapshots + http://artifactory.phonepe.com/content/repositories/snapshots + diff --git a/src/main/java/com/flipkart/ranger/finder/ServiceRegistryUpdater.java b/src/main/java/com/flipkart/ranger/finder/ServiceRegistryUpdater.java index 046029b5..feb15be5 100644 --- a/src/main/java/com/flipkart/ranger/finder/ServiceRegistryUpdater.java +++ b/src/main/java/com/flipkart/ranger/finder/ServiceRegistryUpdater.java @@ -1,12 +1,12 @@ /** * Copyright 2015 Flipkart Internet Pvt. Ltd. - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,6 +24,7 @@ import com.google.common.collect.Lists; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.api.CuratorWatcher; +import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,7 +53,7 @@ public ServiceRegistryUpdater(ServiceRegistry serviceRegistry, boolean disabl public void start() throws Exception { CuratorFramework curatorFramework = serviceRegistry.getService().getCuratorFramework(); - if(!disableWatchers) { + if (!disableWatchers) { curatorFramework.getChildren() .usingWatcher(new CuratorWatcher() { @Override @@ -88,7 +89,7 @@ public Void call() throws Exception { checkCondition.await(); } updateRegistry(); - checkForUpdate =false; + checkForUpdate = false; } finally { checkLock.unlock(); } @@ -110,7 +111,7 @@ private Optional>> checkForUpdateOnZookeeper() { final long healthcheckZombieCheckThresholdTime = System.currentTimeMillis() - 60000; //1 Minute final Service service = serviceRegistry.getService(); final String serviceName = service.getServiceName(); - if(!service.isRunning()) { + if (!service.isRunning()) { return Optional.empty(); } final Deserializer deserializer = serviceRegistry.getDeserializer(); @@ -120,22 +121,26 @@ private Optional>> checkForUpdateOnZookeeper() { List children = curatorFramework.getChildren().forPath(parentPath); List> nodes = Lists.newArrayListWithCapacity(children.size()); logger.debug("Found {} nodes for [{}]", nodes.size(), serviceName); - for(String child : children) { + for (String child : children) { final String path = String.format("%s/%s", parentPath, child); - boolean hasChild = null != curatorFramework.checkExists().forPath(path); - final byte[] data = hasChild ? curatorFramework.getData().forPath(path) : null; - if(null == data) { - logger.warn("Not data present for node: {} of [{}]", path, serviceName); - continue; - } - ServiceNode key = deserializer.deserialize(data); - if (HealthcheckStatus.healthy == key.getHealthcheckStatus()){ - if (key.getLastUpdatedTimeStamp() > healthcheckZombieCheckThresholdTime){ - nodes.add(key); + try { + final byte[] data = curatorFramework.getData().forPath(path); + if (null == data) { + logger.warn("Data not present for node: {} of [{}]", path, serviceName); + continue; } - else { - logger.warn("Zombie node [{}:{}] found for [{}]", key.getHost(), key.getPort(), serviceName); + ServiceNode key = deserializer.deserialize(data); + if (HealthcheckStatus.healthy == key.getHealthcheckStatus()) { + if (key.getLastUpdatedTimeStamp() > healthcheckZombieCheckThresholdTime) { + nodes.add(key); + } else { + logger.warn("Zombie node [{}:{}] found for [{}]", key.getHost(), key.getPort(), serviceName); + } } + } catch (KeeperException.NoNodeException e) { + logger.warn("Node not found for path {}", path); + } catch (Exception e) { + logger.error(String.format("Data fetch failed for path %s", path), e); } } return Optional.of(nodes); @@ -152,14 +157,13 @@ public void stop() { private void updateRegistry() { List> nodes = checkForUpdateOnZookeeper().orElse(null); - if(null != nodes) { + if (null != nodes) { logger.debug("Updating nodelist of size: {} for [{}]", nodes.size(), serviceRegistry.getService().getServiceName()); serviceRegistry.nodes(nodes); - } - else { + } else { logger.warn("No service shards/nodes found. We are disconnected from zookeeper. Keeping old list for {}", - serviceRegistry.getService().getServiceName()); + serviceRegistry.getService().getServiceName()); } } From fd9396654d05d7a01a6190fd5b900e23fe298129 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Sat, 8 Feb 2020 17:49:43 +0530 Subject: [PATCH 2/3] Not doing exist check for node --- pom.xml | 9 ++---- .../ranger/finder/ServiceRegistryUpdater.java | 28 +++++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index c9b3637f..c8216f1c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,13 +11,10 @@ - phonepe-releases - http://artifactory.phonepe.com/content/repositories/releases + clojars + Clojars repository + https://clojars.org/repo - - phonepe-snapshots - http://artifactory.phonepe.com/content/repositories/snapshots - diff --git a/src/main/java/com/flipkart/ranger/finder/ServiceRegistryUpdater.java b/src/main/java/com/flipkart/ranger/finder/ServiceRegistryUpdater.java index feb15be5..7c9e259b 100644 --- a/src/main/java/com/flipkart/ranger/finder/ServiceRegistryUpdater.java +++ b/src/main/java/com/flipkart/ranger/finder/ServiceRegistryUpdater.java @@ -1,12 +1,12 @@ /** * Copyright 2015 Flipkart Internet Pvt. Ltd. - *

+ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

+ * * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -53,7 +53,7 @@ public ServiceRegistryUpdater(ServiceRegistry serviceRegistry, boolean disabl public void start() throws Exception { CuratorFramework curatorFramework = serviceRegistry.getService().getCuratorFramework(); - if (!disableWatchers) { + if(!disableWatchers) { curatorFramework.getChildren() .usingWatcher(new CuratorWatcher() { @Override @@ -89,7 +89,7 @@ public Void call() throws Exception { checkCondition.await(); } updateRegistry(); - checkForUpdate = false; + checkForUpdate =false; } finally { checkLock.unlock(); } @@ -111,7 +111,7 @@ private Optional>> checkForUpdateOnZookeeper() { final long healthcheckZombieCheckThresholdTime = System.currentTimeMillis() - 60000; //1 Minute final Service service = serviceRegistry.getService(); final String serviceName = service.getServiceName(); - if (!service.isRunning()) { + if(!service.isRunning()) { return Optional.empty(); } final Deserializer deserializer = serviceRegistry.getDeserializer(); @@ -121,7 +121,7 @@ private Optional>> checkForUpdateOnZookeeper() { List children = curatorFramework.getChildren().forPath(parentPath); List> nodes = Lists.newArrayListWithCapacity(children.size()); logger.debug("Found {} nodes for [{}]", nodes.size(), serviceName); - for (String child : children) { + for(String child : children) { final String path = String.format("%s/%s", parentPath, child); try { final byte[] data = curatorFramework.getData().forPath(path); @@ -133,13 +133,16 @@ private Optional>> checkForUpdateOnZookeeper() { if (HealthcheckStatus.healthy == key.getHealthcheckStatus()) { if (key.getLastUpdatedTimeStamp() > healthcheckZombieCheckThresholdTime) { nodes.add(key); - } else { + } + else { logger.warn("Zombie node [{}:{}] found for [{}]", key.getHost(), key.getPort(), serviceName); } } - } catch (KeeperException.NoNodeException e) { + } + catch (KeeperException.NoNodeException e) { logger.warn("Node not found for path {}", path); - } catch (Exception e) { + } + catch (Exception e) { logger.error(String.format("Data fetch failed for path %s", path), e); } } @@ -157,11 +160,12 @@ public void stop() { private void updateRegistry() { List> nodes = checkForUpdateOnZookeeper().orElse(null); - if (null != nodes) { + if(null != nodes) { logger.debug("Updating nodelist of size: {} for [{}]", nodes.size(), serviceRegistry.getService().getServiceName()); serviceRegistry.nodes(nodes); - } else { + } + else { logger.warn("No service shards/nodes found. We are disconnected from zookeeper. Keeping old list for {}", serviceRegistry.getService().getServiceName()); } From 91d3068eef7984c8101727e41e8f5fe756319d48 Mon Sep 17 00:00:00 2001 From: Santanu Sinha Date: Mon, 10 Feb 2020 19:16:15 +0530 Subject: [PATCH 3/3] Release version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 760a4b4b..474c07f8 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.flipkart.ranger ranger jar - 0.6.3-SNAPSHOT + 0.6.3