You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2021/11/16 20:57:03 UTC

[GitHub] [accumulo] DomGarguilo commented on a change in pull request #2358: Create page in Monitor for external compactions

DomGarguilo commented on a change in pull request #2358:
URL: https://github.com/apache/accumulo/pull/2358#discussion_r750634825



##########
File path: test/src/main/java/org/apache/accumulo/test/compaction/ExternalCompactionProgressIT.java
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.test.compaction;
+
+import static org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.accumulo.compactor.Compactor;
+import org.apache.accumulo.coordinator.CompactionCoordinator;
+import org.apache.accumulo.core.client.Accumulo;
+import org.apache.accumulo.core.client.AccumuloClient;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.compaction.thrift.TCompactionState;
+import org.apache.accumulo.core.iterators.IteratorUtil;
+import org.apache.accumulo.core.util.threads.Threads;
+import org.apache.accumulo.harness.AccumuloClusterHarness;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
+import org.apache.accumulo.monitor.rest.compactions.external.RunningCompactorInfo;
+import org.apache.accumulo.test.functional.SlowIterator;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.thrift.TException;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests that external compactions report progress from start to finish. To prevent flaky test
+ * failures, we only measure progress in quarter segments: STARTED, QUARTER, HALF, THREE_QUARTERS.
+ * We can detect if the compaction finished without errors but the coordinator will never report
+ * 100% progress since it will remove the ECID upon completion. The {@link SlowIterator} is used to
+ * control the length of time it takes to complete the compaction.
+ */
+public class ExternalCompactionProgressIT extends AccumuloClusterHarness {
+  private static final Logger log = LoggerFactory.getLogger(ExternalCompactionProgressIT.class);
+  private static final int ROWS = 10_000;
+
+  enum EC_PROGRESS {
+    STARTED, QUARTER, HALF, THREE_QUARTERS
+  }
+
+  Map<String,RunningCompactorInfo> runningMap = new HashMap<>();
+  List<EC_PROGRESS> progressList = new ArrayList<>();
+
+  private final AtomicBoolean compactionFinished = new AtomicBoolean(false);
+
+  @Override
+  public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration coreSite) {
+    ExternalCompactionTestUtils.configureMiniCluster(cfg, coreSite);
+  }
+
+  @Test
+  public void testProgress() throws Exception {
+    MiniAccumuloClusterImpl.ProcessInfo c1 = null, coord = null;
+    String table1 = this.getUniqueNames(1)[0];
+    try (AccumuloClient client =
+        Accumulo.newClient().from(getCluster().getClientProperties()).build()) {
+      ExternalCompactionTestUtils.createTable(client, table1, "cs1");
+      ExternalCompactionTestUtils.writeData(client, table1, ROWS);
+      c1 = ((MiniAccumuloClusterImpl) getCluster()).exec(Compactor.class, "-q", "DCQ1");
+      coord = ExternalCompactionTestUtils.startCoordinator(((MiniAccumuloClusterImpl) getCluster()),
+          CompactionCoordinator.class, getCluster().getServerContext());
+
+      Thread checkerThread = startChecker();
+      checkerThread.start();
+
+      IteratorSetting setting = new IteratorSetting(50, "Slow", SlowIterator.class);
+      SlowIterator.setSleepTime(setting, 1);
+      client.tableOperations().attachIterator(table1, setting,
+          EnumSet.of(IteratorUtil.IteratorScope.majc));
+      log.info("Compacting table");
+      ExternalCompactionTestUtils.compact(client, table1, 2, "DCQ1", true);
+      ExternalCompactionTestUtils.verify(client, table1, 2, ROWS);
+
+      log.info("Done Compacting table");
+      compactionFinished.set(true);
+      checkerThread.join();
+
+      verifyProgress();
+    } finally {
+      ExternalCompactionTestUtils.stopProcesses(c1, coord);
+    }
+  }
+
+  public Thread startChecker() {
+    return Threads.createThread("RC checker", () -> {
+      try {
+        while (!compactionFinished.get()) {
+          checkRunning();
+          sleepUninterruptibly(1000, TimeUnit.MILLISECONDS);
+        }
+      } catch (TException e) {
+        log.warn("{}", e.getMessage(), e);
+      }
+    });
+  }
+
+  /**
+   * Check running compaction progress.
+   */
+  private void checkRunning() throws TException {
+    var ecList = ExternalCompactionTestUtils.getRunningCompactions(getCluster().getServerContext());
+    var ecMap = ecList.getCompactions();
+    if (ecMap != null) {
+      ecMap.forEach((ecid, ec) -> {
+        // returns null if it's a new mapping
+        var rci = new RunningCompactorInfo(System.currentTimeMillis(), ecid, ec);
+        var previous = runningMap.put(ecid, rci);

Review comment:
       This could potentially return null if the previously assigned value was null, meaning its not a new mapping. Not sure if that would ever happen though.

##########
File path: server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
##########
@@ -163,6 +169,12 @@ public boolean add(Pair<Long,T> obj) {
   private Map<TableId,Map<ProblemType,Integer>> problemSummary = Collections.emptyMap();
   private Exception problemException;
   private GCStatus gcStatus;
+  private Optional<HostAndPort> coordinatorHost = Optional.empty();
+  private CompactionCoordinatorService.Client coordinatorClient;
+  private final String coordinatorMissingMsg =
+      "Error getting the compaction coordinator. Check that it is running. It is not "
+          + "started automatically with other cluster processes so must be started by running"
+          + "'accumulo compaction-coordinator`.";

Review comment:
       ```suggestion
         "Error getting the compaction coordinator. Check that it is running. It is not "
             + "started automatically with other cluster processes so must be started by running "
             + "'accumulo compaction-coordinator'.";
   ```

##########
File path: test/src/main/java/org/apache/accumulo/test/compaction/ExternalCompactionProgressIT.java
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.test.compaction;
+
+import static org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.accumulo.compactor.Compactor;
+import org.apache.accumulo.coordinator.CompactionCoordinator;
+import org.apache.accumulo.core.client.Accumulo;
+import org.apache.accumulo.core.client.AccumuloClient;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.compaction.thrift.TCompactionState;
+import org.apache.accumulo.core.iterators.IteratorUtil;
+import org.apache.accumulo.core.util.threads.Threads;
+import org.apache.accumulo.harness.AccumuloClusterHarness;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
+import org.apache.accumulo.monitor.rest.compactions.external.RunningCompactorInfo;
+import org.apache.accumulo.test.functional.SlowIterator;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.thrift.TException;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests that external compactions report progress from start to finish. To prevent flaky test
+ * failures, we only measure progress in quarter segments: STARTED, QUARTER, HALF, THREE_QUARTERS.
+ * We can detect if the compaction finished without errors but the coordinator will never report
+ * 100% progress since it will remove the ECID upon completion. The {@link SlowIterator} is used to
+ * control the length of time it takes to complete the compaction.
+ */
+public class ExternalCompactionProgressIT extends AccumuloClusterHarness {
+  private static final Logger log = LoggerFactory.getLogger(ExternalCompactionProgressIT.class);
+  private static final int ROWS = 10_000;
+
+  enum EC_PROGRESS {
+    STARTED, QUARTER, HALF, THREE_QUARTERS
+  }
+
+  Map<String,RunningCompactorInfo> runningMap = new HashMap<>();
+  List<EC_PROGRESS> progressList = new ArrayList<>();
+
+  private final AtomicBoolean compactionFinished = new AtomicBoolean(false);
+
+  @Override
+  public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration coreSite) {
+    ExternalCompactionTestUtils.configureMiniCluster(cfg, coreSite);
+  }
+
+  @Test
+  public void testProgress() throws Exception {
+    MiniAccumuloClusterImpl.ProcessInfo c1 = null, coord = null;
+    String table1 = this.getUniqueNames(1)[0];
+    try (AccumuloClient client =
+        Accumulo.newClient().from(getCluster().getClientProperties()).build()) {
+      ExternalCompactionTestUtils.createTable(client, table1, "cs1");
+      ExternalCompactionTestUtils.writeData(client, table1, ROWS);
+      c1 = ((MiniAccumuloClusterImpl) getCluster()).exec(Compactor.class, "-q", "DCQ1");
+      coord = ExternalCompactionTestUtils.startCoordinator(((MiniAccumuloClusterImpl) getCluster()),
+          CompactionCoordinator.class, getCluster().getServerContext());
+
+      Thread checkerThread = startChecker();
+      checkerThread.start();
+
+      IteratorSetting setting = new IteratorSetting(50, "Slow", SlowIterator.class);
+      SlowIterator.setSleepTime(setting, 1);
+      client.tableOperations().attachIterator(table1, setting,
+          EnumSet.of(IteratorUtil.IteratorScope.majc));
+      log.info("Compacting table");
+      ExternalCompactionTestUtils.compact(client, table1, 2, "DCQ1", true);
+      ExternalCompactionTestUtils.verify(client, table1, 2, ROWS);
+
+      log.info("Done Compacting table");
+      compactionFinished.set(true);
+      checkerThread.join();
+
+      verifyProgress();
+    } finally {
+      ExternalCompactionTestUtils.stopProcesses(c1, coord);
+    }
+  }
+
+  public Thread startChecker() {
+    return Threads.createThread("RC checker", () -> {
+      try {
+        while (!compactionFinished.get()) {
+          checkRunning();
+          sleepUninterruptibly(1000, TimeUnit.MILLISECONDS);
+        }
+      } catch (TException e) {
+        log.warn("{}", e.getMessage(), e);
+      }
+    });
+  }
+
+  /**
+   * Check running compaction progress.
+   */
+  private void checkRunning() throws TException {
+    var ecList = ExternalCompactionTestUtils.getRunningCompactions(getCluster().getServerContext());
+    var ecMap = ecList.getCompactions();
+    if (ecMap != null) {
+      ecMap.forEach((ecid, ec) -> {
+        // returns null if it's a new mapping
+        var rci = new RunningCompactorInfo(System.currentTimeMillis(), ecid, ec);
+        var previous = runningMap.put(ecid, rci);
+        if (previous == null) {
+          log.debug("New ECID {} with inputFiles: {}", ecid, rci.inputFiles);
+        } else {
+          log.debug("{} progressed from {} to {}", ecid, previous.progress, rci.progress);
+          if (rci.progress <= previous.progress) {
+            log.warn("Compaction did not progress. It went from {} to {}", previous.progress,
+                rci.progress);
+          } else {
+            if (rci.progress > 0 && rci.progress < 25)
+              progressList.add(EC_PROGRESS.STARTED);
+            else if (rci.progress > 25 && rci.progress < 50)
+              progressList.add(EC_PROGRESS.QUARTER);
+            else if (rci.progress > 50 && rci.progress < 75)
+              progressList.add(EC_PROGRESS.HALF);
+            else if (rci.progress > 75 && rci.progress < 100)
+              progressList.add(EC_PROGRESS.THREE_QUARTERS);

Review comment:
       what if progress is 0, 25, 50, 75 or 100?

##########
File path: test/src/main/java/org/apache/accumulo/test/compaction/ExternalCompactionProgressIT.java
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.test.compaction;
+
+import static org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.accumulo.compactor.Compactor;
+import org.apache.accumulo.coordinator.CompactionCoordinator;
+import org.apache.accumulo.core.client.Accumulo;
+import org.apache.accumulo.core.client.AccumuloClient;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.compaction.thrift.TCompactionState;
+import org.apache.accumulo.core.iterators.IteratorUtil;
+import org.apache.accumulo.core.util.threads.Threads;
+import org.apache.accumulo.harness.AccumuloClusterHarness;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
+import org.apache.accumulo.monitor.rest.compactions.external.RunningCompactorInfo;
+import org.apache.accumulo.test.functional.SlowIterator;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.thrift.TException;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests that external compactions report progress from start to finish. To prevent flaky test
+ * failures, we only measure progress in quarter segments: STARTED, QUARTER, HALF, THREE_QUARTERS.
+ * We can detect if the compaction finished without errors but the coordinator will never report
+ * 100% progress since it will remove the ECID upon completion. The {@link SlowIterator} is used to
+ * control the length of time it takes to complete the compaction.
+ */
+public class ExternalCompactionProgressIT extends AccumuloClusterHarness {
+  private static final Logger log = LoggerFactory.getLogger(ExternalCompactionProgressIT.class);
+  private static final int ROWS = 10_000;
+
+  enum EC_PROGRESS {
+    STARTED, QUARTER, HALF, THREE_QUARTERS
+  }
+
+  Map<String,RunningCompactorInfo> runningMap = new HashMap<>();
+  List<EC_PROGRESS> progressList = new ArrayList<>();
+
+  private final AtomicBoolean compactionFinished = new AtomicBoolean(false);
+
+  @Override
+  public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration coreSite) {
+    ExternalCompactionTestUtils.configureMiniCluster(cfg, coreSite);
+  }
+
+  @Test
+  public void testProgress() throws Exception {
+    MiniAccumuloClusterImpl.ProcessInfo c1 = null, coord = null;
+    String table1 = this.getUniqueNames(1)[0];
+    try (AccumuloClient client =
+        Accumulo.newClient().from(getCluster().getClientProperties()).build()) {
+      ExternalCompactionTestUtils.createTable(client, table1, "cs1");
+      ExternalCompactionTestUtils.writeData(client, table1, ROWS);
+      c1 = ((MiniAccumuloClusterImpl) getCluster()).exec(Compactor.class, "-q", "DCQ1");
+      coord = ExternalCompactionTestUtils.startCoordinator(((MiniAccumuloClusterImpl) getCluster()),
+          CompactionCoordinator.class, getCluster().getServerContext());
+
+      Thread checkerThread = startChecker();
+      checkerThread.start();
+
+      IteratorSetting setting = new IteratorSetting(50, "Slow", SlowIterator.class);
+      SlowIterator.setSleepTime(setting, 1);
+      client.tableOperations().attachIterator(table1, setting,
+          EnumSet.of(IteratorUtil.IteratorScope.majc));
+      log.info("Compacting table");
+      ExternalCompactionTestUtils.compact(client, table1, 2, "DCQ1", true);
+      ExternalCompactionTestUtils.verify(client, table1, 2, ROWS);
+
+      log.info("Done Compacting table");
+      compactionFinished.set(true);
+      checkerThread.join();
+
+      verifyProgress();
+    } finally {
+      ExternalCompactionTestUtils.stopProcesses(c1, coord);
+    }
+  }
+
+  public Thread startChecker() {
+    return Threads.createThread("RC checker", () -> {
+      try {
+        while (!compactionFinished.get()) {
+          checkRunning();
+          sleepUninterruptibly(1000, TimeUnit.MILLISECONDS);
+        }
+      } catch (TException e) {
+        log.warn("{}", e.getMessage(), e);
+      }
+    });
+  }
+
+  /**
+   * Check running compaction progress.
+   */
+  private void checkRunning() throws TException {
+    var ecList = ExternalCompactionTestUtils.getRunningCompactions(getCluster().getServerContext());
+    var ecMap = ecList.getCompactions();
+    if (ecMap != null) {
+      ecMap.forEach((ecid, ec) -> {
+        // returns null if it's a new mapping
+        var rci = new RunningCompactorInfo(System.currentTimeMillis(), ecid, ec);
+        var previous = runningMap.put(ecid, rci);
+        if (previous == null) {
+          log.debug("New ECID {} with inputFiles: {}", ecid, rci.inputFiles);
+        } else {
+          log.debug("{} progressed from {} to {}", ecid, previous.progress, rci.progress);
+          if (rci.progress <= previous.progress) {
+            log.warn("Compaction did not progress. It went from {} to {}", previous.progress,
+                rci.progress);
+          } else {

Review comment:
       ```suggestion
             if (rci.progress <= previous.progress) {
               log.warn("{} did not progress. It went from {} to {}", ecid, previous.progress,
                   rci.progress);
             } else {
             log.debug("{} progressed from {} to {}", ecid, previous.progress, rci.progress);
   ```
   The log could be moved here to avoid redundant logging. It also could be helpful to include the ecid in the log.warn message.

##########
File path: test/src/main/java/org/apache/accumulo/test/compaction/ExternalCompactionTestUtils.java
##########
@@ -158,8 +160,19 @@ public static void writeData(AccumuloClient client, String table1)
     client.tableOperations().flush(table1);
   }
 
+  public static void writeData(AccumuloClient client, String table1)
+      throws MutationsRejectedException, TableNotFoundException, AccumuloException,

Review comment:
       ```suggestion
         throws TableNotFoundException, AccumuloException,
   ```
   Looks like this is covered under AccumuloException

##########
File path: server/monitor/src/main/java/org/apache/accumulo/monitor/rest/compactions/external/CoordinatorInfo.java
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.rest.compactions.external;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.accumulo.core.util.HostAndPort;
+
+public class CoordinatorInfo {
+  public long lastContact;
+  public String server;
+  public int numQueues;
+  public int numCompactors;

Review comment:
       If applicable, could add this comment for consistency.
   ```suggestion
   public class CoordinatorInfo {
   
     // Variable names become JSON keys
     public long lastContact;
     public String server;
     public int numQueues;
     public int numCompactors;
   ```

##########
File path: test/src/main/java/org/apache/accumulo/test/compaction/ExternalCompactionTestUtils.java
##########
@@ -144,11 +146,11 @@ public static void createTable(AccumuloClient client, String tableName, String s
 
   }
 
-  public static void writeData(AccumuloClient client, String table1)
+  public static void writeData(AccumuloClient client, String table1, int rows)
       throws MutationsRejectedException, TableNotFoundException, AccumuloException,

Review comment:
       ```suggestion
         throws TableNotFoundException, AccumuloException,
   ```
   Looks like this is covered under AccumuloException




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org