keith-turner commented on code in PR #5353:
URL: https://github.com/apache/accumulo/pull/5353#discussion_r1970529126


##########
server/manager/src/main/java/org/apache/accumulo/manager/merge/FindMergeableRangeTask.java:
##########
@@ -0,0 +1,233 @@
+/*
+ * 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
+ *
+ *   https://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.manager.merge;
+
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.FILES;
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.MERGEABILITY;
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.PREV_ROW;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import org.apache.accumulo.core.clientImpl.thrift.TableOperation;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.NamespaceId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.fate.Fate.FateOperation;
+import org.apache.accumulo.core.fate.FateInstanceType;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType;
+import org.apache.accumulo.core.metadata.schema.filters.TabletMetadataFilter;
+import org.apache.accumulo.core.util.time.SteadyTime;
+import org.apache.accumulo.manager.Manager;
+import org.apache.accumulo.manager.tableOps.TraceRepo;
+import org.apache.accumulo.manager.tableOps.merge.MergeInfo.Operation;
+import org.apache.accumulo.manager.tableOps.merge.TableRangeOp;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.io.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+
+public class FindMergeableRangeTask implements Runnable {
+
+  private static final Logger log = 
LoggerFactory.getLogger(FindMergeableRangeTask.class);
+
+  private static final TabletMergeabilityFilter FILTER = new 
TabletMergeabilityFilter();
+
+  private final Manager manager;
+
+  public FindMergeableRangeTask(Manager manager) {
+    this.manager = Objects.requireNonNull(manager);
+    log.debug("Creating FindMergeableRangeTask");
+  }
+
+  @Override
+  public void run() {
+    var context = manager.getContext();
+    Map<TableId,String> tables = context.getTableIdToNameMap();
+
+    log.debug("Starting FindMergeableRangeTask");
+
+    for (Entry<TableId,String> table : tables.entrySet()) {
+      TableId tableId = table.getKey();
+      String tableName = table.getValue();
+
+      long maxFileCount =
+          
context.getTableConfiguration(tableId).getCount(Property.TABLE_MERGE_FILE_MAX);
+      long threshold =
+          
context.getTableConfiguration(tableId).getAsBytes(Property.TABLE_SPLIT_THRESHOLD);
+      double mergeabilityThreshold = context.getTableConfiguration(tableId)
+          .getFraction(Property.TABLE_MAX_MERGEABILITY_THRESHOLD);
+      long maxTotalSize = (long) (threshold * mergeabilityThreshold);
+
+      log.debug("Checking {} for tablets that can be merged", tableName);
+      log.debug("maxFileCount: {}, maxTotalSize:{}, splitThreshold:{}, 
mergeabilityThreshold:{}",
+          maxFileCount, maxTotalSize, threshold, mergeabilityThreshold);
+      try {
+        NamespaceId namespaceId = context.getNamespaceId(tableId);
+        var type = FateInstanceType.fromTableId(tableId);
+
+        try (var tablets = context.getAmple().readTablets().forTable(tableId)
+            .fetch(PREV_ROW, FILES, MERGEABILITY).filter(FILTER).build()) {
+
+          final MergeableRange current =
+              new MergeableRange(manager.getSteadyTime(), maxFileCount, 
maxTotalSize);
+
+          for (var tm : tablets) {
+            log.trace("Checking tablet {}, {}", tm.getExtent(), 
tm.getTabletMergeability());
+            if (!current.add(tm)) {
+              submit(current, type, table, namespaceId);
+              current.resetAndAdd(tm);
+            }
+          }
+
+          submit(current, type, table, namespaceId);
+        }
+
+      } catch (Exception e) {
+        log.error("Failed to generate system merges for {}", tableName, e);
+      }
+    }
+
+  }
+
+  void submit(MergeableRange range, FateInstanceType type, 
Entry<TableId,String> table,
+      NamespaceId namespaceId) {
+    if (range.tabletCount < 2) {
+      return;
+    }
+
+    log.debug("Table {} found {} tablets that can be merged for table", 
table.getValue(),
+        range.tabletCount);
+
+    TableId tableId = table.getKey();
+    String tableName = table.getValue();
+
+    final Text startRow = range.startRow != null ? range.startRow : new 
Text("");
+    final Text endRow = range.endRow != null ? range.endRow : new Text("");
+
+    String startRowStr = StringUtils.defaultIfBlank(startRow.toString(), 
"-inf");
+    String endRowStr = StringUtils.defaultIfBlank(endRow.toString(), "+inf");
+    log.debug("FindMergeableRangeTask: Creating merge op: {} from startRow: {} 
to endRow: {}",
+        tableId, startRowStr, endRowStr);
+    var fateId = manager.fate(type).startTransaction();
+    String goalMessage = TableOperation.MERGE + " Merge table " + tableName + 
"(" + tableId
+        + ") splits from " + startRowStr + " to " + endRowStr;
+
+    manager.fate(type).seedTransaction(FateOperation.SYSTEM_MERGE, fateId,

Review Comment:
   Could create a new FateKey type and use that to seed the fate op.  Could 
create an extent that covers the merge range and use that extent to create the 
key.  This would avoid recreating a fate op if this code runs a 2nd time and 
the fate op it created in the first run is still there.



##########
server/manager/src/main/java/org/apache/accumulo/manager/merge/FindMergeableRangeTask.java:
##########
@@ -0,0 +1,233 @@
+/*
+ * 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
+ *
+ *   https://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.manager.merge;
+
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.FILES;
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.MERGEABILITY;
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.PREV_ROW;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import org.apache.accumulo.core.clientImpl.thrift.TableOperation;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.NamespaceId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.fate.Fate.FateOperation;
+import org.apache.accumulo.core.fate.FateInstanceType;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType;
+import org.apache.accumulo.core.metadata.schema.filters.TabletMetadataFilter;
+import org.apache.accumulo.core.util.time.SteadyTime;
+import org.apache.accumulo.manager.Manager;
+import org.apache.accumulo.manager.tableOps.TraceRepo;
+import org.apache.accumulo.manager.tableOps.merge.MergeInfo.Operation;
+import org.apache.accumulo.manager.tableOps.merge.TableRangeOp;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.io.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+
+public class FindMergeableRangeTask implements Runnable {
+
+  private static final Logger log = 
LoggerFactory.getLogger(FindMergeableRangeTask.class);
+
+  private static final TabletMergeabilityFilter FILTER = new 
TabletMergeabilityFilter();
+
+  private final Manager manager;
+
+  public FindMergeableRangeTask(Manager manager) {
+    this.manager = Objects.requireNonNull(manager);
+    log.debug("Creating FindMergeableRangeTask");
+  }
+
+  @Override
+  public void run() {
+    var context = manager.getContext();
+    Map<TableId,String> tables = context.getTableIdToNameMap();
+
+    log.debug("Starting FindMergeableRangeTask");
+
+    for (Entry<TableId,String> table : tables.entrySet()) {
+      TableId tableId = table.getKey();
+      String tableName = table.getValue();
+
+      long maxFileCount =
+          
context.getTableConfiguration(tableId).getCount(Property.TABLE_MERGE_FILE_MAX);
+      long threshold =
+          
context.getTableConfiguration(tableId).getAsBytes(Property.TABLE_SPLIT_THRESHOLD);
+      double mergeabilityThreshold = context.getTableConfiguration(tableId)
+          .getFraction(Property.TABLE_MAX_MERGEABILITY_THRESHOLD);
+      long maxTotalSize = (long) (threshold * mergeabilityThreshold);
+
+      log.debug("Checking {} for tablets that can be merged", tableName);
+      log.debug("maxFileCount: {}, maxTotalSize:{}, splitThreshold:{}, 
mergeabilityThreshold:{}",
+          maxFileCount, maxTotalSize, threshold, mergeabilityThreshold);
+      try {
+        NamespaceId namespaceId = context.getNamespaceId(tableId);
+        var type = FateInstanceType.fromTableId(tableId);
+
+        try (var tablets = context.getAmple().readTablets().forTable(tableId)
+            .fetch(PREV_ROW, FILES, MERGEABILITY).filter(FILTER).build()) {
+
+          final MergeableRange current =
+              new MergeableRange(manager.getSteadyTime(), maxFileCount, 
maxTotalSize);
+
+          for (var tm : tablets) {
+            log.trace("Checking tablet {}, {}", tm.getExtent(), 
tm.getTabletMergeability());
+            if (!current.add(tm)) {
+              submit(current, type, table, namespaceId);
+              current.resetAndAdd(tm);
+            }
+          }
+
+          submit(current, type, table, namespaceId);
+        }
+
+      } catch (Exception e) {
+        log.error("Failed to generate system merges for {}", tableName, e);
+      }
+    }
+
+  }
+
+  void submit(MergeableRange range, FateInstanceType type, 
Entry<TableId,String> table,
+      NamespaceId namespaceId) {
+    if (range.tabletCount < 2) {
+      return;
+    }
+
+    log.debug("Table {} found {} tablets that can be merged for table", 
table.getValue(),
+        range.tabletCount);
+
+    TableId tableId = table.getKey();
+    String tableName = table.getValue();
+
+    final Text startRow = range.startRow != null ? range.startRow : new 
Text("");
+    final Text endRow = range.endRow != null ? range.endRow : new Text("");
+
+    String startRowStr = StringUtils.defaultIfBlank(startRow.toString(), 
"-inf");
+    String endRowStr = StringUtils.defaultIfBlank(endRow.toString(), "+inf");
+    log.debug("FindMergeableRangeTask: Creating merge op: {} from startRow: {} 
to endRow: {}",
+        tableId, startRowStr, endRowStr);
+    var fateId = manager.fate(type).startTransaction();
+    String goalMessage = TableOperation.MERGE + " Merge table " + tableName + 
"(" + tableId
+        + ") splits from " + startRowStr + " to " + endRowStr;
+
+    manager.fate(type).seedTransaction(FateOperation.SYSTEM_MERGE, fateId,
+        new TraceRepo<>(
+            new TableRangeOp(Operation.SYSTEM_MERGE, namespaceId, tableId, 
startRow, endRow)),
+        true, goalMessage);
+  }
+
+  static class MergeableRange {
+    final SteadyTime currentTime;
+    final long maxFileCount;
+    final long maxTotalSize;
+
+    Text startRow;
+    Text endRow;
+    int tabletCount;
+    long totalFileCount;
+    long totalFileSize;
+
+    MergeableRange(SteadyTime currentTime, long maxFileCount, long 
maxTotalSize) {
+      this.currentTime = currentTime;
+      this.maxFileCount = maxFileCount;
+      this.maxTotalSize = maxTotalSize;
+    }
+
+    boolean add(TabletMetadata tm) {
+      if (validate(tm)) {
+        tabletCount++;
+        log.trace("Adding tablet {} to MergeableRange", tm.getExtent());
+        if (tabletCount == 1) {
+          startRow = tm.getPrevEndRow();
+        }
+        endRow = tm.getEndRow();
+        totalFileCount += tm.getFiles().size();
+        totalFileSize += tm.getFileSize();
+        return true;
+      }
+      return false;
+    }
+
+    private boolean validate(TabletMetadata tm) {
+      if (tabletCount > 0) {
+        // This is at least the second tablet seen so there should not be a 
null prevEndRow

Review Comment:
   Could validate the tableId is the same w/ another preconditions check.



##########
server/manager/src/main/java/org/apache/accumulo/manager/tableOps/merge/VerifyMergeability.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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
+ *
+ *   https://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.manager.tableOps.merge;
+
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.FILES;
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.MERGEABILITY;
+
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.fate.FateId;
+import org.apache.accumulo.core.fate.Repo;
+import org.apache.accumulo.manager.Manager;
+import org.apache.accumulo.manager.tableOps.ManagerRepo;
+import org.apache.accumulo.manager.tableOps.merge.MergeInfo.Operation;
+import org.apache.accumulo.manager.tableOps.merge.UnreserveAndError.Reason;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public class VerifyMergeability extends ManagerRepo {
+  private static final Logger log = 
LoggerFactory.getLogger(VerifyMergeability.class);
+  private static final long serialVersionUID = 1L;
+  private final MergeInfo data;
+
+  public VerifyMergeability(MergeInfo mergeInfo) {
+    this.data = mergeInfo;
+    Preconditions.checkArgument(data.op == Operation.SYSTEM_MERGE, "Must be a 
System Merge");
+  }
+
+  @Override
+  public Repo<Manager> call(FateId fateId, Manager env) throws Exception {
+
+    var range = data.getReserveExtent();
+
+    var currentTime = env.getSteadyTime();
+    var context = env.getContext();
+    var tableConf = context.getTableConfiguration(data.tableId);
+    var splitThreshold = tableConf.getAsBytes(Property.TABLE_SPLIT_THRESHOLD);
+    var maxMergeabilityThreshold = 
tableConf.getFraction(Property.TABLE_MAX_MERGEABILITY_THRESHOLD);
+
+    // max percentage of split threshold
+    long maxTotalSize = (long) (splitThreshold * maxMergeabilityThreshold);
+
+    long maxFiles = 
env.getContext().getTableConfiguration(data.getOriginalExtent().tableId())
+        .getCount(Property.TABLE_MERGE_FILE_MAX);
+
+    log.debug("Validating system merge for {} with range {}", fateId, range);
+
+    try (var tablets = 
env.getContext().getAmple().readTablets().forTable(data.tableId)
+        .overlapping(range.prevEndRow(), range.endRow()).fetch(FILES, 
MERGEABILITY)
+        .checkConsistency().build()) {
+
+      long totalSize = 0;
+      long totalFiles = 0;
+      int totalUnMergeable = 0;
+
+      for (var tabletMetadata : tablets) {

Review Comment:
   When I first saw this code I though maybe it could use the MergeableRange 
code and try to add all tablets in the range to that.  However that would not 
give the reason that a tablet could not be added, so it almost works but not 
quite.



##########
core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java:
##########
@@ -357,4 +358,12 @@ boolean testClassLoad(final String className, final String 
asTypeName)
    * @since 2.1.0
    */
   InstanceId getInstanceId();
