You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by "dlmarion (via GitHub)" <gi...@apache.org> on 2023/03/22 20:01:56 UTC

[GitHub] [accumulo] dlmarion commented on a diff in pull request #3250: Added On-Demand table feature

dlmarion commented on code in PR #3250:
URL: https://github.com/apache/accumulo/pull/3250#discussion_r1145338323


##########
test/src/main/java/org/apache/accumulo/test/MultiTableBatchWriterIT.java:
##########
@@ -400,4 +401,56 @@ public void testOfflineTable() throws Exception {
 
     assertTrue(mutationsRejected, "Expected mutations to be rejected.");
   }
+
+  @Test
+  public void testOnDemandTable() throws Exception {
+    boolean mutationsRejected = false;
+
+    try {
+      final String[] names = getUniqueNames(2);
+      final String table1 = names[0], table2 = names[1];
+
+      TableOperations tops = accumuloClient.tableOperations();
+      tops.create(table1);
+      tops.create(table2);
+
+      tops.offline(table1, true);
+      tops.offline(table2, true);

Review Comment:
   I think these can be replaced with calls to `ondemand`. I believe that this test was created before the unload capability existed, so I used the `offline` command to unload the tablets.



##########
test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java:
##########
@@ -88,9 +119,278 @@ public void test() throws Exception {
       assertNull(online.future);
       assertNotNull(online.current);
       assertEquals(online.current, online.last);
+
+      // take the tablet offline
+      c.tableOperations().offline(tableName, true);
+      offline = getTabletLocationState(c, tableId);
+      assertNull(offline.future);
+      assertNull(offline.current);
+      assertEquals(flushed.current, offline.last);
+
+      // set the table to ondemand
+      c.tableOperations().onDemand(tableName, true);
+      TabletLocationState ondemand = getTabletLocationState(c, tableId);
+      assertNull(ondemand.future);
+      assertNull(ondemand.current);
+      assertEquals(flushed.current, ondemand.last);
+
+      // put it back online
+      c.tableOperations().online(tableName, true);
+      online = getTabletLocationState(c, tableId);
+      assertNull(online.future);
+      assertNotNull(online.current);
+      assertEquals(online.current, online.last);
+
+    }
+  }
+
+  @Test
+  public void testScannerAssignsOneOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "c");
+      Scanner s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      // Should return keys for a, b, c
+      assertEquals(3, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      // There should be one tablet online
+      assertEquals(1, stats.size());
+      assertEquals(1, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+    }
+  }
+
+  @Test
+  public void testScannerAssignsMultipleOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "s");
+      Scanner s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      assertEquals(19, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      assertEquals(3, stats.size());
+      assertEquals(3, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      // Run another scan, all tablets should be loaded
+      scanRange = new Range("a", "t");
+      s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      assertEquals(20, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      assertEquals(3, stats.size());
+      // No more tablets should have been brought online
+      assertEquals(3, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+    }
+  }
+
+  @Test
+  public void testBatchScannerAssignsOneOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "c");
+      BatchScanner s = c.createBatchScanner(tableName);
+      s.setRanges(Collections.singleton(scanRange));
+      // Should return keys for a, b, c
+      assertEquals(3, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      // There should be one tablet online
+      assertEquals(1, stats.size());
+      assertEquals(1, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+    }
+  }
+
+  @Test
+  public void testBatchScannerAssignsMultipleOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);

Review Comment:
   I think these can be removed. I believe that this test was created before the unload capability existed, so I used the `offline` command to unload the tablets.



