From 9db8263761b5a56825b6c5ee5cdd8c87fdb5b9b6 Mon Sep 17 00:00:00 2001 From: liujunhong Date: Wed, 28 Dec 2016 15:34:25 +0800 Subject: [PATCH] fix for HBASE-17374 Signed-off-by: liujunhong --- .../hbase/security/access/ZKPermissionWatcher.java | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ZKPermissionWatcher.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ZKPermissionWatcher.java index d1871ea..6b3ea0d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ZKPermissionWatcher.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ZKPermissionWatcher.java @@ -38,6 +38,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.atomic.AtomicReference; /** @@ -120,7 +121,7 @@ public class ZKPermissionWatcher extends ZooKeeperListener implements Closeable public void nodeCreated(String path) { waitUntilStarted(); if (path.equals(aclZNode)) { - executor.submit(new Runnable() { + asyncProcessNodeUpdate(new Runnable() { @Override public void run() { try { @@ -141,7 +142,7 @@ public class ZKPermissionWatcher extends ZooKeeperListener implements Closeable public void nodeDeleted(final String path) { waitUntilStarted(); if (aclZNode.equals(ZKUtil.getParent(path))) { - executor.submit(new Runnable() { + asyncProcessNodeUpdate(new Runnable() { @Override public void run() { String table = ZKUtil.getNodeName(path); @@ -159,7 +160,7 @@ public class ZKPermissionWatcher extends ZooKeeperListener implements Closeable public void nodeDataChanged(final String path) { waitUntilStarted(); if (aclZNode.equals(ZKUtil.getParent(path))) { - executor.submit(new Runnable() { + asyncProcessNodeUpdate(new Runnable() { @Override public void run() { // update cache on an existing table node @@ -198,7 +199,7 @@ public class ZKPermissionWatcher extends ZooKeeperListener implements Closeable LOG.error("Error reading data from zookeeper for path "+path, ke); watcher.abort("Zookeeper error get node children for path "+path, ke); } - executor.submit(new Runnable() { + asyncProcessNodeUpdate(new Runnable() { // allows subsequent nodeChildrenChanged event to preempt current processing of // nodeChildrenChanged event @Override @@ -211,6 +212,20 @@ public class ZKPermissionWatcher extends ZooKeeperListener implements Closeable } } + private void asyncProcessNodeUpdate(Runnable runnable) { + if (!executor.isShutdown()) { + try { + executor.submit(runnable); + } catch (RejectedExecutionException e) { + if (executor.isShutdown()) { + LOG.warn("aclZNode changed after ZKPermissionWatcher was shutdown"); + } else { + throw e; + } + } + } + } + private void refreshNodes(List nodes, AtomicReference ref) { for (ZKUtil.NodeAndData n : nodes) { if (ref != null && ref.get() != null) { -- 2.9.3 (Apple Git-75)