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


##########
test/src/main/java/org/apache/accumulo/test/ManagerRepairsDualAssignmentIT.java:
##########
@@ -94,12 +95,13 @@ public void test() throws Exception {
       while (states.size() < 2) {
         UtilWaitThread.sleep(250);
         oldLocations.clear();
-        for (TabletManagement mti : store) {
+        // ELASTICITY_TODO passed null here to make test compile
+        store.iterator(null).forEachRemaining(mti -> {

Review Comment:
   Can you use MAC's context to use Ample?



##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletGoalState.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.server.manager.state;
+
+import org.apache.accumulo.core.data.TabletId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.dataImpl.TabletIdImpl;
+import org.apache.accumulo.core.manager.balancer.TabletServerIdImpl;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.spi.balancer.TabletBalancer;
+import org.apache.accumulo.core.spi.balancer.data.TabletServerId;
+import org.apache.accumulo.core.tablet.thrift.TUnloadTabletGoal;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public enum TabletGoalState {
+
+  HOSTED(TUnloadTabletGoal.UNKNOWN),
+  UNASSIGNED(TUnloadTabletGoal.UNASSIGNED),
+  SUSPENDED(TUnloadTabletGoal.SUSPENDED);
+
+  private final TUnloadTabletGoal unloadGoal;
+
+  TabletGoalState(TUnloadTabletGoal unloadGoal) {
+    this.unloadGoal = unloadGoal;
+  }
+
+  /** The purpose of unloading this tablet. */
+  public TUnloadTabletGoal howUnload() {
+    return unloadGoal;
+  }
+
+  private static final Logger log = 
LoggerFactory.getLogger(TabletGoalState.class);
+
+  public static TabletGoalState compute(TabletMetadata tm, TabletState 
currentState,
+      TabletBalancer balancer, TabletManagementParameters params) {
+    Preconditions.checkArgument(Ample.DataLevel.of(tm.getTableId()) == 
params.getLevel(),
+        "Tablet %s not in expected level %s", tm.getExtent(), 
params.getLevel());
+
+    // Always follow through with assignments
+    if (currentState == TabletState.ASSIGNED) {
+      return HOSTED;
+    }
+
+    KeyExtent extent = tm.getExtent();
+    // Shutting down?
+    TabletGoalState systemGoalState = getSystemGoalState(tm, params);
+
+    if (systemGoalState == TabletGoalState.HOSTED) {
+      if (!params.isParentLevelUpgraded()) {
+        // The place where this tablet stores its metadata was not upgraded, 
so do not assign this
+        // tablet yet.
+        return UNASSIGNED;
+      }
+
+      if (tm.getOperationId() != null) {
+        return UNASSIGNED;
+      }
+
+      if (!params.isTableOnline(tm.getTableId())) {
+        return UNASSIGNED;
+      }
+
+      switch (tm.getHostingGoal()) {
+        case NEVER:
+          return UNASSIGNED;
+        case ONDEMAND:
+          if (!tm.getHostingRequested()) {
+            return UNASSIGNED;
+          }
+      }
+
+      TServerInstance dest = params.getMigrations().get(extent);
+      if (dest != null && tm.hasCurrent() && 
!dest.equals(tm.getLocation().getServerInstance())) {
+        return UNASSIGNED;
+      }
+
+      if (currentState == TabletState.HOSTED && balancer != null) {
+        // see if the balancer thinks this tablet needs to be unassigned
+
+        Preconditions.checkArgument(
+            tm.getLocation().getType() == TabletMetadata.LocationType.CURRENT,
+            "Expected current tablet location %s %s", tm.getExtent(), 
tm.getLocation());
+        var tsii = new 
TabletServerIdImpl(tm.getLocation().getServerInstance());
+
+        var resourceGroup = 
params.getResourceGroup(tm.getLocation().getServerInstance());
+
+        if (resourceGroup != null) {
+          var reassign = balancer.needsReassignment(new 
TabletBalancer.CurrentAssignment() {
+            @Override
+            public TabletId getTablet() {
+              return new TabletIdImpl(tm.getExtent());
+            }
+
+            @Override
+            public TabletServerId getTabletServer() {
+              return tsii;
+            }
+
+            @Override
+            public String getResourceGroup() {
+              return resourceGroup;
+            }
+          });
+
+          if (reassign) {
+            return UNASSIGNED;
+          }
+        } else {
+          // A tablet server should always have a resource group, however 
there is a race
+          // conditions where the resource group map was read before a tablet 
server came into
+          // existence. Another possible cause for an absent resource group is 
a bug in accumulo.
+          // In either case do not call the balancer for now with the 
assumption that the resource
+          // group will be available later. Log a message in case it is a bug.

Review Comment:
   Should we just assume the default resource group in this case? In subsequent 
iterations the Tablet would get moved if/when the resource group is known and 
it's not the default.



##########
server/base/src/main/java/org/apache/accumulo/server/util/ListOnlineOnDemandTablets.java:
##########
@@ -79,27 +77,24 @@ public void update(LiveTServerSet current, 
Set<TServerInstance> deleted,
 
     System.out.println("Scanning " + MetadataTable.NAME);
 
-    Range range = TabletsSection.getRange();
-
-    try (TabletManagementScanner metaScanner =
-        new TabletManagementScanner(context, range, MetadataTable.NAME)) {
-      return checkTablets(context, metaScanner, tservers);
+    try (TabletsMetadata metaScanner =
+        
context.getAmple().readTablets().forLevel(Ample.DataLevel.USER).build()) {
+      return checkTablets(context, metaScanner.iterator(), tservers);
     }
   }
 
-  private static int checkTablets(ServerContext context, 
Iterator<TabletManagement> scanner,
+  private static int checkTablets(ServerContext context, 
Iterator<TabletMetadata> scanner,
       LiveTServerSet tservers) {
     int online = 0;
 
     while (scanner.hasNext() && !System.out.checkError()) {
-      final TabletManagement mti = scanner.next();
-      TabletMetadata tabletMetadata = mti.getTabletMetadata();
+      TabletMetadata tabletMetadata = scanner.next();
       Set<TServerInstance> liveTServers = tservers.getCurrentServers();
       TabletState state = TabletState.compute(tabletMetadata, liveTServers);
       if (state == TabletState.HOSTED
-          && mti.getTabletMetadata().getHostingGoal() == 
TabletHostingGoal.ONDEMAND) {
-        System.out.println(
-            mti + " is " + state + "  #walogs:" + 
mti.getTabletMetadata().getLogs().size());
+          && tabletMetadata.getHostingGoal() == TabletHostingGoal.ONDEMAND) {
+        System.out.println(tabletMetadata.getExtent() + " is " + state + "  
#walogs:"

Review Comment:
   Seems like `state` here is always going to be `hosted`. We could just change 
the print statement. Also, maybe a better name for this class is 
`ListHostedOnDemandTablets` as it does not list the unhosted ones. I think it's 
fine to submit a follow-on issue for this if you don't want to address this 
here.



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