##########
test/src/main/java/org/apache/accumulo/test/functional/OnDemandIT.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+import java.util.TreeSet;
+
+import org.apache.accumulo.core.client.Accumulo;
+import org.apache.accumulo.core.client.AccumuloClient;
+import org.apache.accumulo.core.clientImpl.ClientContext;
+import org.apache.accumulo.core.clientImpl.TabletLocator;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.metrics.MetricsProducer;
+import org.apache.accumulo.core.tabletserver.thrift.TabletStats;
+import org.apache.accumulo.harness.SharedMiniClusterBase;
+import org.apache.accumulo.test.metrics.TestStatsDRegistryFactory;
+import org.apache.accumulo.test.metrics.TestStatsDSink;
+import org.apache.accumulo.test.metrics.TestStatsDSink.Metric;
+import org.apache.hadoop.io.Text;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class OnDemandIT extends SharedMiniClusterBase {
+
+  private static final int managerTabletGroupWatcherInterval = 5;
+  private static final int inactiveOnDemandTabletUnloaderInterval = 30;
+  private static TestStatsDSink sink;
+  private static Thread metricConsumer;
+  private static Long ONDEMAND_ONLINE_COUNT = 0L;
+
+  @BeforeAll
+  public static void beforeAll() throws Exception {
+    sink = new TestStatsDSink();
+    metricConsumer = new Thread(() -> {
+      while (!Thread.currentThread().isInterrupted()) {
+        List<String> statsDMetrics = sink.getLines();
+        for (String line : statsDMetrics) {
+          if (Thread.currentThread().isInterrupted()) {
+            break;
+          }
+          if (line.startsWith("accumulo")) {
+            Metric metric = TestStatsDSink.parseStatsDMetric(line);
+            if (MetricsProducer.METRICS_TSERVER_TABLETS_ONLINE_ONDEMAND.equals(metric.getName())) {
+              Long val = Long.parseLong(metric.getValue());
+              ONDEMAND_ONLINE_COUNT = val;
+            }
+          }
+        }
+      }
+    });
+    metricConsumer.start();
+    SharedMiniClusterBase.startMiniClusterWithConfig((cfg, core) -> {
+      cfg.setNumTservers(1);
+      cfg.setProperty(Property.MANAGER_TABLET_GROUP_WATCHER_INTERVAL,
+          Integer.toString(managerTabletGroupWatcherInterval));
+      cfg.setProperty(Property.TABLE_ONDEMAND_UNLOADER_INTERVAL,
+          Integer.toString(inactiveOnDemandTabletUnloaderInterval));
+      cfg.setProperty("table.custom.ondemand.unloader.inactivity.threshold", "30000");
+
+      // Tell the server processes to use a StatsDMeterRegistry that will be configured
+      // to push all metrics to the sink we started.
+      cfg.setProperty(Property.GENERAL_MICROMETER_ENABLED, "true");
+      cfg.setProperty(Property.GENERAL_MICROMETER_FACTORY,
+          TestStatsDRegistryFactory.class.getName());
+      Map<String,String> sysProps = Map.of(TestStatsDRegistryFactory.SERVER_HOST, "127.0.0.1",
+          TestStatsDRegistryFactory.SERVER_PORT, Integer.toString(sink.getPort()));
+      cfg.setSystemProperties(sysProps);
+    });
+  }
+
+  @AfterAll
+  public static void after() throws Exception {
+    sink.close();
+    metricConsumer.interrupt();
+    metricConsumer.join();
+  }
+
+  @BeforeEach
+  public void before() {
+    ONDEMAND_ONLINE_COUNT = 0L;
+  }
+
+  @Test
+  public void testLoadUnload() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      ManagerAssignmentIT.loadDataForScan(c, tableName);
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);

Review Comment:
   I think these can be removed. I believe that this test was created before the unload capability existed, so I used the `offline` command to unload the tablets.



##########
test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java:
##########
@@ -88,9 +119,278 @@ public void test() throws Exception {
       assertNull(online.future);
       assertNotNull(online.current);
       assertEquals(online.current, online.last);
+
+      // take the tablet offline
+      c.tableOperations().offline(tableName, true);
+      offline = getTabletLocationState(c, tableId);
+      assertNull(offline.future);
+      assertNull(offline.current);
+      assertEquals(flushed.current, offline.last);
+
+      // set the table to ondemand
+      c.tableOperations().onDemand(tableName, true);
+      TabletLocationState ondemand = getTabletLocationState(c, tableId);
+      assertNull(ondemand.future);
+      assertNull(ondemand.current);
+      assertEquals(flushed.current, ondemand.last);
+
+      // put it back online
+      c.tableOperations().online(tableName, true);
+      online = getTabletLocationState(c, tableId);
+      assertNull(online.future);
+      assertNotNull(online.current);
+      assertEquals(online.current, online.last);
+
+    }
+  }
+
+  @Test
+  public void testScannerAssignsOneOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);

