You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by dl...@apache.org on 2021/04/14 15:36:49 UTC

[accumulo] branch 1451-external-compactions-feature updated: Added test for compaction that occurs while TServer is down.

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

dlmarion pushed a commit to branch 1451-external-compactions-feature
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/1451-external-compactions-feature by this push:
     new f8caf7a  Added test for compaction that occurs while TServer is down.
f8caf7a is described below

commit f8caf7a88832e49aa78088c33e908b14d3e0ed16
Author: Dave Marion <dl...@apache.org>
AuthorDate: Wed Apr 14 15:36:15 2021 +0000

    Added test for compaction that occurs while TServer is down.
---
 .../miniclusterImpl/MiniAccumuloClusterImpl.java   |   2 +-
 .../org/apache/accumulo/tserver/TabletServer.java  |   9 +-
 .../accumulo/tserver/ThriftClientHandler.java      |   4 +-
 .../apache/accumulo/test/ExternalCompactionIT.java | 123 +++++++++++++++++++--
 .../accumulo/test/ExternalCompactionTServer.java   |  44 ++++++++
 ...ttingExternalCompactionThriftClientHandler.java |  50 +++++++++
 6 files changed, 220 insertions(+), 12 deletions(-)

diff --git a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
index 61dbd5a..7c6f0f2 100644
--- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
+++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
@@ -751,7 +751,7 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
     return executor;
   }
 
