You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2021/05/11 21:24:45 UTC

[accumulo] branch main updated: Remove unused ZK status thread from monitor (#2095)

This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new be861e6  Remove unused ZK status thread from monitor (#2095)
be861e6 is described below

commit be861e6d49dc7c24336ea4d787bf60e5a8557afe
Author: EdColeman <de...@etcoleman.com>
AuthorDate: Tue May 11 17:24:36 2021 -0400

    Remove unused ZK status thread from monitor (#2095)
    
    PR #2020 removed ZooKeeper status from the monitor, but the thread
    polling status was still running. This completes that removal.
---
 server/monitor/pom.xml                             |   4 -
 .../java/org/apache/accumulo/monitor/Monitor.java  |   2 -
 .../apache/accumulo/monitor/ZooKeeperStatus.java   | 157 ---------------------
 .../accumulo/monitor/ZooKeeperStatusTest.java      |  60 --------
 4 files changed, 223 deletions(-)

diff --git a/server/monitor/pom.xml b/server/monitor/pom.xml
index 499852a..b367c8e 100644
--- a/server/monitor/pom.xml
+++ b/server/monitor/pom.xml
@@ -97,10 +97,6 @@
       <artifactId>log4j-web</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.thrift</groupId>
-      <artifactId>libthrift</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.apache.zookeeper</groupId>
       <artifactId>zookeeper</artifactId>
     </dependency>
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
index 5a62e0e..378923f 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
@@ -461,8 +461,6 @@ public class Monitor extends AbstractServer implements HighlyAvailableService {
       log.error("Unable to advertise monitor HTTP address in zookeeper", ex);
     }
 
-    Threads.createThread("ZooKeeperStatus", new ZooKeeperStatus(context)).start();
-
     // need to regularly fetch data so plot data is updated
     Threads.createThread("Data fetcher", () -> {
       while (true) {
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/ZooKeeperStatus.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/ZooKeeperStatus.java
deleted file mode 100644
index b5d93df..0000000
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/ZooKeeperStatus.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.accumulo.monitor;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly;
-
-import java.util.Collection;
-import java.util.Objects;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.accumulo.core.conf.Property;
-import org.apache.accumulo.core.rpc.TTimeoutTransport;
-import org.apache.accumulo.core.util.HostAndPort;
-import org.apache.accumulo.server.ServerContext;
-import org.apache.thrift.transport.TTransport;
-import org.apache.thrift.transport.TTransportException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ZooKeeperStatus implements Runnable {
-
-  private static final Logger log = LoggerFactory.getLogger(ZooKeeperStatus.class);
-
-  private ServerContext context;
-  private volatile boolean stop = false;
-
-  public ZooKeeperStatus(ServerContext context) {
-    this.context = context;
-  }
-
-  public static class ZooKeeperState implements Comparable<ZooKeeperState> {
-    public final String keeper;
-    public final String mode;
-    public final int clients;
-
-    public ZooKeeperState(String keeper, String mode, int clients) {
-      this.keeper = keeper;
-      this.mode = mode;
-      this.clients = clients;
-    }
-
-    @Override
-    public int hashCode() {
-      return Objects.hashCode(keeper);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-      return obj == this
-          || (obj != null && obj instanceof ZooKeeperState && compareTo((ZooKeeperState) obj) == 0);
-    }
-
-    @Override
-    public int compareTo(ZooKeeperState other) {
-      if (this == other) {
-        return 0;
-      } else if (other == null) {
-        return 1;
-      } else {
-        if (this.keeper == other.keeper) {
-          return 0;
-        } else if (this.keeper == null) {
-          return -1;
-        } else if (other.keeper == null) {
-          return 1;
-        } else {
-          return this.keeper.compareTo(other.keeper);
-        }
-      }
-    }
-  }
-
-  private static SortedSet<ZooKeeperState> status = new TreeSet<>();
-
-  public static Collection<ZooKeeperState> getZooKeeperStatus() {
-    return status;
-  }
-
-  @Override
-  public void run() {
-
-    while (!stop) {
-
-      TreeSet<ZooKeeperState> update = new TreeSet<>();
-
-      String[] zookeepers = context.getConfiguration().get(Property.INSTANCE_ZK_HOST).split(",");
-      for (String keeper : zookeepers) {
-        int clients = 0;
-        String mode = "unknown";
-
-        String[] parts = keeper.split(":");
-        TTransport transport = null;
-        try {
-          HostAndPort addr;
-          if (parts.length > 1)
-            addr = HostAndPort.fromParts(parts[0], Integer.parseInt(parts[1]));
-          else
-            addr = HostAndPort.fromParts(parts[0], 2181);
-
-          transport = TTimeoutTransport.create(addr, 10 * 1000L);
-          transport.write("stat\n".getBytes(UTF_8), 0, 5);
-          StringBuilder response = new StringBuilder();
-          try {
-            transport.flush();
-            byte[] buffer = new byte[1024 * 100];
-            int n = 0;
-            while ((n = transport.read(buffer, 0, buffer.length)) > 0) {
-              response.append(new String(buffer, 0, n, UTF_8));
-            }
-          } catch (TTransportException ex) {
-            // happens at EOF
-          }
-          for (String line : response.toString().split("\n")) {
-            if (line.startsWith(" "))
-              clients++;
-            if (line.startsWith("Mode"))
-              mode = line.split(":")[1];
-          }
-          update.add(new ZooKeeperState(keeper, mode, clients));
-        } catch (Exception ex) {
-          log.info("Exception talking to zookeeper " + keeper, ex);
-          update.add(new ZooKeeperState(keeper, "Down", -1));
-        } finally {
-          if (transport != null) {
-            try {
-              transport.close();
-            } catch (Exception ex) {
-              log.error("Exception", ex);
-            }
-          }
-        }
-      }
-      status = update;
-      sleepUninterruptibly(5, TimeUnit.SECONDS);
-    }
-  }
-
-}
diff --git a/server/monitor/src/test/java/org/apache/accumulo/monitor/ZooKeeperStatusTest.java b/server/monitor/src/test/java/org/apache/accumulo/monitor/ZooKeeperStatusTest.java
deleted file mode 100644
index c636900..0000000
--- a/server/monitor/src/test/java/org/apache/accumulo/monitor/ZooKeeperStatusTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.accumulo.monitor;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.TreeSet;
-
-import org.apache.accumulo.monitor.ZooKeeperStatus.ZooKeeperState;
-import org.junit.Test;
-
-public class ZooKeeperStatusTest {
-
-  @Test
-  public void zkHostSortingTest() {
-    List<String> expectedHosts =
-        Arrays.asList("rack1node1", "rack2node1", "rack4node1", "rack4node4");
-
-    // Add the states in a not correctly sorted order
-    TreeSet<ZooKeeperState> states = new TreeSet<>();
-    states.add(new ZooKeeperState("rack4node4", "leader", 10));
-    states.add(new ZooKeeperState("rack4node1", "follower", 10));
-    states.add(new ZooKeeperState("rack1node1", "follower", 10));
-    states.add(new ZooKeeperState("rack2node1", "follower", 10));
-
-    List<String> actualHosts = new ArrayList<>(4);
-    for (ZooKeeperState state : states) {
-      actualHosts.add(state.keeper);
-    }
-
-    // Assert we have 4 of each
-    assertEquals(expectedHosts.size(), actualHosts.size());
-
-    // Assert the ordering is correct
-    for (int i = 0; i < expectedHosts.size(); i++) {
-      assertEquals(expectedHosts.get(i), actualHosts.get(i));
-    }
-
-  }
-
-}