Review Comment:
   I think these can be removed. I believe that this test was created before the unload capability existed, so I used the `offline` command to unload the tablets.



##########
test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java:
##########
@@ -88,9 +119,278 @@ public void test() throws Exception {
       assertNull(online.future);
       assertNotNull(online.current);
       assertEquals(online.current, online.last);
+
+      // take the tablet offline
+      c.tableOperations().offline(tableName, true);
+      offline = getTabletLocationState(c, tableId);
+      assertNull(offline.future);
+      assertNull(offline.current);
+      assertEquals(flushed.current, offline.last);
+
+      // set the table to ondemand
+      c.tableOperations().onDemand(tableName, true);
+      TabletLocationState ondemand = getTabletLocationState(c, tableId);
+      assertNull(ondemand.future);
+      assertNull(ondemand.current);
+      assertEquals(flushed.current, ondemand.last);
+
+      // put it back online
+      c.tableOperations().online(tableName, true);
+      online = getTabletLocationState(c, tableId);
+      assertNull(online.future);
+      assertNotNull(online.current);
+      assertEquals(online.current, online.last);
+
+    }
+  }
+
+  @Test
+  public void testScannerAssignsOneOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "c");
+      Scanner s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      // Should return keys for a, b, c
+      assertEquals(3, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      // There should be one tablet online
+      assertEquals(1, stats.size());
+      assertEquals(1, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+    }
+  }
+
+  @Test
+  public void testScannerAssignsMultipleOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);

Review Comment:
   I think these can be removed. I believe that this test was created before the unload capability existed, so I used the `offline` command to unload the tablets.