-  int stopProcessWithTimeout(final Process proc, long timeout, TimeUnit unit)
+  public int stopProcessWithTimeout(final Process proc, long timeout, TimeUnit unit)
       throws InterruptedException, ExecutionException, TimeoutException {
     FutureTask<Integer> future = new FutureTask<>(() -> {
       proc.destroy();
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
index 7f74c1a..e36dcff 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
@@ -235,7 +235,7 @@ public class TabletServer extends AbstractServer {
     }
   }
 
-  TabletServer(ServerOpts opts, String[] args) {
+  protected TabletServer(ServerOpts opts, String[] args) {
     super("tserver", opts, args);
     ServerContext context = super.getContext();
     context.setupCrypto();
@@ -568,13 +568,18 @@ public class TabletServer extends AbstractServer {
     return null;
   }
 
+  // exists to be overridden in tests
+  protected ThriftClientHandler getThriftClientHandler() {
+    return new ThriftClientHandler(this);
+  }
+
   private void returnManagerConnection(ManagerClientService.Client client) {
     ThriftUtil.returnClient(client);
   }
 
   private HostAndPort startTabletClientService() throws UnknownHostException {
     // start listening for client connection last
-    clientHandler = new ThriftClientHandler(this);
+    clientHandler = getThriftClientHandler();
     Iface rpcProxy = TraceUtil.wrapService(clientHandler);
     final Processor<Iface> processor;
     if (getContext().getThriftServerType() == ThriftServerType.SASL) {
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/ThriftClientHandler.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/ThriftClientHandler.java
index 2ac0d65..7764f5b 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/ThriftClientHandler.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/ThriftClientHandler.java
@@ -160,7 +160,7 @@ import org.slf4j.LoggerFactory;
 import com.google.common.cache.Cache;
 import com.google.common.collect.Collections2;
 
-class ThriftClientHandler extends ClientServiceHandler implements TabletClientService.Iface {
+public class ThriftClientHandler extends ClientServiceHandler implements TabletClientService.Iface {
 
   private static final Logger log = LoggerFactory.getLogger(ThriftClientHandler.class);
   private static final long MAX_TIME_TO_WAIT_FOR_SCAN_RESULT_MILLIS = 1000;
@@ -169,7 +169,7 @@ class ThriftClientHandler extends ClientServiceHandler implements TabletClientSe
   private final WriteTracker writeTracker = new WriteTracker();
   private final RowLocks rowLocks = new RowLocks();
 
-  ThriftClientHandler(TabletServer server) {
+  public ThriftClientHandler(TabletServer server) {
     super(server.getContext(), new TransactionWatcher(server.getContext()));
     this.server = server;
     log.debug("{} created", ThriftClientHandler.class.getName());
diff --git a/test/src/main/java/org/apache/accumulo/test/ExternalCompactionIT.java b/test/src/main/java/org/apache/accumulo/test/ExternalCompactionIT.java
index 837b964..9ce8ea9 100644
--- a/test/src/main/java/org/apache/accumulo/test/ExternalCompactionIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/ExternalCompactionIT.java
@@ -18,12 +18,17 @@
  */
 package org.apache.accumulo.test;
 
+import static org.apache.accumulo.minicluster.ServerType.TABLET_SERVER;
+
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.SortedSet;
 import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
 
 import org.apache.accumulo.compactor.CompactionEnvironment.CompactorIterEnv;
 import org.apache.accumulo.compactor.Compactor;
@@ -46,19 +51,36 @@ import org.apache.accumulo.core.iterators.Filter;
 import org.apache.accumulo.core.iterators.IteratorEnvironment;
 import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
 import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.metadata.schema.Ample.DataLevel;
+import org.apache.accumulo.core.metadata.schema.ExternalCompactionFinalState;
+import org.apache.accumulo.core.metadata.schema.ExternalCompactionId;
+import org.apache.accumulo.core.metadata.schema.ExternalCompactionMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType;
+import org.apache.accumulo.core.metadata.schema.TabletsMetadata;
 import org.apache.accumulo.core.spi.compaction.DefaultCompactionPlanner;
 import org.apache.accumulo.core.spi.compaction.SimpleCompactionDispatcher;
+import org.apache.accumulo.core.util.threads.Threads;
+import org.apache.accumulo.fate.util.UtilWaitThread;
+import org.apache.accumulo.minicluster.ServerType;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl.ProcessInfo;
 import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
 import org.apache.accumulo.test.functional.ConfigurableMacBase;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.RawLocalFileSystem;
 import org.apache.hadoop.io.Text;
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
 
 public class ExternalCompactionIT extends ConfigurableMacBase {
 
+  private static final Logger LOG = LoggerFactory.getLogger(ExternalCompactionIT.class);
+
   @Override
   protected void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {
     cfg.setProperty("tserver.compaction.major.service.cs1.planner",
@@ -69,6 +91,8 @@ public class ExternalCompactionIT extends ConfigurableMacBase {
         DefaultCompactionPlanner.class.getName());
     cfg.setProperty("tserver.compaction.major.service.cs2.planner.opts.executors",
         "[{'name':'all','externalQueue':'DCQ2'}]");
+    // use raw local file system so walogs sync and flush will work
+    hadoopCoreSite.set("fs.file.impl", RawLocalFileSystem.class.getName());
   }
 
   public static class TestFilter extends Filter {
@@ -116,26 +140,110 @@ public class ExternalCompactionIT extends ConfigurableMacBase {
       String table2 = "ectt2";
       createTable(client, table2, "cs2");
 
-      wrtieData(client, table1);
-      wrtieData(client, table2);
+      writeData(client, table1);
+      writeData(client, table2);
 
       cluster.exec(Compactor.class, "-q", "DCQ1");
       cluster.exec(Compactor.class, "-q", "DCQ2");
       cluster.exec(CompactionCoordinator.class);
 
-      compact(client, table1, 2, "DCQ1");
+      compact(client, table1, 2, "DCQ1", true);
       verify(client, table1, 2);
 
       SortedSet<Text> splits = new TreeSet<>();
       splits.add(new Text("r:4"));
       client.tableOperations().addSplits(table2, splits);
 
-      compact(client, table2, 3, "DCQ2");
+      compact(client, table2, 3, "DCQ2", true);
       verify(client, table2, 3);
 
     }
   }
 
+  @Test
+  //@Ignore // waiting for solution to issue #2019
+  public void testExternalCompactionDeadTServer() throws Exception {
+    // Shut down the normal TServers
+    getCluster().getProcesses().get(TABLET_SERVER).forEach(p -> {
+      try {
+        getCluster().killProcess(TABLET_SERVER, p);
+      } catch (Exception e) {
+        Assert.fail("Failed to shutdown tablet server");
+      }
+    });
+    // Start our TServer that will not commit the compaction
+    ProcessInfo process = cluster.exec(ExternalCompactionTServer.class);
+
+    final String table3 = "ectt3";
+    try (final AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
+      createTable(client, table3, "cs1");
+      writeData(client, table3);
+      cluster.exec(Compactor.class, "-q", "DCQ1");
+      cluster.exec(CompactionCoordinator.class);
+      compact(client, table3, 2, "DCQ1", false);
+
+      // ExternalCompactionTServer will not commit the compaction. Wait for the
+      // metadata table entries to show up.
+      LOG.info("Waiting for external compaction to complete.");
+      Stream<ExternalCompactionFinalState> fs =
+          getCluster().getServerContext().getAmple().getExternalCompactionFinalStates();
+      while (fs.count() == 0) {
+        LOG.info("Waiting for compaction completed marker to appear");
+        UtilWaitThread.sleep(1000);
+        fs = getCluster().getServerContext().getAmple().getExternalCompactionFinalStates();
+      }
+
+      // We need to wait until the metadata entries show up
+      LOG.info("Validating metadata table contents.");
+      TabletsMetadata tm = getCluster().getServerContext().getAmple().readTablets()
+          .forLevel(DataLevel.USER).fetch(ColumnType.ECOMP).build();
+      List<TabletMetadata> md = new ArrayList<>();
+      tm.forEach(t -> md.add(t));
+      Assert.assertEquals(1, md.size());
+      TabletMetadata m = md.get(0);
+      Map<ExternalCompactionId,ExternalCompactionMetadata> em = m.getExternalCompactions();
+      Assert.assertEquals(1, em.size());
+      List<ExternalCompactionFinalState> finished = new ArrayList<>();
+      getCluster().getServerContext().getAmple().getExternalCompactionFinalStates()
+          .forEach(f -> finished.add(f));
+      Assert.assertEquals(1, finished.size());
+      Assert.assertEquals(em.entrySet().iterator().next().getKey(),
+          finished.get(0).getExternalCompactionId());
+      tm.close();
+
+      // Force a flush on the metadata table before killing our tserver
+      client.tableOperations().compact("accumulo.metadata", new CompactionConfig().setWait(true));
+    }
+
+    // Stop our TabletServer. Need to perform a normal shutdown so that the WAL is closed normally.
+    LOG.info("Stopping our tablet server");
+    Process tsp = process.getProcess();
+    if (tsp.supportsNormalTermination()) {
+      cluster.stopProcessWithTimeout(tsp, 60, TimeUnit.SECONDS);
+    } else {
+      LOG.info("Stopping tserver manually");
+      new ProcessBuilder("kill", Long.toString(tsp.pid())).start();
+      tsp.waitFor();
+    }
+
+    // Start a TabletServer to commit the compaction.
+    LOG.info("Starting normal tablet server");
+    getCluster().getClusterControl().start(ServerType.TABLET_SERVER);
+
+    // Wait for the compaction to be committed.
+    LOG.info("Waiting for compaction completed marker to disappear");
+    Stream<ExternalCompactionFinalState> fs =
+        getCluster().getServerContext().getAmple().getExternalCompactionFinalStates();
+    while (fs.count() != 0) {
+      LOG.info("Waiting for compaction completed marker to disappear");
+      UtilWaitThread.sleep(1000);
+      fs = getCluster().getServerContext().getAmple().getExternalCompactionFinalStates();
+    }
+    try (final AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
+      verify(client, table3, 2);
+    }
+  }
+
   private void verify(AccumuloClient client, String table1, int modulus)
       throws TableNotFoundException, AccumuloSecurityException, AccumuloException {
     try (Scanner scanner = client.createScanner(table1)) {
@@ -155,14 +263,15 @@ public class ExternalCompactionIT extends ConfigurableMacBase {
     }
   }
 
-  private void compact(AccumuloClient client, String table1, int modulus, String expectedQueue)
+  private void compact(final AccumuloClient client, String table1, int modulus,
+      String expectedQueue, boolean wait)
       throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
     IteratorSetting iterSetting = new IteratorSetting(100, TestFilter.class);
     // make sure iterator options make it to compactor process
     iterSetting.addOption("expectedQ", expectedQueue);
     iterSetting.addOption("modulus", modulus + "");
     CompactionConfig config =
-        new CompactionConfig().setIterators(List.of(iterSetting)).setWait(true);
+        new CompactionConfig().setIterators(List.of(iterSetting)).setWait(wait);
     client.tableOperations().compact(table1, config);
   }
 
@@ -177,7 +286,7 @@ public class ExternalCompactionIT extends ConfigurableMacBase {
 
   }
 
-  private void wrtieData(AccumuloClient client, String table1) throws MutationsRejectedException,
+  private void writeData(AccumuloClient client, String table1) throws MutationsRejectedException,
       TableNotFoundException, AccumuloException, AccumuloSecurityException {
     try (BatchWriter bw = client.createBatchWriter(table1)) {
       for (int i = 0; i < 10; i++) {
diff --git a/test/src/main/java/org/apache/accumulo/test/ExternalCompactionTServer.java b/test/src/main/java/org/apache/accumulo/test/ExternalCompactionTServer.java
new file mode 100644
index 0000000..2282e47
--- /dev/null
+++ b/test/src/main/java/org/apache/accumulo/test/ExternalCompactionTServer.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import org.apache.accumulo.server.ServerOpts;
+import org.apache.accumulo.tserver.TabletServer;
+import org.apache.accumulo.tserver.ThriftClientHandler;
+
+public class ExternalCompactionTServer extends TabletServer {
+
+  ExternalCompactionTServer(ServerOpts opts, String[] args) {
+    super(opts, args);
+  }
+
+  @Override
+  protected ThriftClientHandler getThriftClientHandler() {
+    return new NonCommittingExternalCompactionThriftClientHandler(this);
+  }
+
+  public static void main(String[] args) throws Exception {
+    try (
+        ExternalCompactionTServer tserver = new ExternalCompactionTServer(new ServerOpts(), args)) {
+      tserver.runServer();
+    }
+
+  }
+
+}
diff --git a/test/src/main/java/org/apache/accumulo/test/NonCommittingExternalCompactionThriftClientHandler.java b/test/src/main/java/org/apache/accumulo/test/NonCommittingExternalCompactionThriftClientHandler.java
new file mode 100644
index 0000000..dabfe78
--- /dev/null
+++ b/test/src/main/java/org/apache/accumulo/test/NonCommittingExternalCompactionThriftClientHandler.java
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException;
+import org.apache.accumulo.core.dataImpl.thrift.TKeyExtent;
+import org.apache.accumulo.core.securityImpl.thrift.TCredentials;
+import org.apache.accumulo.core.tabletserver.thrift.TabletClientService;
+import org.apache.accumulo.core.trace.thrift.TInfo;
+import org.apache.accumulo.tserver.TabletServer;
+import org.apache.accumulo.tserver.ThriftClientHandler;
+import org.apache.thrift.TException;
+
+public class NonCommittingExternalCompactionThriftClientHandler extends ThriftClientHandler
+    implements TabletClientService.Iface {
+
+  public NonCommittingExternalCompactionThriftClientHandler(TabletServer server) {
+    super(server);
+  }
+
+  @Override
+  public void compactionJobFinished(TInfo tinfo, TCredentials credentials,
+      String externalCompactionId, TKeyExtent extent, long fileSize, long entries)
+      throws ThriftSecurityException, TException {
+    // do nothing
+  }
+
+  @Override
+  public void compactionJobFailed(TInfo tinfo, TCredentials credentials,
+      String externalCompactionId, TKeyExtent extent) throws TException {
+    // do nothing
+  }
+
+}