+
+  /**
+   * Return the current manager time

Review Comment:
   ```suggestion
      * Return the current manager time.  This duration represents the amount 
of time an accumulo manager process has been running.  The duration is 
persisted and should only increase over the lifetime of an Accumulo instance.  
   ```



##########
test/src/main/java/org/apache/accumulo/test/functional/TabletMergeabilityIT.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * 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
+ *
+ *   https://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.functional;
+
+import static 
org.apache.accumulo.test.compaction.ExternalCompactionTestUtils.countTablets;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.accumulo.core.client.Accumulo;
+import org.apache.accumulo.core.client.AccumuloClient;
+import org.apache.accumulo.core.client.admin.NewTableConfiguration;
+import org.apache.accumulo.core.client.admin.TabletMergeability;
+import org.apache.accumulo.core.clientImpl.TabletMergeabilityUtil;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.harness.MiniClusterConfigurationCallback;
+import org.apache.accumulo.harness.SharedMiniClusterBase;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.test.TestIngest;
+import org.apache.accumulo.test.VerifyIngest;
+import org.apache.accumulo.test.VerifyIngest.VerifyParams;
+import org.apache.accumulo.test.util.Wait;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.Text;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+public class TabletMergeabilityIT extends SharedMiniClusterBase {
+
+  @Override
+  protected Duration defaultTimeout() {
+    return Duration.ofMinutes(5);
+  }
+
+  @BeforeAll
+  public static void setup() throws Exception {
+    SharedMiniClusterBase.startMiniClusterWithConfig(new Callback());
+  }
+
+  @AfterAll
+  public static void teardown() {
+    SharedMiniClusterBase.stopMiniCluster();
+  }
+
+  private static class Callback implements MiniClusterConfigurationCallback {
+    @Override
+    public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration 
coreSite) {
+      // Configure a short period of time to run the auto merge thread for 
testing
+      cfg.setProperty(Property.MANAGER_TABLET_MERGEABILITY_INTERVAL, "3s");
+    }
+  }
+
+  @Test
+  public void testMergeabilityAll() throws Exception {
+    String tableName = getUniqueNames(1)[0];
+    try (AccumuloClient c = 
Accumulo.newClient().from(getClientProps()).build()) {
+      c.tableOperations().create(tableName);
+      var tableId = 
TableId.of(c.tableOperations().tableIdMap().get(tableName));
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text(String.format("%09d", 333)));
+      splits.add(new Text(String.format("%09d", 666)));
+      splits.add(new Text(String.format("%09d", 999)));
+
+      // create splits with mergeabilty disabled so the task does not merge 
them away
+      // The default tablet is always mergeable, but it is currently the only 
one that is mergeable,
+      // so nothing will merge
+      c.tableOperations().putSplits(tableName, 
TabletMergeabilityUtil.userDefaultSplits(splits));
+      Wait.waitFor(() -> countTablets(getCluster().getServerContext(), 
tableName, tm -> true) == 4,
+          5000, 200);
+
+      // update to always mergeable so the task can now merge tablets
+      c.tableOperations().putSplits(tableName, 
TabletMergeabilityUtil.systemDefaultSplits(splits));
+
+      // Wait for merge, we should have one tablet
+      Wait.waitFor(() -> hasExactTablets(getCluster().getServerContext(), 
tableId,
+          Set.of(new KeyExtent(tableId, null, null))), 10000, 200);
+
+    }
+  }
+
+  @Test
+  public void testMergeabilityMultipleRanges() throws Exception {
+    String tableName = getUniqueNames(1)[0];
+    try (AccumuloClient c = 
Accumulo.newClient().from(getClientProps()).build()) {
+      c.tableOperations().create(tableName);
+      var tableId = 
TableId.of(c.tableOperations().tableIdMap().get(tableName));
+
+      SortedMap<Text,TabletMergeability> splits = new TreeMap<>();
+      splits.put(new Text(String.format("%09d", 333)), 
TabletMergeability.never());
+      splits.put(new Text(String.format("%09d", 555)), 
TabletMergeability.never());
+      splits.put(new Text(String.format("%09d", 666)), 
TabletMergeability.never());
+      splits.put(new Text(String.format("%09d", 999)), 
TabletMergeability.never());
+
+      c.tableOperations().putSplits(tableName, splits);
+      Wait.waitFor(() -> countTablets(getCluster().getServerContext(), 
tableName, tm -> true) == 5,
+          5000, 500);
+
+      splits.put(new Text(String.format("%09d", 333)), 
TabletMergeability.always());
+      splits.put(new Text(String.format("%09d", 555)), 
TabletMergeability.always());
+      // Keep tablet 666 as never, this should cause two fate jobs for merging
+      splits.put(new Text(String.format("%09d", 999)), 
TabletMergeability.always());
+      c.tableOperations().putSplits(tableName, splits);
+
+      // Wait for merge, we should have 3 tablets
+      // 333 and 555 should be merged into 555
+      // 666
+      // 999 and default merged into default
+      Wait.waitFor(() -> hasExactTablets(getCluster().getServerContext(), 
tableId,
+          Set.of(new KeyExtent(tableId, new Text(String.format("%09d", 555)), 
null),
+              new KeyExtent(tableId, new Text(String.format("%09d", 666)),
+                  new Text(String.format("%09d", 555))),
+              new KeyExtent(tableId, null, new Text(String.format("%09d", 
666))))),
+          10000, 200);
+
+    }
+  }
+
+  @Test
+  public void testSplitAndMergeAll() throws Exception {
+    String tableName = getUniqueNames(1)[0];
+    try (AccumuloClient c = 
Accumulo.newClient().from(getClientProps()).build()) {
+      Map<String,String> props = new HashMap<>();
+      props.put(Property.TABLE_SPLIT_THRESHOLD.getKey(), "32K");
+      props.put(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE.getKey(), "1K");
+      c.tableOperations().create(tableName, new 
NewTableConfiguration().setProperties(props));
+      var tableId = 
TableId.of(c.tableOperations().tableIdMap().get(tableName));
+
+      // Ingest data so tablet will split
+      VerifyParams params = new VerifyParams(getClientProps(), tableName, 
50_000);
+      TestIngest.ingest(c, params);
+      VerifyIngest.verifyIngest(c, params);
+
+      // Wait for table to split, should be more than 10 tablets
+      Wait.waitFor(() -> c.tableOperations().listSplits(tableName).size() > 
10, 10000, 200);
+
+      // Delete all the data
+      c.tableOperations().deleteRows(tableName, null, null);

Review Comment:
   deleteRows also merges tablets I think, so the splits may not be going away 
because of auto merge here.  Could delete all the data and then compact to 
process all the delete markers.
   
   
   ```suggestion
          var bd = c.createBatchDeleter(tableName, Authorizations.EMPTY, 1);
         bd.setRanges(List.of(new Range()));
         bd.delete();
         c.tableOperations().compact(tableName, new 
CompactionConfig().setFlush(true));
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to