##########
test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java:
##########
@@ -88,9 +119,278 @@ public void test() throws Exception {
       assertNull(online.future);
       assertNotNull(online.current);
       assertEquals(online.current, online.last);
+
+      // take the tablet offline
+      c.tableOperations().offline(tableName, true);
+      offline = getTabletLocationState(c, tableId);
+      assertNull(offline.future);
+      assertNull(offline.current);
+      assertEquals(flushed.current, offline.last);
+
+      // set the table to ondemand
+      c.tableOperations().onDemand(tableName, true);
+      TabletLocationState ondemand = getTabletLocationState(c, tableId);
+      assertNull(ondemand.future);
+      assertNull(ondemand.current);
+      assertEquals(flushed.current, ondemand.last);
+
+      // put it back online
+      c.tableOperations().online(tableName, true);
+      online = getTabletLocationState(c, tableId);
+      assertNull(online.future);
+      assertNotNull(online.current);
+      assertEquals(online.current, online.last);
+
+    }
+  }
+
+  @Test
+  public void testScannerAssignsOneOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "c");
+      Scanner s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      // Should return keys for a, b, c
+      assertEquals(3, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      // There should be one tablet online
+      assertEquals(1, stats.size());
+      assertEquals(1, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+    }
+  }
+
+  @Test
+  public void testScannerAssignsMultipleOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "s");
+      Scanner s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      assertEquals(19, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      assertEquals(3, stats.size());
+      assertEquals(3, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      // Run another scan, all tablets should be loaded
+      scanRange = new Range("a", "t");
+      s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      assertEquals(20, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      assertEquals(3, stats.size());
+      // No more tablets should have been brought online
+      assertEquals(3, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+    }
+  }
+
+  @Test
+  public void testBatchScannerAssignsOneOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);

Review Comment:
   I think these can be removed. I believe that this test was created before the unload capability existed, so I used the `offline` command to unload the tablets.



##########
test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java:
##########
@@ -88,9 +119,278 @@ public void test() throws Exception {
       assertNull(online.future);
       assertNotNull(online.current);
       assertEquals(online.current, online.last);
+
+      // take the tablet offline
+      c.tableOperations().offline(tableName, true);
+      offline = getTabletLocationState(c, tableId);
+      assertNull(offline.future);
+      assertNull(offline.current);
+      assertEquals(flushed.current, offline.last);
+
+      // set the table to ondemand
+      c.tableOperations().onDemand(tableName, true);
+      TabletLocationState ondemand = getTabletLocationState(c, tableId);
+      assertNull(ondemand.future);
+      assertNull(ondemand.current);
+      assertEquals(flushed.current, ondemand.last);
+
+      // put it back online
+      c.tableOperations().online(tableName, true);
+      online = getTabletLocationState(c, tableId);
+      assertNull(online.future);
+      assertNotNull(online.current);
+      assertEquals(online.current, online.last);
+
+    }
+  }
+
+  @Test
+  public void testScannerAssignsOneOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "c");
+      Scanner s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      // Should return keys for a, b, c
+      assertEquals(3, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      // There should be one tablet online
+      assertEquals(1, stats.size());
+      assertEquals(1, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+    }
+  }
+
+  @Test
+  public void testScannerAssignsMultipleOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "s");
+      Scanner s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      assertEquals(19, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      assertEquals(3, stats.size());
+      assertEquals(3, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      // Run another scan, all tablets should be loaded
+      scanRange = new Range("a", "t");
+      s = c.createScanner(tableName);
+      s.setRange(scanRange);
+      assertEquals(20, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      assertEquals(3, stats.size());
+      // No more tablets should have been brought online
+      assertEquals(3, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+    }
+  }
+
+  @Test
+  public void testBatchScannerAssignsOneOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "c");
+      BatchScanner s = c.createBatchScanner(tableName);
+      s.setRanges(Collections.singleton(scanRange));
+      // Should return keys for a, b, c
+      assertEquals(3, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      // There should be one tablet online
+      assertEquals(1, stats.size());
+      assertEquals(1, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+    }
+  }
+
+  @Test
+  public void testBatchScannerAssignsMultipleOnDemandTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);
+      c.tableOperations().onDemand(tableName, true);
+      assertTrue(c.tableOperations().isOnDemand(tableName));
+
+      List<TabletStats> stats = getTabletStats(c, tableId);
+      // There should be no tablets online
+      assertEquals(0, stats.size());
+      assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      c.tableOperations().clearLocatorCache(tableName);
+
+      Range scanRange = new Range("a", "s");
+      BatchScanner s = c.createBatchScanner(tableName);
+      s.setRanges(Collections.singleton(scanRange));
+      assertEquals(19, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      assertEquals(3, stats.size());
+      assertEquals(3, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
+      // Run another scan, all tablets should be loaded
+      scanRange = new Range("a", "t");
+      s = c.createBatchScanner(tableName);
+      s.setRanges(Collections.singleton(scanRange));
+      assertEquals(20, Iterables.size(s));
+
+      stats = getTabletStats(c, tableId);
+      assertEquals(3, stats.size());
+      // No more tablets should have been brought online
+      assertEquals(3, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId))
+          .onDemandTabletsOnlined());
+
     }
   }
 
+  @Test
+  public void testBatchWriterAssignsTablets() throws Exception {
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      String tableName = super.getUniqueNames(1)[0];
+      c.tableOperations().create(tableName);
+      String tableId = c.tableOperations().tableIdMap().get(tableName);
+      loadDataForScan(c, tableName);
+
+      TreeSet<Text> splits = new TreeSet<>();
+      splits.add(new Text("f"));
+      splits.add(new Text("m"));
+      splits.add(new Text("t"));
+      c.tableOperations().addSplits(tableName, splits);
+      // Need to offline the table first so that the tablets
+      // are unloaded.
+      c.tableOperations().offline(tableName, true);

Review Comment:
   I think these can be removed. I believe that this test was created before the unload capability existed, so I used the `offline` command to unload the tablets.



##########
server/manager/src/main/java/org/apache/accumulo/manager/tableOps/bulkVer2/LoadFiles.java:
##########
@@ -107,6 +107,7 @@ public long isReady(long tid, Manager manager) throws Exception {
 
   @Override
   public Repo<Manager> call(final long tid, final Manager manager) {
+    // TODO: How are we treating ONDEMAND tables for BulkImport?

Review Comment:
   Need to address this.



-- 
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