You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by "keith-turner (via GitHub)" <gi...@apache.org> on 2023/10/30 17:30:57 UTC
[PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
keith-turner opened a new pull request, #3904:
URL: https://github.com/apache/accumulo/pull/3904
The TabletGroupWatcher uses the TabletManagementIterator to filter tablets that need attention. The TabletMgmtIter had its own custom code to make decision about tablets. This commit modifies the TabletMgmtIterator to use the same code as the TGW when making decisions about tablets. This makes it easier to reason about and change the behavior of the TGW.
In making the TGW and TabletMgmtIter share code a change was also made to how they get information to make decisions. A new class called TabletManagementParameters was introduced that contains an immutable snapshot of the information that both classes need to make decisions. With this change the iterator and TGW are using the same information for a pass over the metadata table, in the past the information was obtained at different times and could have been different due to race conditions. These race conditions were probably not harmful, but removing them makes the code easier to reason about.
Also move some code outside of TGW away from using the TableMgmtIterator. Need to move all code outside of TGW away from using this iterator in order to make the code easier to maintain. Left TODOs in the code about this and will open follow on issues.
--
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
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
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 got 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: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner merged PR #3904:
URL: https://github.com/apache/accumulo/pull/3904
--
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
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3904:
URL: https://github.com/apache/accumulo/pull/3904#discussion_r1376657725
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletGoalState.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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 state = getSystemGoalState(tm, params);
+
+ if (state == TabletGoalState.HOSTED) {
+ if (!params.isParentLevelUpgraded()) {
+ // The place where this tablet stores its metadata was not upgraded, so do not assign this
+ // tablet yet.
+ return TabletGoalState.UNASSIGNED;
+ }
+
+ if (tm.getOperationId() != null) {
+ return TabletGoalState.UNASSIGNED;
+ }
+
+ if (!params.isTableOnline(tm.getTableId())) {
+ return TabletGoalState.UNASSIGNED;
+ }
+
+ switch (tm.getHostingGoal()) {
+ case NEVER:
+ return TabletGoalState.UNASSIGNED;
+ case ONDEMAND:
+ if (!tm.getHostingRequested()) {
+ return TabletGoalState.UNASSIGNED;
+ }
+ }
+
+ TServerInstance dest = params.getMigrations().get(extent);
+ if (dest != null && tm.hasCurrent() && !dest.equals(tm.getLocation().getServerInstance())) {
+ return TabletGoalState.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.
+ log.trace(
+ "Could not find resource group for tserver {}, so did not consult balancer. Assuming this is a temporary race condition.",
+ tm.getLocation().getServerInstance());
+ }
+ }
+
+ if (tm.hasCurrent()
+ && params.getServersToShutdown().contains(tm.getLocation().getServerInstance())) {
+ return TabletGoalState.SUSPENDED;
Review Comment:
#3896 was not merged, but one of the changes I made in there was:
```
if (tgw.canSuspendTablets()) {
return TabletGoalState.SUSPENDED;
} else {
return TabletGoalState.UNASSIGNED;
}
```
This is because the TGW for the Root table returns false for `canSuspendTablets`.
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletManagementParameters.java:
##########
@@ -0,0 +1,244 @@
+/*
+ * 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 static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toSet;
+import static java.util.stream.Collectors.toUnmodifiableMap;
+import static java.util.stream.Collectors.toUnmodifiableSet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Supplier;
+
+import org.apache.accumulo.core.data.AbstractId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.manager.balancer.TabletServerIdImpl;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.core.spi.balancer.data.TabletServerId;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+
+import com.google.common.base.Suppliers;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * An immutable snapshot of the information needed by the TabletGroupWatcher and the
+ * {@link TabletManagementIterator} to make decisions about tablets.
+ */
+public class TabletManagementParameters {
+
+ private final ManagerState managerState;
+ private final Map<Ample.DataLevel,Boolean> parentUpgradeMap;
+ private final Set<TableId> onlineTables;
+ private final Set<TServerInstance> serversToShutdown;
+ private final Map<KeyExtent,TServerInstance> migrations;
+
+ private final Ample.DataLevel level;
+
+ private final Supplier<Map<TServerInstance,String>> resourceGroups;
+ private final Map<String,Set<TServerInstance>> tserverGroups;
+ private final Map<Long,Map<String,String>> compactionHints;
+ private final Set<TServerInstance> onlineTservers;
+
+ public TabletManagementParameters(ManagerState managerState,
+ Map<Ample.DataLevel,Boolean> parentUpgradeMap, Set<TableId> onlineTables,
+ Set<TServerInstance> onlineTservers, Set<TServerInstance> serversToShutdown,
+ Map<KeyExtent,TServerInstance> migrations, Map<String,Set<TServerInstance>> tserverGroups,
+ Ample.DataLevel level, Map<Long,Map<String,String>> compactionHints) {
+ this.managerState = managerState;
+ this.parentUpgradeMap = Map.copyOf(parentUpgradeMap);
+ // TODO could filter by level
+ this.onlineTables = Set.copyOf(onlineTables);
+ this.onlineTservers = Set.copyOf(onlineTservers);
+ this.serversToShutdown = Set.copyOf(serversToShutdown);
+ // TODO could filter by level
+ this.migrations = Map.copyOf(migrations);
+ this.level = level;
+ this.tserverGroups = tserverGroups.entrySet().stream()
+ .collect(toUnmodifiableMap(Map.Entry::getKey, entry -> Set.copyOf(entry.getValue())));
+ this.compactionHints = makeImmutable(compactionHints);
+ this.resourceGroups = Suppliers.memoize(() -> {
+ Map<TServerInstance,String> resourceGroups = new HashMap<>();
+ TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, tservers) -> tservers
+ .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+ return Map.copyOf(resourceGroups);
+ });
+ }
+
+ private TabletManagementParameters(JsonData jdata) {
+ this.managerState = jdata.managerState;
+ this.parentUpgradeMap = Map.copyOf(jdata.parentUpgradeMap);
+ this.onlineTables = jdata.onlineTables.stream().map(TableId::of).collect(toUnmodifiableSet());
+ this.onlineTservers =
+ jdata.onlineTservers.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+ this.serversToShutdown =
+ jdata.serversToShutdown.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+ this.migrations = jdata.migrations.entrySet().stream()
+ .collect(toUnmodifiableMap(entry -> JsonData.strToExtent(entry.getKey()),
+ entry -> new TServerInstance(entry.getValue())));
+ this.level = jdata.level;
+ this.compactionHints = makeImmutable(jdata.compactionHints);
+ this.tserverGroups = jdata.tserverGroups.entrySet().stream().collect(toUnmodifiableMap(
+ Map.Entry::getKey,
+ entry -> entry.getValue().stream().map(TServerInstance::new).collect(toUnmodifiableSet())));
+ this.resourceGroups = Suppliers.memoize(() -> {
+ Map<TServerInstance,String> resourceGroups = new HashMap<>();
+ TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, tservers) -> tservers
+ .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+ return Map.copyOf(resourceGroups);
+ });
+ }
+
+ public ManagerState getManagerState() {
+ return managerState;
+ }
+
+ public boolean isParentLevelUpgraded() {
+ return parentUpgradeMap.get(level);
+ }
+
+ public Set<TServerInstance> getOnlineTsevers() {
Review Comment:
```suggestion
public Set<TServerInstance> getOnlineTServers() {
```
--
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
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3904:
URL: https://github.com/apache/accumulo/pull/3904#discussion_r1377713283
##########
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:
done in d58a025
--
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
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on PR #3904:
URL: https://github.com/apache/accumulo/pull/3904#issuecomment-1786058668
> Please also check that ManagerAssignmentIT is still passing.
@dlmarion that was a good call on running that test. Ran and it blew up. Turned out the best way to fix was to move a lot of code from using the tablet mgmt scanner to using ample. Made that change in e1da6f0. After that change the only thing left using the tabletmgmt iterator is TGW which is good.
--
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
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3904:
URL: https://github.com/apache/accumulo/pull/3904#discussion_r1377680903
##########
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:
With the changes in the PR, the data acquisition for TGW is all corralled into one place. Thinking if we do anything, it should be done there. Then the rest of the code can assume things are consistent. Also, we have made changes to remove some of the race conditions that caused this, but maybe not all. I think for now we should try to track down and understand all race conditions that cause this so we can distinguish bugs from unavoidable race conditions. Thinking for now that this log level should be warn and we should try to triage the cause whenever it triggers and place any mitigations in the data acquisition code in TGW.
--
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
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3904:
URL: https://github.com/apache/accumulo/pull/3904#discussion_r1376720158
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletGoalState.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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 state = getSystemGoalState(tm, params);
+
+ if (state == TabletGoalState.HOSTED) {
+ if (!params.isParentLevelUpgraded()) {
+ // The place where this tablet stores its metadata was not upgraded, so do not assign this
+ // tablet yet.
+ return TabletGoalState.UNASSIGNED;
+ }
+
+ if (tm.getOperationId() != null) {
+ return TabletGoalState.UNASSIGNED;
+ }
+
+ if (!params.isTableOnline(tm.getTableId())) {
+ return TabletGoalState.UNASSIGNED;
+ }
+
+ switch (tm.getHostingGoal()) {
+ case NEVER:
+ return TabletGoalState.UNASSIGNED;
+ case ONDEMAND:
+ if (!tm.getHostingRequested()) {
+ return TabletGoalState.UNASSIGNED;
+ }
+ }
+
+ TServerInstance dest = params.getMigrations().get(extent);
+ if (dest != null && tm.hasCurrent() && !dest.equals(tm.getLocation().getServerInstance())) {
+ return TabletGoalState.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.
+ log.trace(
+ "Could not find resource group for tserver {}, so did not consult balancer. Assuming this is a temporary race condition.",
+ tm.getLocation().getServerInstance());
+ }
+ }
+
+ if (tm.hasCurrent()
+ && params.getServersToShutdown().contains(tm.getLocation().getServerInstance())) {
+ return TabletGoalState.SUSPENDED;
Review Comment:
done in 1f10135
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletManagementParameters.java:
##########
@@ -0,0 +1,244 @@
+/*
+ * 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 static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toSet;
+import static java.util.stream.Collectors.toUnmodifiableMap;
+import static java.util.stream.Collectors.toUnmodifiableSet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Supplier;
+
+import org.apache.accumulo.core.data.AbstractId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.manager.balancer.TabletServerIdImpl;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.core.spi.balancer.data.TabletServerId;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+
+import com.google.common.base.Suppliers;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * An immutable snapshot of the information needed by the TabletGroupWatcher and the
+ * {@link TabletManagementIterator} to make decisions about tablets.
+ */
+public class TabletManagementParameters {
+
+ private final ManagerState managerState;
+ private final Map<Ample.DataLevel,Boolean> parentUpgradeMap;
+ private final Set<TableId> onlineTables;
+ private final Set<TServerInstance> serversToShutdown;
+ private final Map<KeyExtent,TServerInstance> migrations;
+
+ private final Ample.DataLevel level;
+
+ private final Supplier<Map<TServerInstance,String>> resourceGroups;
+ private final Map<String,Set<TServerInstance>> tserverGroups;
+ private final Map<Long,Map<String,String>> compactionHints;
+ private final Set<TServerInstance> onlineTservers;
+
+ public TabletManagementParameters(ManagerState managerState,
+ Map<Ample.DataLevel,Boolean> parentUpgradeMap, Set<TableId> onlineTables,
+ Set<TServerInstance> onlineTservers, Set<TServerInstance> serversToShutdown,
+ Map<KeyExtent,TServerInstance> migrations, Map<String,Set<TServerInstance>> tserverGroups,
+ Ample.DataLevel level, Map<Long,Map<String,String>> compactionHints) {
+ this.managerState = managerState;
+ this.parentUpgradeMap = Map.copyOf(parentUpgradeMap);
+ // TODO could filter by level
+ this.onlineTables = Set.copyOf(onlineTables);
+ this.onlineTservers = Set.copyOf(onlineTservers);
+ this.serversToShutdown = Set.copyOf(serversToShutdown);
+ // TODO could filter by level
+ this.migrations = Map.copyOf(migrations);
+ this.level = level;
+ this.tserverGroups = tserverGroups.entrySet().stream()
+ .collect(toUnmodifiableMap(Map.Entry::getKey, entry -> Set.copyOf(entry.getValue())));
+ this.compactionHints = makeImmutable(compactionHints);
+ this.resourceGroups = Suppliers.memoize(() -> {
+ Map<TServerInstance,String> resourceGroups = new HashMap<>();
+ TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, tservers) -> tservers
+ .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+ return Map.copyOf(resourceGroups);
+ });
+ }
+
+ private TabletManagementParameters(JsonData jdata) {
+ this.managerState = jdata.managerState;
+ this.parentUpgradeMap = Map.copyOf(jdata.parentUpgradeMap);
+ this.onlineTables = jdata.onlineTables.stream().map(TableId::of).collect(toUnmodifiableSet());
+ this.onlineTservers =
+ jdata.onlineTservers.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+ this.serversToShutdown =
+ jdata.serversToShutdown.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+ this.migrations = jdata.migrations.entrySet().stream()
+ .collect(toUnmodifiableMap(entry -> JsonData.strToExtent(entry.getKey()),
+ entry -> new TServerInstance(entry.getValue())));
+ this.level = jdata.level;
+ this.compactionHints = makeImmutable(jdata.compactionHints);
+ this.tserverGroups = jdata.tserverGroups.entrySet().stream().collect(toUnmodifiableMap(
+ Map.Entry::getKey,
+ entry -> entry.getValue().stream().map(TServerInstance::new).collect(toUnmodifiableSet())));
+ this.resourceGroups = Suppliers.memoize(() -> {
+ Map<TServerInstance,String> resourceGroups = new HashMap<>();
+ TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, tservers) -> tservers
+ .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+ return Map.copyOf(resourceGroups);
+ });
+ }
+
+ public ManagerState getManagerState() {
+ return managerState;
+ }
+
+ public boolean isParentLevelUpgraded() {
+ return parentUpgradeMap.get(level);
+ }
+
+ public Set<TServerInstance> getOnlineTsevers() {
Review Comment:
done in 1f10135
--
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
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "EdColeman (via GitHub)" <gi...@apache.org>.
EdColeman commented on code in PR #3904:
URL: https://github.com/apache/accumulo/pull/3904#discussion_r1376695011
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletManagementParameters.java:
##########
@@ -0,0 +1,244 @@
+/*
+ * 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 static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toSet;
+import static java.util.stream.Collectors.toUnmodifiableMap;
+import static java.util.stream.Collectors.toUnmodifiableSet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Supplier;
+
+import org.apache.accumulo.core.data.AbstractId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.manager.balancer.TabletServerIdImpl;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.core.spi.balancer.data.TabletServerId;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+
+import com.google.common.base.Suppliers;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * An immutable snapshot of the information needed by the TabletGroupWatcher and the
+ * {@link TabletManagementIterator} to make decisions about tablets.
+ */
+public class TabletManagementParameters {
+
+ private final ManagerState managerState;
+ private final Map<Ample.DataLevel,Boolean> parentUpgradeMap;
+ private final Set<TableId> onlineTables;
+ private final Set<TServerInstance> serversToShutdown;
+ private final Map<KeyExtent,TServerInstance> migrations;
+
+ private final Ample.DataLevel level;
+
+ private final Supplier<Map<TServerInstance,String>> resourceGroups;
+ private final Map<String,Set<TServerInstance>> tserverGroups;
+ private final Map<Long,Map<String,String>> compactionHints;
+ private final Set<TServerInstance> onlineTservers;
+
+ public TabletManagementParameters(ManagerState managerState,
+ Map<Ample.DataLevel,Boolean> parentUpgradeMap, Set<TableId> onlineTables,
+ Set<TServerInstance> onlineTservers, Set<TServerInstance> serversToShutdown,
+ Map<KeyExtent,TServerInstance> migrations, Map<String,Set<TServerInstance>> tserverGroups,
+ Ample.DataLevel level, Map<Long,Map<String,String>> compactionHints) {
+ this.managerState = managerState;
+ this.parentUpgradeMap = Map.copyOf(parentUpgradeMap);
+ // TODO could filter by level
+ this.onlineTables = Set.copyOf(onlineTables);
+ this.onlineTservers = Set.copyOf(onlineTservers);
+ this.serversToShutdown = Set.copyOf(serversToShutdown);
+ // TODO could filter by level
+ this.migrations = Map.copyOf(migrations);
+ this.level = level;
+ this.tserverGroups = tserverGroups.entrySet().stream()
+ .collect(toUnmodifiableMap(Map.Entry::getKey, entry -> Set.copyOf(entry.getValue())));
+ this.compactionHints = makeImmutable(compactionHints);
+ this.resourceGroups = Suppliers.memoize(() -> {
+ Map<TServerInstance,String> resourceGroups = new HashMap<>();
+ TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, tservers) -> tservers
+ .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+ return Map.copyOf(resourceGroups);
+ });
+ }
+
+ private TabletManagementParameters(JsonData jdata) {
+ this.managerState = jdata.managerState;
+ this.parentUpgradeMap = Map.copyOf(jdata.parentUpgradeMap);
+ this.onlineTables = jdata.onlineTables.stream().map(TableId::of).collect(toUnmodifiableSet());
+ this.onlineTservers =
+ jdata.onlineTservers.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+ this.serversToShutdown =
+ jdata.serversToShutdown.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+ this.migrations = jdata.migrations.entrySet().stream()
+ .collect(toUnmodifiableMap(entry -> JsonData.strToExtent(entry.getKey()),
+ entry -> new TServerInstance(entry.getValue())));
+ this.level = jdata.level;
+ this.compactionHints = makeImmutable(jdata.compactionHints);
+ this.tserverGroups = jdata.tserverGroups.entrySet().stream().collect(toUnmodifiableMap(
+ Map.Entry::getKey,
+ entry -> entry.getValue().stream().map(TServerInstance::new).collect(toUnmodifiableSet())));
+ this.resourceGroups = Suppliers.memoize(() -> {
+ Map<TServerInstance,String> resourceGroups = new HashMap<>();
+ TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, tservers) -> tservers
+ .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+ return Map.copyOf(resourceGroups);
+ });
+ }
+
+ public ManagerState getManagerState() {
+ return managerState;
+ }
+
+ public boolean isParentLevelUpgraded() {
+ return parentUpgradeMap.get(level);
+ }
+
+ public Set<TServerInstance> getOnlineTsevers() {
+ return onlineTservers;
+ }
+
+ public Set<TServerInstance> getServersToShutdown() {
+ return serversToShutdown;
+ }
+
+ public boolean isTableOnline(TableId tableId) {
+ return onlineTables.contains(tableId);
+ }
+
+ public Map<KeyExtent,TServerInstance> getMigrations() {
+ return migrations;
+ }
+
+ public Ample.DataLevel getLevel() {
+ return level;
+ }
+
+ public String getResourceGroup(TServerInstance tserver) {
+ return resourceGroups.get().get(tserver);
+ }
+
+ public Map<String,Set<TServerInstance>> getGroupedTservers() {
+ return tserverGroups;
+ }
+
+ public Set<TableId> getOnlineTables() {
+ return onlineTables;
+ }
+
+ public Map<Long,Map<String,String>> getCompactionHints() {
+ return compactionHints;
+ }
+
+ private static Map<Long,Map<String,String>>
+ makeImmutable(Map<Long,Map<String,String>> compactionHints) {
+ var copy = new HashMap<Long,Map<String,String>>();
+ compactionHints.forEach((ftxid, hints) -> copy.put(ftxid, Map.copyOf(hints)));
+ return Collections.unmodifiableMap(copy);
+ }
+
+ private static class JsonData {
Review Comment:
Would something less generic than JsonData help when it is declared / used? Maybe TMParmsJson or even ParamsJason?
--
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
Re: [PR] Refactors tablet mgmt iterator to share decision code w/ TGW [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3904:
URL: https://github.com/apache/accumulo/pull/3904#discussion_r1376704011
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletManagementParameters.java:
##########
@@ -0,0 +1,244 @@
+/*
+ * 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 static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toSet;
+import static java.util.stream.Collectors.toUnmodifiableMap;
+import static java.util.stream.Collectors.toUnmodifiableSet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Supplier;
+
+import org.apache.accumulo.core.data.AbstractId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.manager.balancer.TabletServerIdImpl;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.core.spi.balancer.data.TabletServerId;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+
+import com.google.common.base.Suppliers;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * An immutable snapshot of the information needed by the TabletGroupWatcher and the
+ * {@link TabletManagementIterator} to make decisions about tablets.
+ */
+public class TabletManagementParameters {
+
+ private final ManagerState managerState;
+ private final Map<Ample.DataLevel,Boolean> parentUpgradeMap;
+ private final Set<TableId> onlineTables;
+ private final Set<TServerInstance> serversToShutdown;
+ private final Map<KeyExtent,TServerInstance> migrations;
+
+ private final Ample.DataLevel level;
+
+ private final Supplier<Map<TServerInstance,String>> resourceGroups;
+ private final Map<String,Set<TServerInstance>> tserverGroups;
+ private final Map<Long,Map<String,String>> compactionHints;
+ private final Set<TServerInstance> onlineTservers;
+
+ public TabletManagementParameters(ManagerState managerState,
+ Map<Ample.DataLevel,Boolean> parentUpgradeMap, Set<TableId> onlineTables,
+ Set<TServerInstance> onlineTservers, Set<TServerInstance> serversToShutdown,
+ Map<KeyExtent,TServerInstance> migrations, Map<String,Set<TServerInstance>> tserverGroups,
+ Ample.DataLevel level, Map<Long,Map<String,String>> compactionHints) {
+ this.managerState = managerState;
+ this.parentUpgradeMap = Map.copyOf(parentUpgradeMap);
+ // TODO could filter by level
+ this.onlineTables = Set.copyOf(onlineTables);
+ this.onlineTservers = Set.copyOf(onlineTservers);
+ this.serversToShutdown = Set.copyOf(serversToShutdown);
+ // TODO could filter by level
+ this.migrations = Map.copyOf(migrations);
+ this.level = level;
+ this.tserverGroups = tserverGroups.entrySet().stream()
+ .collect(toUnmodifiableMap(Map.Entry::getKey, entry -> Set.copyOf(entry.getValue())));
+ this.compactionHints = makeImmutable(compactionHints);
+ this.resourceGroups = Suppliers.memoize(() -> {
+ Map<TServerInstance,String> resourceGroups = new HashMap<>();
+ TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, tservers) -> tservers
+ .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+ return Map.copyOf(resourceGroups);
+ });
+ }
+
+ private TabletManagementParameters(JsonData jdata) {
+ this.managerState = jdata.managerState;
+ this.parentUpgradeMap = Map.copyOf(jdata.parentUpgradeMap);
+ this.onlineTables = jdata.onlineTables.stream().map(TableId::of).collect(toUnmodifiableSet());
+ this.onlineTservers =
+ jdata.onlineTservers.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+ this.serversToShutdown =
+ jdata.serversToShutdown.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+ this.migrations = jdata.migrations.entrySet().stream()
+ .collect(toUnmodifiableMap(entry -> JsonData.strToExtent(entry.getKey()),
+ entry -> new TServerInstance(entry.getValue())));
+ this.level = jdata.level;
+ this.compactionHints = makeImmutable(jdata.compactionHints);
+ this.tserverGroups = jdata.tserverGroups.entrySet().stream().collect(toUnmodifiableMap(
+ Map.Entry::getKey,
+ entry -> entry.getValue().stream().map(TServerInstance::new).collect(toUnmodifiableSet())));
+ this.resourceGroups = Suppliers.memoize(() -> {
+ Map<TServerInstance,String> resourceGroups = new HashMap<>();
+ TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, tservers) -> tservers
+ .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+ return Map.copyOf(resourceGroups);
+ });
+ }
+
+ public ManagerState getManagerState() {
+ return managerState;
+ }
+
+ public boolean isParentLevelUpgraded() {
+ return parentUpgradeMap.get(level);
+ }
+
+ public Set<TServerInstance> getOnlineTsevers() {
+ return onlineTservers;
+ }
+
+ public Set<TServerInstance> getServersToShutdown() {
+ return serversToShutdown;
+ }
+
+ public boolean isTableOnline(TableId tableId) {
+ return onlineTables.contains(tableId);
+ }
+
+ public Map<KeyExtent,TServerInstance> getMigrations() {
+ return migrations;
+ }
+
+ public Ample.DataLevel getLevel() {
+ return level;
+ }
+
+ public String getResourceGroup(TServerInstance tserver) {
+ return resourceGroups.get().get(tserver);
+ }
+
+ public Map<String,Set<TServerInstance>> getGroupedTservers() {
+ return tserverGroups;
+ }
+
+ public Set<TableId> getOnlineTables() {
+ return onlineTables;
+ }
+
+ public Map<Long,Map<String,String>> getCompactionHints() {
+ return compactionHints;
+ }
+
+ private static Map<Long,Map<String,String>>
+ makeImmutable(Map<Long,Map<String,String>> compactionHints) {
+ var copy = new HashMap<Long,Map<String,String>>();
+ compactionHints.forEach((ftxid, hints) -> copy.put(ftxid, Map.copyOf(hints)));
+ return Collections.unmodifiableMap(copy);
+ }
+
+ private static class JsonData {
Review Comment:
IMO that's not necessary because its a private inner class and is only used inside the class and never seen outside of the class.
--
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