keith-turner commented on code in PR #3904: URL: https://github.com/apache/accumulo/pull/3904#discussion_r1377715633
########## 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: adlusted log level and comment in 5f7a3dd. Eventually when we get to more focused testing of the elasticity branch, we can triage errors and warns seen in the logs during testing. If we see this we can look into it. -- 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]
