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/05/18 19:26:26 UTC
[GitHub] [accumulo] dlmarion opened a new pull request, #3409: Modified TabletGroupWatcher to use TabletMetadata
dlmarion opened a new pull request, #3409:
URL: https://github.com/apache/accumulo/pull/3409
Replaced TabletStateChangeIterator with TabletMetadataIterator which returns TabletMetadata objects instead of TabletLocationState objects.
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204613782
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,452 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ // ELASTICITY_TODO passing the unassignemnt request as part of the migrations is a hack. Was
+ // not sure of the entire unassignment request approach and did not want to push it further
+ // into the code.
+ ManagerTabletInfoIterator.setMigrations(tabletChange,
+ Sets.union(state.migrationsSnapshot(), state.getUnassignmentRequest()));
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ String managerStateOptionValue = options.get(MANAGER_STATE_OPTION);
+ try {
+ managerState = ManagerState.valueOf(managerStateOptionValue);
+ } catch (RuntimeException ex) {
+ if (managerStateOptionValue != null) {
+ LOG.error("Unable to decode managerState {}", managerStateOptionValue);
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
Review Comment:
Renamed in 9153726
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202330484
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/AbstractTabletStateStore.java:
##########
@@ -108,51 +108,51 @@ public void setFutureLocations(Collection<Assignment> assignments)
}
@Override
- public void unassign(Collection<TabletLocationState> tablets,
+ public void unassign(Collection<TabletMetadata> tablets,
Map<TServerInstance,List<Path>> logsForDeadServers) throws DistributedStoreException {
unassign(tablets, logsForDeadServers, -1);
}
@Override
- public void suspend(Collection<TabletLocationState> tablets,
+ public void suspend(Collection<TabletMetadata> tablets,
Map<TServerInstance,List<Path>> logsForDeadServers, long suspensionTimestamp)
throws DistributedStoreException {
unassign(tablets, logsForDeadServers, suspensionTimestamp);
}
protected abstract void processSuspension(Ample.ConditionalTabletMutator tabletMutator,
- TabletLocationState tls, long suspensionTimestamp);
+ TabletMetadata tm, long suspensionTimestamp);
- private void unassign(Collection<TabletLocationState> tablets,
+ private void unassign(Collection<TabletMetadata> tablets,
Map<TServerInstance,List<Path>> logsForDeadServers, long suspensionTimestamp)
throws DistributedStoreException {
try (var tabletsMutator = ample.conditionallyMutateTablets()) {
- for (TabletLocationState tls : tablets) {
- var tabletMutator = tabletsMutator.mutateTablet(tls.extent).requireAbsentOperation();
+ for (TabletMetadata tm : tablets) {
+ var tabletMutator = tabletsMutator.mutateTablet(tm.getExtent()).requireAbsentOperation();
- if (tls.hasCurrent()) {
- tabletMutator.requireLocation(tls.current);
+ if (tm.hasCurrent()) {
+ tabletMutator.requireLocation(tm.getLocation());
ManagerMetadataUtil.updateLastForAssignmentMode(context, tabletMutator,
- tls.current.getServerInstance(), tls.last);
- tabletMutator.deleteLocation(tls.current);
+ tm.getLocation().getServerInstance(), tm.getLast());
+ tabletMutator.deleteLocation(tm.getLocation());
if (logsForDeadServers != null) {
- List<Path> logs = logsForDeadServers.get(tls.current.getServerInstance());
+ List<Path> logs = logsForDeadServers.get(tm.getLocation().getServerInstance());
if (logs != null) {
for (Path log : logs) {
- LogEntry entry = new LogEntry(tls.extent, 0, log.toString());
+ LogEntry entry = new LogEntry(tm.getExtent(), 0, log.toString());
tabletMutator.putWal(entry);
}
}
}
}
- if (tls.hasFuture()) {
- tabletMutator.requireLocation(tls.future);
- tabletMutator.deleteLocation(tls.future);
+ if (tm.getLocation().getType().equals(LocationType.FUTURE)) {
Review Comment:
If tm has no location could get an NPE here. The old code seemed to handle the case of no current or future location. Not sure in general if the code should handle this case, just noticed the diff in behavior.
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
Review Comment:
Another type later in the code used the word Management. Made me think this could be called `TabletManagementIterator`.
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
Review Comment:
Since a collection is passed in, it would be better to pass in an empty set instead of null and remove the null handling from this code. This behavior was carried forward from the old code, so not something to worry about in this PR there is already enough changes. It would be a nice follow on improvement as the null handling cold mask bugs.
##########
server/manager/src/main/java/org/apache/accumulo/manager/Manager.java:
##########
@@ -888,12 +889,12 @@ private long updateStatus() {
} else if (!serversToShutdown.isEmpty()) {
log.debug("not balancing while shutting down servers {}", serversToShutdown);
} else {
- for (TabletGroupWatcher tgw : watchers) {
- if (!tgw.isSameTserversAsLastScan(currentServers)) {
- log.debug("not balancing just yet, as collection of live tservers is in flux");
- return DEFAULT_WAIT_FOR_WATCHER;
- }
- }
+ // for (TabletGroupWatcher tgw : watchers) {
Review Comment:
What is going on here?
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ reasonsToReturnThisTablet.clear();
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
Review Comment:
I do not understand why the following conditions result in bad state. Can you explain?
`onlineTables == null || current == null || managerState != ManagerState.NORMAL`
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ reasonsToReturnThisTablet.clear();
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
+ || tm.isFutureAndCurrentLocationSet()) {
+ // no need to check everything, we are in a known state where we want to return everything.
+ reasonsToReturnThisTablet.add(ManagementAction.BAD_STATE);
+ return true;
+ }
+
+ // we always want data about merges
+ final MergeInfo merge = merges.get(tm.getTableId());
+ if (merge != null) {
+ // could make this smarter by only returning if the tablet is involved in the merge
+ reasonsToReturnThisTablet.add(ManagementAction.IS_MERGING);
+ }
+
+ // always return the information for migrating tablets
+ if (migrations.contains(tm.getExtent())) {
+ reasonsToReturnThisTablet.add(ManagementAction.IS_MIGRATING);
+ }
+
+ if (shouldReturnDueToLocation(tm, onlineTables, current, debug)) {
+ reasonsToReturnThisTablet.add(ManagementAction.NEEDS_LOCATION_UPDATE);
+ }
+
+ final long splitThreshold =
+ ConfigurationTypeHelper.getFixedMemoryAsBytes(this.env.getPluginEnv()
+ .getConfiguration(tm.getTableId()).get(Property.TABLE_SPLIT_THRESHOLD.getKey()));
+ if (shouldReturnDueToSplit(tm, splitThreshold)) {
+ reasonsToReturnThisTablet.add(ManagementAction.NEEDS_SPLITTING);
+ }
+
+ // TODO: Add compaction logic
+
+ if (!reasonsToReturnThisTablet.isEmpty()) {
+ return true;
Review Comment:
Not sure how it would turn out, but wondering if it would be a bit cleaner if the calling code just checked if the set was empty or not instead of this method returning a boolean. I think that would clean up this method, but may make the calling code a bit less concise.
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
Review Comment:
```suggestion
LOG.trace("Returning extent {} with reasons: {}", tm.getExtent(), reasonsToReturnThisTablet);
```
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
Review Comment:
If the topKey and topValue are set to null in consume, may be able to drop the next() and seek() overrides.
```suggestion
@Override
protected void consume() throws IOException {
topKey = null;
topValue = null;
```
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/MetaDataTableScanner.java:
##########
@@ -134,84 +87,19 @@ public boolean hasNext() {
}
@Override
- public TabletLocationState next() {
+ public ManagerTabletInfo next() {
if (closed.get()) {
throw new NoSuchElementException(this.getClass().getSimpleName() + " is closed");
}
+ Entry<Key,Value> e = iter.next();
try {
- Entry<Key,Value> e = iter.next();
- return createTabletLocationState(e.getKey(), e.getValue());
- } catch (IOException | BadLocationStateException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- public static TabletLocationState createTabletLocationState(Key k, Value v)
- throws IOException, BadLocationStateException {
- final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
- KeyExtent extent = null;
- Location future = null;
- Location current = null;
- Location last = null;
- SuspendingTServer suspend = null;
- long lastTimestamp = 0;
- List<Collection<String>> walogs = new ArrayList<>();
- boolean chopped = false;
- TabletHostingGoal goal = TabletHostingGoal.ONDEMAND;
- boolean onDemandHostingRequested = false;
-
- for (Entry<Key,Value> entry : decodedRow.entrySet()) {
-
- Key key = entry.getKey();
- Text row = key.getRow();
- Text cf = key.getColumnFamily();
- Text cq = key.getColumnQualifier();
-
- if (cf.compareTo(FutureLocationColumnFamily.NAME) == 0) {
- Location location = Location.future(new TServerInstance(entry.getValue(), cq));
- if (future != null) {
- throw new BadLocationStateException("found two assignments for the same extent " + row
- + ": " + future + " and " + location, row);
- }
- future = location;
- } else if (cf.compareTo(CurrentLocationColumnFamily.NAME) == 0) {
- Location location = Location.current(new TServerInstance(entry.getValue(), cq));
- if (current != null) {
- throw new BadLocationStateException("found two locations for the same extent " + row
- + ": " + current + " and " + location, row);
- }
- current = location;
- } else if (cf.compareTo(LogColumnFamily.NAME) == 0) {
- String[] split = entry.getValue().toString().split("\\|")[0].split(";");
- walogs.add(Arrays.asList(split));
- } else if (cf.compareTo(LastLocationColumnFamily.NAME) == 0) {
- if (lastTimestamp < entry.getKey().getTimestamp()) {
- last = Location.last(new TServerInstance(entry.getValue(), cq));
- lastTimestamp = entry.getKey().getTimestamp();
- }
- } else if (cf.compareTo(ChoppedColumnFamily.NAME) == 0) {
- chopped = true;
- } else if (TabletColumnFamily.PREV_ROW_COLUMN.equals(cf, cq)) {
- extent = KeyExtent.fromMetaPrevRow(entry);
- } else if (SuspendLocationColumn.SUSPEND_COLUMN.equals(cf, cq)) {
- suspend = SuspendingTServer.fromValue(entry.getValue());
- } else if (HostingColumnFamily.GOAL_COLUMN.equals(cf, cq)) {
- goal = TabletHostingGoalUtil.fromValue(entry.getValue());
- } else if (HostingColumnFamily.REQUESTED_COLUMN.equals(cf, cq)) {
- onDemandHostingRequested = true;
- }
- }
- if (extent == null) {
- String msg = "No prev-row for key extent " + decodedRow;
- log.error(msg);
- throw new BadLocationStateException(msg, k.getRow());
- }
- // Override the goal for root and metadata table, should be always
- if (extent.isMeta()) {
- goal = TabletHostingGoal.ALWAYS;
+ ManagerTabletInfo tmi = ManagerTabletInfoIterator.decode(e);
+ log.debug("Returning metadata tablet, extent: {}, hostingGoal: {}",
Review Comment:
```suggestion
log.trace("Returning metadata tablet, extent: {}, hostingGoal: {}",
```
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
Review Comment:
```suggestion
LOG.trace("No reason to return this extent {}, continuing", tm.getExtent());
```
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/MetaDataTableScanner.java:
##########
@@ -20,49 +20,25 @@
import java.io.IOException;
import java.lang.ref.Cleaner.Cleanable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
-import java.util.SortedMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.accumulo.core.client.BatchScanner;
-import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.client.ScannerBase;
import org.apache.accumulo.core.client.TableNotFoundException;
-import org.apache.accumulo.core.client.admin.TabletHostingGoal;
import org.apache.accumulo.core.clientImpl.ClientContext;
-import org.apache.accumulo.core.clientImpl.TabletHostingGoalUtil;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.dataImpl.KeyExtent;
-import org.apache.accumulo.core.iterators.user.WholeRowIterator;
-import org.apache.accumulo.core.metadata.SuspendingTServer;
-import org.apache.accumulo.core.metadata.TServerInstance;
-import org.apache.accumulo.core.metadata.TabletLocationState;
-import org.apache.accumulo.core.metadata.TabletLocationState.BadLocationStateException;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
-import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.util.cleaner.CleanerUtil;
-import org.apache.hadoop.io.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class MetaDataTableScanner implements ClosableIterator<TabletLocationState> {
Review Comment:
This name is very generic. Could be TabletManagementScanner
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
Review Comment:
Could name this something like `getManagmentActions()`, `computeManagmentActions()`, `evaluteManagmentActions()`. The name of the method is misleading in isolation, but it does actually flow with if stmt where its used.
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
Review Comment:
```suggestion
LOG.trace("Evaluating extent: {}", tm);
```
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletStateStore.java:
##########
@@ -25,16 +25,17 @@
import org.apache.accumulo.core.clientImpl.ClientContext;
import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
import org.apache.accumulo.core.metadata.TServerInstance;
-import org.apache.accumulo.core.metadata.TabletLocationState;
import org.apache.accumulo.core.metadata.schema.Ample.DataLevel;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
import org.apache.accumulo.server.ServerContext;
import org.apache.hadoop.fs.Path;
/**
* Interface for storing information about tablet assignments. There are three implementations:
*/
-public interface TabletStateStore extends Iterable<TabletLocationState> {
+public interface TabletStateStore extends Iterable<ManagerTabletInfo> {
Review Comment:
A lot of the reasons behind the creation of this abstraction are going away. This used to abstract writing to metadata tablet vs zookeeper, but a lot of that has been more generally pushed into ample. The changes in this PR remove the TabletLocationState class that used to go with this interface. This interface used to abstract the computation of TabletLocationState. Wondering if this interface is on its way to becoming a vestigial artifact that could be removed and result in an overall simplification of the code. Maybe it still has a place, not sure.
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ZooTabletStateStore.java:
##########
@@ -42,16 +39,14 @@ class ZooTabletStateStore extends AbstractTabletStateStore implements TabletStat
private static final Logger log = LoggerFactory.getLogger(ZooTabletStateStore.class);
private final Ample ample;
- private final ClientContext context;
ZooTabletStateStore(ClientContext context) {
super(context);
- this.context = context;
this.ample = context.getAmple();
}
@Override
- public ClosableIterator<TabletLocationState> iterator() {
+ public ClosableIterator<ManagerTabletInfo> iterator() {
Review Comment:
In the past this method could always return a tablet location state even if there was nothing to do. Now I think it should only return something if there is work to do. Also thinking it should somehow call the code in ManagerTabletInfoIterator. This does not compile, but I worked up the following as a proof of concept of what I was thinking.
```java
@Override
public ClosableIterator<ManagerTabletInfo> iterator() {
List<ManagerTabletInfo> mtis = List.of();
TabletMetadata tabletMetadata = ample.readTablet(RootTable.EXTENT, ReadConsistency.EVENTUAL);
Set<ManagementAction> reasons = new HashSet<>();
if(ManagerTabletInfoIterator.sendToTabletServer(tabletMetadata, reasons)){
mtis = List.of(new ManagerTabletInfo(reasons, tabletMetadata));
}
var iterator = mtis.iterator();
return new ClosableIterator<>() {
private final TabletMetadata tabletMetadata = ample.readTablet(RootTable.EXTENT, ReadConsistency.EVENTUAL);
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public ManagerTabletInfo next() {
return iterator.next();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
@Override
public void close() {}
};
}
```
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202696603
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
Review Comment:
Addressed in 5f28395
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/MetaDataTableScanner.java:
##########
@@ -134,84 +87,19 @@ public boolean hasNext() {
}
@Override
- public TabletLocationState next() {
+ public ManagerTabletInfo next() {
if (closed.get()) {
throw new NoSuchElementException(this.getClass().getSimpleName() + " is closed");
}
+ Entry<Key,Value> e = iter.next();
try {
- Entry<Key,Value> e = iter.next();
- return createTabletLocationState(e.getKey(), e.getValue());
- } catch (IOException | BadLocationStateException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- public static TabletLocationState createTabletLocationState(Key k, Value v)
- throws IOException, BadLocationStateException {
- final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
- KeyExtent extent = null;
- Location future = null;
- Location current = null;
- Location last = null;
- SuspendingTServer suspend = null;
- long lastTimestamp = 0;
- List<Collection<String>> walogs = new ArrayList<>();
- boolean chopped = false;
- TabletHostingGoal goal = TabletHostingGoal.ONDEMAND;
- boolean onDemandHostingRequested = false;
-
- for (Entry<Key,Value> entry : decodedRow.entrySet()) {
-
- Key key = entry.getKey();
- Text row = key.getRow();
- Text cf = key.getColumnFamily();
- Text cq = key.getColumnQualifier();
-
- if (cf.compareTo(FutureLocationColumnFamily.NAME) == 0) {
- Location location = Location.future(new TServerInstance(entry.getValue(), cq));
- if (future != null) {
- throw new BadLocationStateException("found two assignments for the same extent " + row
- + ": " + future + " and " + location, row);
- }
- future = location;
- } else if (cf.compareTo(CurrentLocationColumnFamily.NAME) == 0) {
- Location location = Location.current(new TServerInstance(entry.getValue(), cq));
- if (current != null) {
- throw new BadLocationStateException("found two locations for the same extent " + row
- + ": " + current + " and " + location, row);
- }
- current = location;
- } else if (cf.compareTo(LogColumnFamily.NAME) == 0) {
- String[] split = entry.getValue().toString().split("\\|")[0].split(";");
- walogs.add(Arrays.asList(split));
- } else if (cf.compareTo(LastLocationColumnFamily.NAME) == 0) {
- if (lastTimestamp < entry.getKey().getTimestamp()) {
- last = Location.last(new TServerInstance(entry.getValue(), cq));
- lastTimestamp = entry.getKey().getTimestamp();
- }
- } else if (cf.compareTo(ChoppedColumnFamily.NAME) == 0) {
- chopped = true;
- } else if (TabletColumnFamily.PREV_ROW_COLUMN.equals(cf, cq)) {
- extent = KeyExtent.fromMetaPrevRow(entry);
- } else if (SuspendLocationColumn.SUSPEND_COLUMN.equals(cf, cq)) {
- suspend = SuspendingTServer.fromValue(entry.getValue());
- } else if (HostingColumnFamily.GOAL_COLUMN.equals(cf, cq)) {
- goal = TabletHostingGoalUtil.fromValue(entry.getValue());
- } else if (HostingColumnFamily.REQUESTED_COLUMN.equals(cf, cq)) {
- onDemandHostingRequested = true;
- }
- }
- if (extent == null) {
- String msg = "No prev-row for key extent " + decodedRow;
- log.error(msg);
- throw new BadLocationStateException(msg, k.getRow());
- }
- // Override the goal for root and metadata table, should be always
- if (extent.isMeta()) {
- goal = TabletHostingGoal.ALWAYS;
+ ManagerTabletInfo tmi = ManagerTabletInfoIterator.decode(e);
+ log.debug("Returning metadata tablet, extent: {}, hostingGoal: {}",
Review Comment:
Addressed in 5f28395
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204611171
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
Review Comment:
Renamed to TabletManagementIterator in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202694876
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
Review Comment:
Addressed in 5f28395
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
Review Comment:
Addressed in 5f28395
--
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
[GitHub] [accumulo] dlmarion commented on pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#issuecomment-1559810979
I have no issue renaming things. Let's get the changes fleshed out first, then we can rename.
--
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
[GitHub] [accumulo] dlmarion merged pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion merged PR #3409:
URL: https://github.com/apache/accumulo/pull/3409
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202755038
##########
server/manager/src/main/java/org/apache/accumulo/manager/TabletGroupWatcher.java:
##########
@@ -219,13 +240,24 @@ public void run() {
// towards their goal
iter = store.iterator();
while (iter.hasNext()) {
- TabletLocationState tls = iter.next();
- if (tls == null) {
+ final ManagerTabletInfo mti = iter.next();
+ if (mti == null) {
+ LOG.debug("ManagerTabletInfoIterator returned null ManagerTabletInfo");
Review Comment:
Is returning null expected?
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204613191
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,452 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
Review Comment:
Removed duplicate method in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204615289
##########
core/src/main/java/org/apache/accumulo/core/metadata/schema/RootTabletMetadata.java:
##########
@@ -156,10 +159,11 @@ public SortedMap<Key,Value> toKeyValues() {
* Convert this class to a {@link TabletMetadata}
*/
public TabletMetadata toTabletMetadata() {
- // use a stream so we don't have to re-sort in a new TreeMap<Key,Value> structure
- Stream<SimpleImmutableEntry<Key,Value>> entries = getKeyValues();
- return TabletMetadata.convertRow(entries.iterator(),
- EnumSet.allOf(TabletMetadata.ColumnType.class), false);
+ TreeMap<Key,Value> entries = new TreeMap<>();
+ getKeyValues().forEach(entry -> entries.put(entry.getKey(), entry.getValue()));
+ ManagerTabletInfo.addActions(entries, Set.of(ManagementAction.NEEDS_LOCATION_UPDATE));
Review Comment:
Removed in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#issuecomment-1561757597
I'm going to fix the failed build issue, and then merge this to `elasticity` so that we can continue to build off of it. There are two failing ITs IIRC, MergeStateIT and AssignLocationModeIT, we can fix them up later.
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204614515
##########
server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletMetadataIteratorTest.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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 org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.COMPACT_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.FLUSH_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.TIME_COLUMN;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.fate.FateTxId;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.metadata.StoredTabletFile;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.BulkFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ClonedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.DataFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ScanFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.tabletserver.log.LogEntry;
+import org.apache.hadoop.io.Text;
+import org.junit.jupiter.api.Test;
+
+public class TabletMetadataIteratorTest {
Review Comment:
Renamed to TabletManagementTest in 9153726
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202660783
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletMetadataIterator.java:
##########
@@ -0,0 +1,450 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.VirtualMetadataColumns.MaintenanceRequired;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.VirtualMetadataColumns.MaintenanceRequired.Reasons;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class TabletMetadataIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TabletMetadataIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+ private static final EnumSet<ColumnType> CONFIGURED_COLUMNS = EnumSet.of(ColumnType.PREV_ROW,
+ ColumnType.LOCATION, ColumnType.SUSPEND, ColumnType.LOGS, ColumnType.CHOPPED,
+ ColumnType.HOSTING_GOAL, ColumnType.HOSTING_REQUESTED, ColumnType.FILES, ColumnType.LAST);
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "tabletMetadataIterator", TabletMetadataIterator.class);
+ if (state != null) {
+ TabletMetadataIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ TabletMetadataIterator.setOnlineTables(tabletChange, state.onlineTables());
+ TabletMetadataIterator.setMerges(tabletChange, state.merges());
+ TabletMetadataIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ TabletMetadataIterator.setManagerState(tabletChange, state.getManagerState());
+ TabletMetadataIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static TabletMetadata decode(Entry<Key,Value> e) throws IOException {
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(e.getKey(), e.getValue());
+ return TabletMetadata.convertRow(decodedRow.entrySet().iterator(), CONFIGURED_COLUMNS, false,
+ true);
+ }
Review Comment:
You used the word Management in another type name and I like that. I was trying to think of how to work the word Management into this type name. Was thinking of things like `TabletManagementInfo`, `TabletManagementAction`, `TableManagementAlert`... not really sure about these, but those were things I thought of.
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202859920
##########
core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchReaderIterator.java:
##########
@@ -285,21 +285,22 @@ private ScanServerData binRanges(ClientTabletCache clientTabletCache, List<Range
break;
} else {
// tried to only do table state checks when failures.size() == ranges.size(), however this
- // did
- // not work because nothing ever invalidated entries in the tabletLocator cache... so even
- // though
- // the table was deleted the tablet locator entries for the deleted table were not
- // cleared... so
- // need to always do the check when failures occur
+ // did not work because nothing ever invalidated entries in the tabletLocator cache... so
+ // even though the table was deleted the tablet locator entries for the deleted table
+ // were not cleared. So need to always do the check when failures occur
if (failures.size() >= lastFailureSize) {
context.requireNotDeleted(tableId);
context.requireNotOffline(tableId, tableName);
}
lastFailureSize = failures.size();
+ log.debug(
Review Comment:
Thanks, another artifact from debugging failed tests
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202851096
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ZooTabletStateStore.java:
##########
@@ -42,16 +39,14 @@ class ZooTabletStateStore extends AbstractTabletStateStore implements TabletStat
private static final Logger log = LoggerFactory.getLogger(ZooTabletStateStore.class);
private final Ample ample;
- private final ClientContext context;
ZooTabletStateStore(ClientContext context) {
super(context);
- this.context = context;
this.ample = context.getAmple();
}
@Override
- public ClosableIterator<TabletLocationState> iterator() {
+ public ClosableIterator<ManagerTabletInfo> iterator() {
Review Comment:
I spent some time on this and was unable to determine a good way to create Set<TServerInstance> to represent the current set of TabletServers from the ZooTabletStateStore. They come from the `CurrentState` object, which in the typical case, is the `Manager`.
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202894162
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ZooTabletStateStore.java:
##########
@@ -42,16 +39,14 @@ class ZooTabletStateStore extends AbstractTabletStateStore implements TabletStat
private static final Logger log = LoggerFactory.getLogger(ZooTabletStateStore.class);
private final Ample ample;
- private final ClientContext context;
ZooTabletStateStore(ClientContext context) {
super(context);
- this.context = context;
this.ample = context.getAmple();
}
@Override
- public ClosableIterator<TabletLocationState> iterator() {
+ public ClosableIterator<ManagerTabletInfo> iterator() {
Review Comment:
Looking at the ZooTabletStateStore code it takes a ClientContext, so trying to something from the manager would not be worthwhile if its not necessary.
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204617641
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
Review Comment:
I removed the null checks in TabletManagementIterator by making the collections final, and then adding the parsed information to them, in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204618840
##########
server/manager/src/main/java/org/apache/accumulo/manager/TabletGroupWatcher.java:
##########
@@ -219,13 +240,24 @@ public void run() {
// towards their goal
iter = store.iterator();
while (iter.hasNext()) {
- TabletLocationState tls = iter.next();
- if (tls == null) {
+ final ManagerTabletInfo mti = iter.next();
+ if (mti == null) {
+ LOG.debug("ManagerTabletInfoIterator returned null ManagerTabletInfo");
Review Comment:
I modified this to throw an IllegalStateException in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204616064
##########
core/src/test/java/org/apache/accumulo/core/metadata/schema/TabletMetadataTest.java:
##########
@@ -116,7 +116,7 @@ public void testAllColumns() {
SortedMap<Key,Value> rowMap = toRowMap(mutation);
TabletMetadata tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(),
- EnumSet.allOf(ColumnType.class), true);
+ EnumSet.allOf(ColumnType.class), true, false);
Review Comment:
Test added in 9153726
--
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
[GitHub] [accumulo] keith-turner commented on pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#issuecomment-1559916769
> I have no issue renaming things. Let's get the changes fleshed out first, then we can rename.
I finished looking over the changes. I am going to look into the null server sets and see if I can understand what is going on with those.
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204612458
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/MetaDataTableScanner.java:
##########
@@ -20,49 +20,25 @@
import java.io.IOException;
import java.lang.ref.Cleaner.Cleanable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
-import java.util.SortedMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.accumulo.core.client.BatchScanner;
-import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.client.ScannerBase;
import org.apache.accumulo.core.client.TableNotFoundException;
-import org.apache.accumulo.core.client.admin.TabletHostingGoal;
import org.apache.accumulo.core.clientImpl.ClientContext;
-import org.apache.accumulo.core.clientImpl.TabletHostingGoalUtil;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.dataImpl.KeyExtent;
-import org.apache.accumulo.core.iterators.user.WholeRowIterator;
-import org.apache.accumulo.core.metadata.SuspendingTServer;
-import org.apache.accumulo.core.metadata.TServerInstance;
-import org.apache.accumulo.core.metadata.TabletLocationState;
-import org.apache.accumulo.core.metadata.TabletLocationState.BadLocationStateException;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
-import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.util.cleaner.CleanerUtil;
-import org.apache.hadoop.io.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class MetaDataTableScanner implements ClosableIterator<TabletLocationState> {
Review Comment:
Renamed to TabletManagementScanner in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204618015
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ // ELASTICITY_TODO passing the unassignemnt request as part of the migrations is a hack. Was
+ // not sure of the entire unassignment request approach and did not want to push it further
+ // into the code.
+ ManagerTabletInfoIterator.setMigrations(tabletChange,
+ Sets.union(state.migrationsSnapshot(), state.getUnassignmentRequest()));
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ String managerStateOptionValue = options.get(MANAGER_STATE_OPTION);
+ try {
+ managerState = ManagerState.valueOf(managerStateOptionValue);
+ } catch (RuntimeException ex) {
+ if (managerStateOptionValue != null) {
+ LOG.error("Unable to decode managerState {}", managerStateOptionValue);
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ protected void consume() throws IOException {
+ topKey = null;
+ topValue = null;
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.trace("Evaluating extent: {}", tm);
+ reasonsToReturnThisTablet.clear();
+ computeTabletManagementActions(tm, reasonsToReturnThisTablet);
+ if (!reasonsToReturnThisTablet.isEmpty()) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.trace("Returning extent {} with reasons: {}", tm.getExtent(),
+ reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.trace("No reason to return extent {}, continuing", tm.getExtent());
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private void computeTabletManagementActions(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
+ || tm.isFutureAndCurrentLocationSet()) {
+ // no need to check everything, we are in a known state where we want to return everything.
+ reasonsToReturnThisTablet.add(ManagementAction.BAD_STATE);
+ return;
+ }
Review Comment:
Implemented in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202696000
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
Review Comment:
Addressed in 5f28395
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ reasonsToReturnThisTablet.clear();
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
+ || tm.isFutureAndCurrentLocationSet()) {
+ // no need to check everything, we are in a known state where we want to return everything.
+ reasonsToReturnThisTablet.add(ManagementAction.BAD_STATE);
+ return true;
+ }
+
+ // we always want data about merges
+ final MergeInfo merge = merges.get(tm.getTableId());
+ if (merge != null) {
+ // could make this smarter by only returning if the tablet is involved in the merge
+ reasonsToReturnThisTablet.add(ManagementAction.IS_MERGING);
+ }
+
+ // always return the information for migrating tablets
+ if (migrations.contains(tm.getExtent())) {
+ reasonsToReturnThisTablet.add(ManagementAction.IS_MIGRATING);
+ }
+
+ if (shouldReturnDueToLocation(tm, onlineTables, current, debug)) {
+ reasonsToReturnThisTablet.add(ManagementAction.NEEDS_LOCATION_UPDATE);
+ }
+
+ final long splitThreshold =
+ ConfigurationTypeHelper.getFixedMemoryAsBytes(this.env.getPluginEnv()
+ .getConfiguration(tm.getTableId()).get(Property.TABLE_SPLIT_THRESHOLD.getKey()));
+ if (shouldReturnDueToSplit(tm, splitThreshold)) {
+ reasonsToReturnThisTablet.add(ManagementAction.NEEDS_SPLITTING);
+ }
+
+ // TODO: Add compaction logic
+
+ if (!reasonsToReturnThisTablet.isEmpty()) {
+ return true;
Review Comment:
Addressed in 5f28395
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202695539
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
Review Comment:
Addressed in 5f28395
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202673897
##########
server/manager/src/main/java/org/apache/accumulo/manager/Manager.java:
##########
@@ -888,12 +889,12 @@ private long updateStatus() {
} else if (!serversToShutdown.isEmpty()) {
log.debug("not balancing while shutting down servers {}", serversToShutdown);
} else {
- for (TabletGroupWatcher tgw : watchers) {
- if (!tgw.isSameTserversAsLastScan(currentServers)) {
- log.debug("not balancing just yet, as collection of live tservers is in flux");
- return DEFAULT_WAIT_FOR_WATCHER;
- }
- }
+ // for (TabletGroupWatcher tgw : watchers) {
Review Comment:
Good catch. I think I commented this out while dealing with a test.
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202868843
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
Review Comment:
Think we can remove the null check. This set comes from Manager.onlineTabletServers() which I linked in another comment and that never returns null.
```suggestion
List<String> servers = new ArrayList<>();
for (TServerInstance server : goodServers) {
servers.add(server.getHostPortSession());
}
cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
```
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
Review Comment:
Maybe just expect this to be set to simplify other code.
```suggestion
```
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ // ELASTICITY_TODO passing the unassignemnt request as part of the migrations is a hack. Was
+ // not sure of the entire unassignment request approach and did not want to push it further
+ // into the code.
+ ManagerTabletInfoIterator.setMigrations(tabletChange,
+ Sets.union(state.migrationsSnapshot(), state.getUnassignmentRequest()));
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ String managerStateOptionValue = options.get(MANAGER_STATE_OPTION);
+ try {
+ managerState = ManagerState.valueOf(managerStateOptionValue);
+ } catch (RuntimeException ex) {
+ if (managerStateOptionValue != null) {
+ LOG.error("Unable to decode managerState {}", managerStateOptionValue);
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ protected void consume() throws IOException {
+ topKey = null;
+ topValue = null;
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.trace("Evaluating extent: {}", tm);
+ reasonsToReturnThisTablet.clear();
+ computeTabletManagementActions(tm, reasonsToReturnThisTablet);
+ if (!reasonsToReturnThisTablet.isEmpty()) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.trace("Returning extent {} with reasons: {}", tm.getExtent(),
+ reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.trace("No reason to return extent {}, continuing", tm.getExtent());
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private void computeTabletManagementActions(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
+ || tm.isFutureAndCurrentLocationSet()) {
+ // no need to check everything, we are in a known state where we want to return everything.
+ reasonsToReturnThisTablet.add(ManagementAction.BAD_STATE);
+ return;
+ }
Review Comment:
With the changes to assume we always have servers and tables could do the following. Also looked at the manager state it has some things related to shutdown. I think the old iterator just returned everything when it was not normal, will that work with these new changes?
```suggestion
if(managerState != ManagerState.NORMAL){
// when manager is in the process of starting up or shutting down return everything.
reasonsToReturnThisTablet.add(ManagementAction.NEEDS_LOCATION_UPDATE);
return;
}
if ( tm.isFutureAndCurrentLocationSet()) {
// no need to check everything, we are in a known state where we want to return everything.
reasonsToReturnThisTablet.add(ManagementAction.BAD_STATE);
return;
}
```
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
Review Comment:
```suggestion
cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
```
I looked around in the code for things that implement CurrentState and I did not see anything passing null for this for current servers. The following is the code I looked at in the manager that gets these sets.
https://github.com/apache/accumulo/blob/ce54fb3903749d30b6ccb92038280dfb160dcbb9/server/base/src/main/java/org/apache/accumulo/server/manager/LiveTServerSet.java#L392
https://github.com/apache/accumulo/blob/ce54fb3903749d30b6ccb92038280dfb160dcbb9/server/manager/src/main/java/org/apache/accumulo/manager/Manager.java#L1661-L1687
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
Review Comment:
Maybe just expect this to be set to simplify other code.
```suggestion
```
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202652586
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ reasonsToReturnThisTablet.clear();
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
Review Comment:
It's a carry-over from [here](https://github.com/apache/accumulo/blob/main/server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletStateChangeIterator.java#L170).
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202796029
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ reasonsToReturnThisTablet.clear();
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
Review Comment:
Wonder if we have any ITs relate to safe mode.
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202807225
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
Review Comment:
Null may be intentional here as discussed in other comments. Going to look into it a bit and see if that is the case.
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202891676
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ZooTabletStateStore.java:
##########
@@ -42,16 +39,14 @@ class ZooTabletStateStore extends AbstractTabletStateStore implements TabletStat
private static final Logger log = LoggerFactory.getLogger(ZooTabletStateStore.class);
private final Ample ample;
- private final ClientContext context;
ZooTabletStateStore(ClientContext context) {
super(context);
- this.context = context;
this.ample = context.getAmple();
}
@Override
- public ClosableIterator<TabletLocationState> iterator() {
+ public ClosableIterator<ManagerTabletInfo> iterator() {
Review Comment:
ok, so if this code always returns NEEDS_LOCATION_UPDATE for the root tablet then the manager code will look at the tablets locations and the live tserver set and see if there is actually anything to do? If that is the case then its fine the way it was, maybe add a comment about why NEEDS_LOCATION_UPDATE is always returned.
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204613481
##########
server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletMetadataIteratorTest.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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 org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.COMPACT_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.FLUSH_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.TIME_COLUMN;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.fate.FateTxId;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.metadata.StoredTabletFile;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.BulkFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ClonedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.DataFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ScanFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.tabletserver.log.LogEntry;
+import org.apache.hadoop.io.Text;
+import org.junit.jupiter.api.Test;
+
+public class TabletMetadataIteratorTest {
+
+ private SortedMap<Key,Value> toRowMap(Mutation mutation) {
+ SortedMap<Key,Value> rowMap = new TreeMap<>();
+ mutation.getUpdates().forEach(cu -> {
+ Key k = new Key(mutation.getRow(), cu.getColumnFamily(), cu.getColumnQualifier(),
+ cu.getTimestamp());
+ Value v = new Value(cu.getValue());
+ rowMap.put(k, v);
+ });
+ return rowMap;
+ }
+
+ private SortedMap<Key,Value> createMetadataEntryKV() {
+ KeyExtent extent = new KeyExtent(TableId.of("5"), new Text("df"), new Text("da"));
+
+ Mutation mutation = TabletColumnFamily.createPrevRowMutation(extent);
+
+ COMPACT_COLUMN.put(mutation, new Value("5"));
+ DIRECTORY_COLUMN.put(mutation, new Value("t-0001757"));
+ FLUSH_COLUMN.put(mutation, new Value("6"));
+ TIME_COLUMN.put(mutation, new Value("M123456789"));
+
+ String bf1 = "hdfs://nn1/acc/tables/1/t-0001/bf1";
+ String bf2 = "hdfs://nn1/acc/tables/1/t-0001/bf2";
+ mutation.at().family(BulkFileColumnFamily.NAME).qualifier(bf1).put(FateTxId.formatTid(56));
+ mutation.at().family(BulkFileColumnFamily.NAME).qualifier(bf2).put(FateTxId.formatTid(59));
+
+ mutation.at().family(ClonedColumnFamily.NAME).qualifier("").put("OK");
+
+ DataFileValue dfv1 = new DataFileValue(555, 23);
+ StoredTabletFile tf1 = new StoredTabletFile("hdfs://nn1/acc/tables/1/t-0001/df1.rf");
+ StoredTabletFile tf2 = new StoredTabletFile("hdfs://nn1/acc/tables/1/t-0001/df2.rf");
+ mutation.at().family(DataFileColumnFamily.NAME).qualifier(tf1.getMetaUpdateDelete())
+ .put(dfv1.encode());
+ DataFileValue dfv2 = new DataFileValue(234, 13);
+ mutation.at().family(DataFileColumnFamily.NAME).qualifier(tf2.getMetaUpdateDelete())
+ .put(dfv2.encode());
+
+ mutation.at().family(CurrentLocationColumnFamily.NAME).qualifier("s001").put("server1:8555");
+
+ mutation.at().family(LastLocationColumnFamily.NAME).qualifier("s000").put("server2:8555");
+
+ LogEntry le1 = new LogEntry(extent, 55, "lf1");
+ mutation.at().family(le1.getColumnFamily()).qualifier(le1.getColumnQualifier())
+ .timestamp(le1.timestamp).put(le1.getValue());
+ LogEntry le2 = new LogEntry(extent, 57, "lf2");
+ mutation.at().family(le2.getColumnFamily()).qualifier(le2.getColumnQualifier())
+ .timestamp(le2.timestamp).put(le2.getValue());
+
+ StoredTabletFile sf1 = new StoredTabletFile("hdfs://nn1/acc/tables/1/t-0001/sf1.rf");
+ StoredTabletFile sf2 = new StoredTabletFile("hdfs://nn1/acc/tables/1/t-0001/sf2.rf");
+ mutation.at().family(ScanFileColumnFamily.NAME).qualifier(sf1.getMetaUpdateDelete()).put("");
+ mutation.at().family(ScanFileColumnFamily.NAME).qualifier(sf2.getMetaUpdateDelete()).put("");
+
+ return toRowMap(mutation);
+
+ }
+
+ @Test
+ public void testEncodeDecodeWithReasons() throws Exception {
+ final Set<ManagementAction> reasons =
Review Comment:
renamed in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204615650
##########
core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java:
##########
@@ -505,10 +529,24 @@ public static <E extends Entry<Key,Value>> TabletMetadata convertRow(Iterator<E>
BulkFileColumnFamily.getBulkLoadTid(val));
break;
case CurrentLocationColumnFamily.STR_NAME:
- te.setLocationOnce(val, qual, LocationType.CURRENT);
+ try {
+ te.setLocationOnce(val, qual, LocationType.CURRENT);
+ } catch (IllegalStateException e) {
+ te.futureAndCurrentLocationSet = true;
+ if (!suppressLocationError) {
+ throw e;
+ }
+ }
Review Comment:
Moved the error suppression logic in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202849667
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ reasonsToReturnThisTablet.clear();
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
Review Comment:
ok, sounds like we need to add more states. For online tables, I only assume it's an issue if the root and metadata tables are not online.
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202524520
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ZooTabletStateStore.java:
##########
@@ -42,16 +39,14 @@ class ZooTabletStateStore extends AbstractTabletStateStore implements TabletStat
private static final Logger log = LoggerFactory.getLogger(ZooTabletStateStore.class);
private final Ample ample;
- private final ClientContext context;
ZooTabletStateStore(ClientContext context) {
super(context);
- this.context = context;
this.ample = context.getAmple();
}
@Override
- public ClosableIterator<TabletLocationState> iterator() {
+ public ClosableIterator<ManagerTabletInfo> iterator() {
Review Comment:
In the past this method could always return a tablet location state even if there was nothing to do. Now I think it should only return something if there is work to do. Also thinking it should somehow call the code in ManagerTabletInfoIterator. This does not compile, but I worked up the following as a proof of concept of what I was thinking.
```java
@Override
public ClosableIterator<ManagerTabletInfo> iterator() {
List<ManagerTabletInfo> mtis = List.of();
TabletMetadata tabletMetadata = ample.readTablet(RootTable.EXTENT, ReadConsistency.EVENTUAL);
Set<ManagementAction> reasons = new HashSet<>();
if(ManagerTabletInfoIterator.sendToManager(tabletMetadata, reasons)){
mtis = List.of(new ManagerTabletInfo(reasons, tabletMetadata));
}
var iterator = mtis.iterator();
return new ClosableIterator<>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public ManagerTabletInfo next() {
return iterator.next();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
@Override
public void close() {}
};
}
```
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202853763
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,452 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
Review Comment:
Yes, I think that should work.
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202857679
##########
server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletMetadataImposterTest.java:
##########
@@ -18,171 +18,171 @@
*/
package org.apache.accumulo.server.manager.state;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.createNiceMock;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Collection;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import org.apache.accumulo.core.client.admin.TabletHostingGoal;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.metadata.TServerInstance;
-import org.apache.accumulo.core.metadata.TabletLocationState;
import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
-import org.apache.hadoop.io.Text;
-import org.junit.jupiter.api.BeforeAll;
+import org.apache.accumulo.core.tabletserver.log.LogEntry;
+import org.easymock.EasyMock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class CachedTabletStateTest {
- private static final Collection<String> innerWalogs = new java.util.HashSet<>();
- private static final Collection<Collection<String>> walogs = new java.util.HashSet<>();
-
- @BeforeAll
- public static void setUpClass() {
- walogs.add(innerWalogs);
- innerWalogs.add("somelog");
- }
+public class TabletMetadataImposterTest {
private KeyExtent keyExtent;
private Location future;
private Location current;
private Location last;
- private TabletLocationState tls;
+ private TabletMetadata tls;
+ private List<LogEntry> walogs = new ArrayList<>();
@BeforeEach
public void setUp() {
- keyExtent = createMock(KeyExtent.class);
- future = Location.future(createMock(TServerInstance.class));
- current = Location.current(createMock(TServerInstance.class));
- last = Location.last(createMock(TServerInstance.class));
+ keyExtent = createNiceMock(KeyExtent.class);
+ TServerInstance futureInstance = createNiceMock(TServerInstance.class);
+ future = Location.future(futureInstance);
+ TServerInstance currentInstance = createNiceMock(TServerInstance.class);
+ current = Location.current(currentInstance);
+ TServerInstance lastInstance = createNiceMock(TServerInstance.class);
+ last = Location.last(lastInstance);
+ walogs.clear();
+ walogs.add(new LogEntry(keyExtent, 1234L, "some file name"));
+ EasyMock.replay(keyExtent, futureInstance, currentInstance, lastInstance);
}
@Test
public void testConstruction_NoFuture() throws Exception {
- tls = new TabletLocationState(keyExtent, null, current, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, current, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
- assertSame(keyExtent, tls.extent);
- assertNull(tls.future);
- assertSame(current, tls.current);
- assertSame(last, tls.last);
- assertSame(walogs, tls.walogs);
- assertTrue(tls.chopped);
+ assertSame(keyExtent, tls.getExtent());
+ assertTrue(tls.hasCurrent());
+ assertSame(current, tls.getLocation());
+ assertSame(last, tls.getLast());
+ assertSame(walogs, tls.getLogs());
+ assertTrue(tls.hasChopped());
}
@Test
public void testConstruction_NoCurrent() throws Exception {
- tls = new TabletLocationState(keyExtent, future, null, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, future, null, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
- assertSame(keyExtent, tls.extent);
- assertSame(future, tls.future);
- assertNull(tls.current);
- assertSame(last, tls.last);
- assertSame(walogs, tls.walogs);
- assertTrue(tls.chopped);
+ assertSame(keyExtent, tls.getExtent());
+ assertSame(future, tls.getLocation());
+ assertFalse(tls.hasCurrent());
+ assertSame(last, tls.getLast());
+ assertSame(walogs, tls.getLogs());
+ assertTrue(tls.hasChopped());
}
@Test
public void testConstruction_FutureAndCurrent() {
- expect(keyExtent.toMetaRow()).andReturn(new Text("entry"));
- replay(keyExtent);
- var e = assertThrows(TabletLocationState.BadLocationStateException.class,
- () -> new TabletLocationState(keyExtent, future, current, last, null, walogs, true,
- TabletHostingGoal.ONDEMAND, false));
- assertEquals(new Text("entry"), e.getEncodedEndRow());
+ tls = new TabletMetadataImposter(keyExtent, future, current, last, null, walogs, true,
+ TabletHostingGoal.ONDEMAND, false);
+ assertTrue(tls.isFutureAndCurrentLocationSet());
}
@Test
public void testConstruction_NoFuture_NoWalogs() throws Exception {
- tls = new TabletLocationState(keyExtent, null, current, last, null, null, true,
+ tls = new TabletMetadataImposter(keyExtent, null, current, last, null, null, true,
TabletHostingGoal.ONDEMAND, false);
- assertNotNull(tls.walogs);
- assertEquals(0, tls.walogs.size());
+ assertNotNull(tls.getLogs());
+ assertEquals(0, tls.getLogs().size());
}
@Test
public void testGetServer_Current() throws Exception {
- tls = new TabletLocationState(keyExtent, null, current, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, current, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
+ assertTrue(tls.hasCurrent());
assertSame(current, tls.getLocation());
}
@Test
public void testGetServer_Future() throws Exception {
- tls = new TabletLocationState(keyExtent, future, null, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, future, null, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
+ assertFalse(tls.hasCurrent());
assertSame(future, tls.getLocation());
}
@Test
public void testGetServer_Last() throws Exception {
- tls = new TabletLocationState(keyExtent, null, null, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, null, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
- assertSame(last, tls.getLocation());
+ assertFalse(tls.hasCurrent());
+ assertNull(tls.getLocation());
+ assertSame(last, tls.getLast());
}
@Test
public void testGetServer_None() throws Exception {
- tls = new TabletLocationState(keyExtent, null, null, null, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, null, null, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
+ assertFalse(tls.hasCurrent());
assertNull(tls.getLocation());
}
@Test
public void testGetState_Unassigned1() throws Exception {
- tls = new TabletLocationState(keyExtent, null, null, null, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, null, null, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
- assertEquals(TabletState.UNASSIGNED, tls.getState(null));
+ assertEquals(TabletState.UNASSIGNED, tls.getTabletState(null));
Review Comment:
Yeah, TabletMetadataImposter and it's test, are derived from the old TabletLocationState objects.
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202691175
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,452 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
Review Comment:
```suggestion
```
Could this method be dropped and TabletMetadata.getTabletState() used instead?
##########
core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchReaderIterator.java:
##########
@@ -285,21 +285,22 @@ private ScanServerData binRanges(ClientTabletCache clientTabletCache, List<Range
break;
} else {
// tried to only do table state checks when failures.size() == ranges.size(), however this
- // did
- // not work because nothing ever invalidated entries in the tabletLocator cache... so even
- // though
- // the table was deleted the tablet locator entries for the deleted table were not
- // cleared... so
- // need to always do the check when failures occur
+ // did not work because nothing ever invalidated entries in the tabletLocator cache... so
+ // even though the table was deleted the tablet locator entries for the deleted table
+ // were not cleared. So need to always do the check when failures occur
if (failures.size() >= lastFailureSize) {
context.requireNotDeleted(tableId);
context.requireNotOffline(tableId, tableName);
}
lastFailureSize = failures.size();
+ log.debug(
Review Comment:
Is this meant to be left here?
##########
server/manager/src/main/java/org/apache/accumulo/manager/TabletGroupWatcher.java:
##########
@@ -219,13 +240,24 @@ public void run() {
// towards their goal
iter = store.iterator();
while (iter.hasNext()) {
- TabletLocationState tls = iter.next();
- if (tls == null) {
+ final ManagerTabletInfo mti = iter.next();
+ if (mti == null) {
+ LOG.debug("ManagerTabletInfoIterator returned null ManagerTabletInfo");
Review Comment:
Is it returning null expected?
##########
core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java:
##########
@@ -379,6 +384,20 @@ public boolean getHostingRequested() {
return onDemandHostingRequested;
}
+ @Override
+ public String toString() {
Review Comment:
This is really nice to have.
##########
server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletMetadataIteratorTest.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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 org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.COMPACT_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.FLUSH_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.TIME_COLUMN;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.fate.FateTxId;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.metadata.StoredTabletFile;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.BulkFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ClonedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.DataFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ScanFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.tabletserver.log.LogEntry;
+import org.apache.hadoop.io.Text;
+import org.junit.jupiter.api.Test;
+
+public class TabletMetadataIteratorTest {
+
+ private SortedMap<Key,Value> toRowMap(Mutation mutation) {
+ SortedMap<Key,Value> rowMap = new TreeMap<>();
+ mutation.getUpdates().forEach(cu -> {
+ Key k = new Key(mutation.getRow(), cu.getColumnFamily(), cu.getColumnQualifier(),
+ cu.getTimestamp());
+ Value v = new Value(cu.getValue());
+ rowMap.put(k, v);
+ });
+ return rowMap;
+ }
+
+ private SortedMap<Key,Value> createMetadataEntryKV() {
+ KeyExtent extent = new KeyExtent(TableId.of("5"), new Text("df"), new Text("da"));
+
+ Mutation mutation = TabletColumnFamily.createPrevRowMutation(extent);
+
+ COMPACT_COLUMN.put(mutation, new Value("5"));
+ DIRECTORY_COLUMN.put(mutation, new Value("t-0001757"));
+ FLUSH_COLUMN.put(mutation, new Value("6"));
+ TIME_COLUMN.put(mutation, new Value("M123456789"));
+
+ String bf1 = "hdfs://nn1/acc/tables/1/t-0001/bf1";
+ String bf2 = "hdfs://nn1/acc/tables/1/t-0001/bf2";
+ mutation.at().family(BulkFileColumnFamily.NAME).qualifier(bf1).put(FateTxId.formatTid(56));
+ mutation.at().family(BulkFileColumnFamily.NAME).qualifier(bf2).put(FateTxId.formatTid(59));
+
+ mutation.at().family(ClonedColumnFamily.NAME).qualifier("").put("OK");
+
+ DataFileValue dfv1 = new DataFileValue(555, 23);
+ StoredTabletFile tf1 = new StoredTabletFile("hdfs://nn1/acc/tables/1/t-0001/df1.rf");
+ StoredTabletFile tf2 = new StoredTabletFile("hdfs://nn1/acc/tables/1/t-0001/df2.rf");
+ mutation.at().family(DataFileColumnFamily.NAME).qualifier(tf1.getMetaUpdateDelete())
+ .put(dfv1.encode());
+ DataFileValue dfv2 = new DataFileValue(234, 13);
+ mutation.at().family(DataFileColumnFamily.NAME).qualifier(tf2.getMetaUpdateDelete())
+ .put(dfv2.encode());
+
+ mutation.at().family(CurrentLocationColumnFamily.NAME).qualifier("s001").put("server1:8555");
+
+ mutation.at().family(LastLocationColumnFamily.NAME).qualifier("s000").put("server2:8555");
+
+ LogEntry le1 = new LogEntry(extent, 55, "lf1");
+ mutation.at().family(le1.getColumnFamily()).qualifier(le1.getColumnQualifier())
+ .timestamp(le1.timestamp).put(le1.getValue());
+ LogEntry le2 = new LogEntry(extent, 57, "lf2");
+ mutation.at().family(le2.getColumnFamily()).qualifier(le2.getColumnQualifier())
+ .timestamp(le2.timestamp).put(le2.getValue());
+
+ StoredTabletFile sf1 = new StoredTabletFile("hdfs://nn1/acc/tables/1/t-0001/sf1.rf");
+ StoredTabletFile sf2 = new StoredTabletFile("hdfs://nn1/acc/tables/1/t-0001/sf2.rf");
+ mutation.at().family(ScanFileColumnFamily.NAME).qualifier(sf1.getMetaUpdateDelete()).put("");
+ mutation.at().family(ScanFileColumnFamily.NAME).qualifier(sf2.getMetaUpdateDelete()).put("");
+
+ return toRowMap(mutation);
+
+ }
+
+ @Test
+ public void testEncodeDecodeWithReasons() throws Exception {
+ final Set<ManagementAction> reasons =
Review Comment:
```suggestion
final Set<ManagementAction> actions =
```
##########
server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletMetadataIteratorTest.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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 org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.COMPACT_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.FLUSH_COLUMN;
+import static org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.TIME_COLUMN;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.fate.FateTxId;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.metadata.StoredTabletFile;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.BulkFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ClonedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.DataFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ScanFileColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.tabletserver.log.LogEntry;
+import org.apache.hadoop.io.Text;
+import org.junit.jupiter.api.Test;
+
+public class TabletMetadataIteratorTest {
Review Comment:
Test focuses on code in ManagerTabletInfo, maybe it should be in the test name
```suggestion
public class ManagerTabletInfoTest {
```
##########
server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletMetadataImposterTest.java:
##########
@@ -18,171 +18,171 @@
*/
package org.apache.accumulo.server.manager.state;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.createNiceMock;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Collection;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import org.apache.accumulo.core.client.admin.TabletHostingGoal;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.metadata.TServerInstance;
-import org.apache.accumulo.core.metadata.TabletLocationState;
import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
-import org.apache.hadoop.io.Text;
-import org.junit.jupiter.api.BeforeAll;
+import org.apache.accumulo.core.tabletserver.log.LogEntry;
+import org.easymock.EasyMock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class CachedTabletStateTest {
- private static final Collection<String> innerWalogs = new java.util.HashSet<>();
- private static final Collection<Collection<String>> walogs = new java.util.HashSet<>();
-
- @BeforeAll
- public static void setUpClass() {
- walogs.add(innerWalogs);
- innerWalogs.add("somelog");
- }
+public class TabletMetadataImposterTest {
private KeyExtent keyExtent;
private Location future;
private Location current;
private Location last;
- private TabletLocationState tls;
+ private TabletMetadata tls;
+ private List<LogEntry> walogs = new ArrayList<>();
@BeforeEach
public void setUp() {
- keyExtent = createMock(KeyExtent.class);
- future = Location.future(createMock(TServerInstance.class));
- current = Location.current(createMock(TServerInstance.class));
- last = Location.last(createMock(TServerInstance.class));
+ keyExtent = createNiceMock(KeyExtent.class);
+ TServerInstance futureInstance = createNiceMock(TServerInstance.class);
+ future = Location.future(futureInstance);
+ TServerInstance currentInstance = createNiceMock(TServerInstance.class);
+ current = Location.current(currentInstance);
+ TServerInstance lastInstance = createNiceMock(TServerInstance.class);
+ last = Location.last(lastInstance);
+ walogs.clear();
+ walogs.add(new LogEntry(keyExtent, 1234L, "some file name"));
+ EasyMock.replay(keyExtent, futureInstance, currentInstance, lastInstance);
}
@Test
public void testConstruction_NoFuture() throws Exception {
- tls = new TabletLocationState(keyExtent, null, current, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, current, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
- assertSame(keyExtent, tls.extent);
- assertNull(tls.future);
- assertSame(current, tls.current);
- assertSame(last, tls.last);
- assertSame(walogs, tls.walogs);
- assertTrue(tls.chopped);
+ assertSame(keyExtent, tls.getExtent());
+ assertTrue(tls.hasCurrent());
+ assertSame(current, tls.getLocation());
+ assertSame(last, tls.getLast());
+ assertSame(walogs, tls.getLogs());
+ assertTrue(tls.hasChopped());
}
@Test
public void testConstruction_NoCurrent() throws Exception {
- tls = new TabletLocationState(keyExtent, future, null, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, future, null, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
- assertSame(keyExtent, tls.extent);
- assertSame(future, tls.future);
- assertNull(tls.current);
- assertSame(last, tls.last);
- assertSame(walogs, tls.walogs);
- assertTrue(tls.chopped);
+ assertSame(keyExtent, tls.getExtent());
+ assertSame(future, tls.getLocation());
+ assertFalse(tls.hasCurrent());
+ assertSame(last, tls.getLast());
+ assertSame(walogs, tls.getLogs());
+ assertTrue(tls.hasChopped());
}
@Test
public void testConstruction_FutureAndCurrent() {
- expect(keyExtent.toMetaRow()).andReturn(new Text("entry"));
- replay(keyExtent);
- var e = assertThrows(TabletLocationState.BadLocationStateException.class,
- () -> new TabletLocationState(keyExtent, future, current, last, null, walogs, true,
- TabletHostingGoal.ONDEMAND, false));
- assertEquals(new Text("entry"), e.getEncodedEndRow());
+ tls = new TabletMetadataImposter(keyExtent, future, current, last, null, walogs, true,
+ TabletHostingGoal.ONDEMAND, false);
+ assertTrue(tls.isFutureAndCurrentLocationSet());
}
@Test
public void testConstruction_NoFuture_NoWalogs() throws Exception {
- tls = new TabletLocationState(keyExtent, null, current, last, null, null, true,
+ tls = new TabletMetadataImposter(keyExtent, null, current, last, null, null, true,
TabletHostingGoal.ONDEMAND, false);
- assertNotNull(tls.walogs);
- assertEquals(0, tls.walogs.size());
+ assertNotNull(tls.getLogs());
+ assertEquals(0, tls.getLogs().size());
}
@Test
public void testGetServer_Current() throws Exception {
- tls = new TabletLocationState(keyExtent, null, current, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, current, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
+ assertTrue(tls.hasCurrent());
assertSame(current, tls.getLocation());
}
@Test
public void testGetServer_Future() throws Exception {
- tls = new TabletLocationState(keyExtent, future, null, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, future, null, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
+ assertFalse(tls.hasCurrent());
assertSame(future, tls.getLocation());
}
@Test
public void testGetServer_Last() throws Exception {
- tls = new TabletLocationState(keyExtent, null, null, last, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, null, last, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
- assertSame(last, tls.getLocation());
+ assertFalse(tls.hasCurrent());
+ assertNull(tls.getLocation());
+ assertSame(last, tls.getLast());
}
@Test
public void testGetServer_None() throws Exception {
- tls = new TabletLocationState(keyExtent, null, null, null, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, null, null, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
+ assertFalse(tls.hasCurrent());
assertNull(tls.getLocation());
}
@Test
public void testGetState_Unassigned1() throws Exception {
- tls = new TabletLocationState(keyExtent, null, null, null, null, walogs, true,
+ tls = new TabletMetadataImposter(keyExtent, null, null, null, null, walogs, true,
TabletHostingGoal.ONDEMAND, false);
- assertEquals(TabletState.UNASSIGNED, tls.getState(null));
+ assertEquals(TabletState.UNASSIGNED, tls.getTabletState(null));
Review Comment:
This is a preexisting problem. I tried running this test locally and noticed the suspended state is not covered by this test.
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,452 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ // ELASTICITY_TODO passing the unassignemnt request as part of the migrations is a hack. Was
+ // not sure of the entire unassignment request approach and did not want to push it further
+ // into the code.
+ ManagerTabletInfoIterator.setMigrations(tabletChange,
+ Sets.union(state.migrationsSnapshot(), state.getUnassignmentRequest()));
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ String managerStateOptionValue = options.get(MANAGER_STATE_OPTION);
+ try {
+ managerState = ManagerState.valueOf(managerStateOptionValue);
+ } catch (RuntimeException ex) {
+ if (managerStateOptionValue != null) {
+ LOG.error("Unable to decode managerState {}", managerStateOptionValue);
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
Review Comment:
Could rename this to align with the new type name.
```suggestion
final Set<ManagementAction> actions= new HashSet<>();
```
##########
core/src/main/java/org/apache/accumulo/core/metadata/schema/RootTabletMetadata.java:
##########
@@ -156,10 +159,11 @@ public SortedMap<Key,Value> toKeyValues() {
* Convert this class to a {@link TabletMetadata}
*/
public TabletMetadata toTabletMetadata() {
- // use a stream so we don't have to re-sort in a new TreeMap<Key,Value> structure
- Stream<SimpleImmutableEntry<Key,Value>> entries = getKeyValues();
- return TabletMetadata.convertRow(entries.iterator(),
- EnumSet.allOf(TabletMetadata.ColumnType.class), false);
+ TreeMap<Key,Value> entries = new TreeMap<>();
+ getKeyValues().forEach(entry -> entries.put(entry.getKey(), entry.getValue()));
+ ManagerTabletInfo.addActions(entries, Set.of(ManagementAction.NEEDS_LOCATION_UPDATE));
Review Comment:
Is this change still needed?
##########
core/src/test/java/org/apache/accumulo/core/metadata/schema/TabletMetadataTest.java:
##########
@@ -116,7 +116,7 @@ public void testAllColumns() {
SortedMap<Key,Value> rowMap = toRowMap(mutation);
TabletMetadata tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(),
- EnumSet.allOf(ColumnType.class), true);
+ EnumSet.allOf(ColumnType.class), true, false);
Review Comment:
If not covered elsewhere, a unit test for the error suppression case would be nice.
##########
server/manager/src/main/java/org/apache/accumulo/manager/Manager.java:
##########
@@ -635,19 +635,19 @@ public TUnloadTabletGoal howUnload() {
}
}
- TabletGoalState getSystemGoalState(TabletLocationState tls) {
+ TabletGoalState getSystemGoalState(TabletMetadata tm) {
Review Comment:
Looking though these changes it nice to see that TabletMetadata was an easy replacement.
##########
core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java:
##########
@@ -505,10 +529,24 @@ public static <E extends Entry<Key,Value>> TabletMetadata convertRow(Iterator<E>
BulkFileColumnFamily.getBulkLoadTid(val));
break;
case CurrentLocationColumnFamily.STR_NAME:
- te.setLocationOnce(val, qual, LocationType.CURRENT);
+ try {
+ te.setLocationOnce(val, qual, LocationType.CURRENT);
+ } catch (IllegalStateException e) {
+ te.futureAndCurrentLocationSet = true;
+ if (!suppressLocationError) {
+ throw e;
+ }
+ }
Review Comment:
May be able to push checking `suppressLocationError` and setting `suppressLocationError` into `setLocationOnce` and can avoid catching the exception here. Something like the following.
```java
private void setLocationOnce(String val, String qual, LocationType lt, boolean suppressError) {
if (location != null) {
if(suppressError) {
futureAndCurrentLocationSet = true;
} else {
throw new IllegalStateException("Attempted to set second location for tableId: " + tableId
+ " endrow: " + endRow + " -- " + location + " " + qual + " " + val);
}
}
location = new Location(val, qual, lt);
}
```
##########
server/manager/src/main/java/org/apache/accumulo/manager/tableOps/delete/CleanUp.java:
##########
@@ -91,18 +92,18 @@ public long isReady(long tid, Manager manager) throws Exception {
boolean done = true;
Range tableRange = new KeyExtent(tableId, null, null).toMetaRange();
Scanner scanner = manager.getContext().createScanner(MetadataTable.NAME, Authorizations.EMPTY);
- MetaDataTableScanner.configureScanner(scanner, manager);
+ ManagerTabletInfoIterator.configureScanner(scanner, manager);
Review Comment:
This would be a follow on. As this iterator is intended to find tablets that need work, not sure its suitable for this case of deleting a table. We could optimize the iterator for this case to avoid looking for things that need splits for example, but not sure if that is worthwhile in terms of code complexity increase. As long as no harm comes from doing the unnecessary checks, maybe using the ManagerTabletInfoIterator here is fine.
##########
server/tserver/src/main/java/org/apache/accumulo/tserver/UnloadTabletHandler.java:
##########
@@ -114,19 +114,14 @@ public void run() {
try {
TServerInstance instance =
new TServerInstance(server.clientAddress, server.getLock().getSessionId());
- TabletLocationState tls = null;
- try {
- tls = new TabletLocationState(extent, null, Location.current(instance), null, null, null,
- false, TabletHostingGoal.ONDEMAND, false);
- } catch (BadLocationStateException e) {
- log.error("Unexpected error", e);
- }
+ TabletMetadata tm = new TabletMetadataImposter(extent, null, Location.current(instance), null,
Review Comment:
We may want to open up a follow on issue here and add a TODO. Eventually the tablet may have a cahced version of a tabletmetadata obj it could pass here. Not sure though.
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202789160
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ reasonsToReturnThisTablet.clear();
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
Review Comment:
Thanks for the pointer. So thats just carried forward. I still don't fully understand it, I suspect null has special meaning and that would need to be traced back through the code.
The ManagerState one kinds makes sense, I suppose when its not normal it just wants to see everything. I am not sure the reason should be BAD_STATE for that case though. So may need a new ManagementAction for that?
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202957618
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
Review Comment:
Must be something with the serialization of an empty string or something
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1199510951
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletMetadataIterator.java:
##########
@@ -0,0 +1,450 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.VirtualMetadataColumns.MaintenanceRequired;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.VirtualMetadataColumns.MaintenanceRequired.Reasons;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class TabletMetadataIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TabletMetadataIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+ private static final EnumSet<ColumnType> CONFIGURED_COLUMNS = EnumSet.of(ColumnType.PREV_ROW,
+ ColumnType.LOCATION, ColumnType.SUSPEND, ColumnType.LOGS, ColumnType.CHOPPED,
+ ColumnType.HOSTING_GOAL, ColumnType.HOSTING_REQUESTED, ColumnType.FILES, ColumnType.LAST);
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "tabletMetadataIterator", TabletMetadataIterator.class);
+ if (state != null) {
+ TabletMetadataIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ TabletMetadataIterator.setOnlineTables(tabletChange, state.onlineTables());
+ TabletMetadataIterator.setMerges(tabletChange, state.merges());
+ TabletMetadataIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ TabletMetadataIterator.setManagerState(tabletChange, state.getManagerState());
+ TabletMetadataIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static TabletMetadata decode(Entry<Key,Value> e) throws IOException {
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(e.getKey(), e.getValue());
+ return TabletMetadata.convertRow(decodedRow.entrySet().iterator(), CONFIGURED_COLUMNS, false,
+ true);
+ }
Review Comment:
The reason information is more associated with this iterator than it is with TabletMetadata. Could move that code to this iterator. Below was something I was playing around. If this makes sense could possibly rename this iterator to TabletAlertIterator
```suggestion
// was trying to think of a single word for "needs attention" and Alert was the best thing I could think of...
public static class TabletAlert {
public static enum Reasons {
BAD_STATE,
NEEDS_COMPACTING,
NEEDS_LOCATION_UPDATE,
IS_MERGING,
IS_MIGRATING,
NEEDS_SPLITTING;
}
public static final String REASONS_COLUMN_NAME = "REASONS";
public final Set<Reasons> reasons;
public final TabletMetadata tabletMetadata;
public TabletAlert(Set<Reasons> reasons, TabletMetadata tabletMetadata) {
this.reasons = reasons;
this.tabletMetadata = tabletMetadata;
}
}
public static TabletAlert decode(Entry<Key,Value> e) throws IOException {
final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(e.getKey(), e.getValue());
var row = decodedRow.firstKey().getRow();
// must remove the alert reasons before creating the tablet metadata object
var value = decodedRow.remove(new Key(row, TabletAlert.REASONS_COLUMN_NAME, ""));
Set<TabletAlert.Reasons> reasons = decodeReasons(value);
var tabletMetadata = TabletMetadata.convertRow(decodedRow.entrySet().iterator(), CONFIGURED_COLUMNS, false,
true);
return new TabletAlert(reasons, tabletMetadata);
}
```
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202497565
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletMetadataIterator.java:
##########
@@ -0,0 +1,450 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.VirtualMetadataColumns.MaintenanceRequired;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.VirtualMetadataColumns.MaintenanceRequired.Reasons;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class TabletMetadataIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TabletMetadataIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+ private static final EnumSet<ColumnType> CONFIGURED_COLUMNS = EnumSet.of(ColumnType.PREV_ROW,
+ ColumnType.LOCATION, ColumnType.SUSPEND, ColumnType.LOGS, ColumnType.CHOPPED,
+ ColumnType.HOSTING_GOAL, ColumnType.HOSTING_REQUESTED, ColumnType.FILES, ColumnType.LAST);
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "tabletMetadataIterator", TabletMetadataIterator.class);
+ if (state != null) {
+ TabletMetadataIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ TabletMetadataIterator.setOnlineTables(tabletChange, state.onlineTables());
+ TabletMetadataIterator.setMerges(tabletChange, state.merges());
+ TabletMetadataIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ TabletMetadataIterator.setManagerState(tabletChange, state.getManagerState());
+ TabletMetadataIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static TabletMetadata decode(Entry<Key,Value> e) throws IOException {
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(e.getKey(), e.getValue());
+ return TabletMetadata.convertRow(decodedRow.entrySet().iterator(), CONFIGURED_COLUMNS, false,
+ true);
+ }
Review Comment:
I created ManagerTabletInfo object in 6d22d81 based on this suggestion.
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202693907
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/AbstractTabletStateStore.java:
##########
@@ -108,51 +108,51 @@ public void setFutureLocations(Collection<Assignment> assignments)
}
@Override
- public void unassign(Collection<TabletLocationState> tablets,
+ public void unassign(Collection<TabletMetadata> tablets,
Map<TServerInstance,List<Path>> logsForDeadServers) throws DistributedStoreException {
unassign(tablets, logsForDeadServers, -1);
}
@Override
- public void suspend(Collection<TabletLocationState> tablets,
+ public void suspend(Collection<TabletMetadata> tablets,
Map<TServerInstance,List<Path>> logsForDeadServers, long suspensionTimestamp)
throws DistributedStoreException {
unassign(tablets, logsForDeadServers, suspensionTimestamp);
}
protected abstract void processSuspension(Ample.ConditionalTabletMutator tabletMutator,
- TabletLocationState tls, long suspensionTimestamp);
+ TabletMetadata tm, long suspensionTimestamp);
- private void unassign(Collection<TabletLocationState> tablets,
+ private void unassign(Collection<TabletMetadata> tablets,
Map<TServerInstance,List<Path>> logsForDeadServers, long suspensionTimestamp)
throws DistributedStoreException {
try (var tabletsMutator = ample.conditionallyMutateTablets()) {
- for (TabletLocationState tls : tablets) {
- var tabletMutator = tabletsMutator.mutateTablet(tls.extent).requireAbsentOperation();
+ for (TabletMetadata tm : tablets) {
+ var tabletMutator = tabletsMutator.mutateTablet(tm.getExtent()).requireAbsentOperation();
- if (tls.hasCurrent()) {
- tabletMutator.requireLocation(tls.current);
+ if (tm.hasCurrent()) {
+ tabletMutator.requireLocation(tm.getLocation());
ManagerMetadataUtil.updateLastForAssignmentMode(context, tabletMutator,
- tls.current.getServerInstance(), tls.last);
- tabletMutator.deleteLocation(tls.current);
+ tm.getLocation().getServerInstance(), tm.getLast());
+ tabletMutator.deleteLocation(tm.getLocation());
if (logsForDeadServers != null) {
- List<Path> logs = logsForDeadServers.get(tls.current.getServerInstance());
+ List<Path> logs = logsForDeadServers.get(tm.getLocation().getServerInstance());
if (logs != null) {
for (Path log : logs) {
- LogEntry entry = new LogEntry(tls.extent, 0, log.toString());
+ LogEntry entry = new LogEntry(tm.getExtent(), 0, log.toString());
tabletMutator.putWal(entry);
}
}
}
}
- if (tls.hasFuture()) {
- tabletMutator.requireLocation(tls.future);
- tabletMutator.deleteLocation(tls.future);
+ if (tm.getLocation().getType().equals(LocationType.FUTURE)) {
Review Comment:
Addressed in 5f28395
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202697357
##########
server/manager/src/main/java/org/apache/accumulo/manager/Manager.java:
##########
@@ -888,12 +889,12 @@ private long updateStatus() {
} else if (!serversToShutdown.isEmpty()) {
log.debug("not balancing while shutting down servers {}", serversToShutdown);
} else {
- for (TabletGroupWatcher tgw : watchers) {
- if (!tgw.isSameTserversAsLastScan(currentServers)) {
- log.debug("not balancing just yet, as collection of live tservers is in flux");
- return DEFAULT_WAIT_FOR_WATCHER;
- }
- }
+ // for (TabletGroupWatcher tgw : watchers) {
Review Comment:
Addressed in 5f28395
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202870514
##########
core/src/main/java/org/apache/accumulo/core/metadata/schema/RootTabletMetadata.java:
##########
@@ -156,10 +159,11 @@ public SortedMap<Key,Value> toKeyValues() {
* Convert this class to a {@link TabletMetadata}
*/
public TabletMetadata toTabletMetadata() {
- // use a stream so we don't have to re-sort in a new TreeMap<Key,Value> structure
- Stream<SimpleImmutableEntry<Key,Value>> entries = getKeyValues();
- return TabletMetadata.convertRow(entries.iterator(),
- EnumSet.allOf(TabletMetadata.ColumnType.class), false);
+ TreeMap<Key,Value> entries = new TreeMap<>();
+ getKeyValues().forEach(entry -> entries.put(entry.getKey(), entry.getValue()));
+ ManagerTabletInfo.addActions(entries, Set.of(ManagementAction.NEEDS_LOCATION_UPDATE));
Review Comment:
No, I don't think it's needed any longer
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204614971
##########
core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchReaderIterator.java:
##########
@@ -285,21 +285,22 @@ private ScanServerData binRanges(ClientTabletCache clientTabletCache, List<Range
break;
} else {
// tried to only do table state checks when failures.size() == ranges.size(), however this
- // did
- // not work because nothing ever invalidated entries in the tabletLocator cache... so even
- // though
- // the table was deleted the tablet locator entries for the deleted table were not
- // cleared... so
- // need to always do the check when failures occur
+ // did not work because nothing ever invalidated entries in the tabletLocator cache... so
+ // even though the table was deleted the tablet locator entries for the deleted table
+ // were not cleared. So need to always do the check when failures occur
if (failures.size() >= lastFailureSize) {
context.requireNotDeleted(tableId);
context.requireNotOffline(tableId, tableName);
}
lastFailureSize = failures.size();
+ log.debug(
Review Comment:
Removed in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204616274
##########
server/tserver/src/main/java/org/apache/accumulo/tserver/UnloadTabletHandler.java:
##########
@@ -114,19 +114,14 @@ public void run() {
try {
TServerInstance instance =
new TServerInstance(server.clientAddress, server.getLock().getSessionId());
- TabletLocationState tls = null;
- try {
- tls = new TabletLocationState(extent, null, Location.current(instance), null, null, null,
- false, TabletHostingGoal.ONDEMAND, false);
- } catch (BadLocationStateException e) {
- log.error("Unexpected error", e);
- }
+ TabletMetadata tm = new TabletMetadataImposter(extent, null, Location.current(instance), null,
Review Comment:
TODO added in 9153726
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1204612190
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ reasonsToReturnThisTablet.clear();
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
Review Comment:
I had to keep this logic for some edge cases. ITs were failing when I took it out. I did move it the `consume` method though in 9153726.
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202794396
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
+ cfg.addOption(TABLES_OPTION, Joiner.on(",").join(onlineTables));
+ }
+ }
+
+ private static void setMerges(final IteratorSetting cfg, final Collection<MergeInfo> merges) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (MergeInfo info : merges) {
+ KeyExtent extent = info.getExtent();
+ if (extent != null && !info.getState().equals(MergeState.NONE)) {
+ info.write(buffer);
+ }
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MERGES_OPTION, encoded);
+ }
+
+ private static void setMigrations(final IteratorSetting cfg,
+ final Collection<KeyExtent> migrations) {
+ DataOutputBuffer buffer = new DataOutputBuffer();
+ try {
+ for (KeyExtent extent : migrations) {
+ extent.writeTo(buffer);
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ String encoded =
+ Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
+ cfg.addOption(MIGRATIONS_OPTION, encoded);
+ }
+
+ private static void setManagerState(final IteratorSetting cfg, final ManagerState state) {
+ cfg.addOption(MANAGER_STATE_OPTION, state.toString());
+ }
+
+ private static void setShuttingDown(final IteratorSetting cfg,
+ final Set<TServerInstance> servers) {
+ if (servers != null) {
+ cfg.addOption(SHUTTING_DOWN_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static Set<KeyExtent> parseMigrations(final String migrations) {
+ if (migrations == null) {
+ return Collections.emptySet();
+ }
+ try {
+ Set<KeyExtent> result = new HashSet<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(migrations);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ result.add(KeyExtent.readFrom(buffer));
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static Set<TableId> parseTableIDs(final String tableIDs) {
+ if (tableIDs == null) {
+ return null;
+ }
+ Set<TableId> result = new HashSet<>();
+ for (String tableID : tableIDs.split(",")) {
+ result.add(TableId.of(tableID));
+ }
+ return result;
+ }
+
+ private static Set<TServerInstance> parseServers(final String servers) {
+ if (servers == null) {
+ return null;
+ }
+ // parse "host:port[INSTANCE]"
+ Set<TServerInstance> result = new HashSet<>();
+ if (!servers.isEmpty()) {
+ for (String part : servers.split(",")) {
+ String[] parts = part.split("\\[", 2);
+ String hostport = parts[0];
+ String instance = parts[1];
+ if (instance != null && instance.endsWith("]")) {
+ instance = instance.substring(0, instance.length() - 1);
+ }
+ result.add(new TServerInstance(AddressUtil.parseAddress(hostport, false), instance));
+ }
+ }
+ return result;
+ }
+
+ private static Map<TableId,MergeInfo> parseMerges(final String merges) {
+ if (merges == null) {
+ return null;
+ }
+ try {
+ Map<TableId,MergeInfo> result = new HashMap<>();
+ DataInputBuffer buffer = new DataInputBuffer();
+ byte[] data = Base64.getDecoder().decode(merges);
+ buffer.reset(data, data.length);
+ while (buffer.available() > 0) {
+ MergeInfo mergeInfo = new MergeInfo();
+ mergeInfo.readFields(buffer);
+ result.put(mergeInfo.extent.tableId(), mergeInfo);
+ }
+ return result;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private static boolean shouldReturnDueToSplit(final TabletMetadata tm,
+ final long splitThreshold) {
+ return tm.getFilesMap().values().stream().map(DataFileValue::getSize)
+ .collect(Collectors.summarizingLong(Long::longValue)).getSum() > splitThreshold;
+ }
+
+ private static boolean shouldReturnDueToLocation(final TabletMetadata tm,
+ final Set<TableId> onlineTables, final Set<TServerInstance> current, final boolean debug) {
+ // is the table supposed to be online or offline?
+ final boolean shouldBeOnline = onlineTables.contains(tm.getTableId());
+
+ if (debug) {
+ LOG.debug("{} is {}. Table is {}line. Tablet hosting goal is {}, hostingRequested: {}",
+ tm.getExtent(), getLocationState(current, tm), (shouldBeOnline ? "on" : "off"),
+ tm.getHostingGoal(), tm.getHostingRequested());
+ }
+ switch (getLocationState(current, tm)) {
+ case ASSIGNED:
+ // we always want data about assigned tablets
+ return true;
+ case HOSTED:
+ if (!shouldBeOnline || tm.getHostingGoal() == TabletHostingGoal.NEVER
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && !tm.getHostingRequested())) {
+ return true;
+ }
+ break;
+ case ASSIGNED_TO_DEAD_SERVER:
+ return true;
+ case SUSPENDED:
+ case UNASSIGNED:
+ if (shouldBeOnline && (tm.getHostingGoal() == TabletHostingGoal.ALWAYS
+ || (tm.getHostingGoal() == TabletHostingGoal.ONDEMAND && tm.getHostingRequested()))) {
+ return true;
+ }
+ break;
+ default:
+ throw new AssertionError(
+ "Inconceivable! The tablet is an unrecognized state: " + getLocationState(current, tm));
+ }
+ return false;
+ }
+
+ private static TabletState getLocationState(final Set<TServerInstance> liveServers,
+ final TabletMetadata tm) {
+ Location loc = tm.getLocation();
+
+ if (loc == null || loc.getType() == null || loc.getServerInstance() == null) {
+ return TabletState.UNASSIGNED;
+ }
+
+ if (loc.getType().equals(LocationType.FUTURE)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.ASSIGNED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (loc.getType().equals(LocationType.CURRENT)) {
+ return liveServers.contains(loc.getServerInstance()) ? TabletState.HOSTED
+ : TabletState.ASSIGNED_TO_DEAD_SERVER;
+ } else if (tm.getSuspend() != null) {
+ return TabletState.SUSPENDED;
+ } else {
+ return TabletState.UNASSIGNED;
+ }
+ }
+
+ public static void configureScanner(final ScannerBase scanner, final CurrentState state) {
+ TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
+ scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
+ scanner.fetchColumnFamily(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily());
+ scanner.fetchColumnFamily(LogColumnFamily.NAME);
+ scanner.fetchColumnFamily(ChoppedColumnFamily.NAME);
+ scanner.fetchColumnFamily(HostingColumnFamily.NAME);
+ scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class));
+ IteratorSetting tabletChange =
+ new IteratorSetting(1001, "ManagerTabletInfoIterator", ManagerTabletInfoIterator.class);
+ if (state != null) {
+ ManagerTabletInfoIterator.setCurrentServers(tabletChange, state.onlineTabletServers());
+ ManagerTabletInfoIterator.setOnlineTables(tabletChange, state.onlineTables());
+ ManagerTabletInfoIterator.setMerges(tabletChange, state.merges());
+ ManagerTabletInfoIterator.setMigrations(tabletChange, state.migrationsSnapshot());
+ ManagerTabletInfoIterator.setManagerState(tabletChange, state.getManagerState());
+ ManagerTabletInfoIterator.setShuttingDown(tabletChange, state.shutdownServers());
+ }
+ scanner.addScanIterator(tabletChange);
+ }
+
+ public static ManagerTabletInfo decode(Entry<Key,Value> e) throws IOException {
+ return new ManagerTabletInfo(e.getKey(), e.getValue());
+ }
+
+ private Set<TServerInstance> current;
+ private Set<TableId> onlineTables;
+ private Map<TableId,MergeInfo> merges;
+ private boolean debug = false;
+ private Set<KeyExtent> migrations;
+ private ManagerState managerState = ManagerState.NORMAL;
+ private IteratorEnvironment env;
+ private Key topKey = null;
+ private Value topValue = null;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ this.env = env;
+ current = parseServers(options.get(SERVERS_OPTION));
+ onlineTables = parseTableIDs(options.get(TABLES_OPTION));
+ merges = parseMerges(options.get(MERGES_OPTION));
+ debug = options.containsKey(DEBUG_OPTION);
+ migrations = parseMigrations(options.get(MIGRATIONS_OPTION));
+ try {
+ managerState = ManagerState.valueOf(options.get(MANAGER_STATE_OPTION));
+ } catch (Exception ex) {
+ if (options.get(MANAGER_STATE_OPTION) != null) {
+ LOG.error("Unable to decode managerState {}", options.get(MANAGER_STATE_OPTION));
+ }
+ }
+ Set<TServerInstance> shuttingDown = parseServers(options.get(SHUTTING_DOWN_OPTION));
+ if (current != null && shuttingDown != null) {
+ current.removeAll(shuttingDown);
+ }
+ }
+
+ @Override
+ public Key getTopKey() {
+ return topKey;
+ }
+
+ @Override
+ public Value getTopValue() {
+ return topValue;
+ }
+
+ @Override
+ public boolean hasTop() {
+ return topKey != null && topValue != null;
+ }
+
+ @Override
+ public void next() throws IOException {
+ topKey = null;
+ topValue = null;
+ super.next();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
+ throws IOException {
+ topKey = null;
+ topValue = null;
+ super.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ protected void consume() throws IOException {
+
+ final Set<ManagementAction> reasonsToReturnThisTablet = new HashSet<>();
+ while (getSource().hasTop()) {
+ final Key k = getSource().getTopKey();
+ final Value v = getSource().getTopValue();
+ final SortedMap<Key,Value> decodedRow = WholeRowIterator.decodeRow(k, v);
+ final TabletMetadata tm = TabletMetadata.convertRow(decodedRow.entrySet().iterator(),
+ ManagerTabletInfo.CONFIGURED_COLUMNS, false, true);
+
+ LOG.debug("Evaluating extent: {}", tm);
+ if (sendTabletToManager(tm, reasonsToReturnThisTablet)) {
+ // If we simply returned here, then the client would get the encoded K,V
+ // from the WholeRowIterator. However, it would not know the reason(s) why
+ // it was returned. Insert a K,V pair to represent the reasons. The client
+ // can pull this K,V pair from the results by looking at the colf.
+ ManagerTabletInfo.addActions(decodedRow, reasonsToReturnThisTablet);
+ topKey = decodedRow.firstKey();
+ topValue = WholeRowIterator.encodeRow(new ArrayList<>(decodedRow.keySet()),
+ new ArrayList<>(decodedRow.values()));
+ LOG.debug("Returning extent with reasons: {}", reasonsToReturnThisTablet);
+ return;
+ }
+
+ LOG.debug("No reason to return this extent, continuing");
+ getSource().next();
+ }
+ }
+
+ /**
+ * Evaluates whether or not this Tablet should be returned so that it can be acted upon by the
+ * Manager
+ */
+ private boolean sendTabletToManager(final TabletMetadata tm,
+ final Set<ManagementAction> reasonsToReturnThisTablet) {
+
+ reasonsToReturnThisTablet.clear();
+
+ if (onlineTables == null || current == null || managerState != ManagerState.NORMAL
Review Comment:
When the manager is in SAFE_MODE we want to assign metadata tablets only. Returning BAD_STATE only may cause the TGW to skip assigning metadata tablets when in safe mode.
--
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
[GitHub] [accumulo] dlmarion commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "dlmarion (via GitHub)" <gi...@apache.org>.
dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202952659
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,434 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
Review Comment:
I removed the null check in ManagerTabletInfoIterator.parseServers() and ended up with the following when running LocatorIT:
```
java.lang.NullPointerException: null
at org.apache.accumulo.server.manager.state.ManagerTabletInfoIterator.parseServers(ManagerTabletInfoIterator.java:170) ~[classes/:?]
at org.apache.accumulo.server.manager.state.ManagerTabletInfoIterator.init(ManagerTabletInfoIterator.java:292) ~[classes/:?]
at org.apache.accumulo.core.iteratorsImpl.IteratorConfigUtil.loadIterators(IteratorConfigUtil.java:226) ~[classes/:?]
```
--
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
[GitHub] [accumulo] keith-turner commented on a diff in pull request #3409: Modified TabletGroupWatcher to use TabletMetadata
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202876085
##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/ManagerTabletInfoIterator.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.admin.TabletHostingGoal;
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.SkippingIterator;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.user.WholeRowIterator;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo;
+import org.apache.accumulo.core.manager.state.ManagerTabletInfo.ManagementAction;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.DataFileValue;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.HostingColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LastLocationColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType;
+import org.apache.accumulo.core.util.AddressUtil;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+
+public class ManagerTabletInfoIterator extends SkippingIterator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTabletInfoIterator.class);
+
+ private static final String SERVERS_OPTION = "servers";
+ private static final String TABLES_OPTION = "tables";
+ private static final String MERGES_OPTION = "merges";
+ private static final String DEBUG_OPTION = "debug";
+ private static final String MIGRATIONS_OPTION = "migrations";
+ private static final String MANAGER_STATE_OPTION = "managerState";
+ private static final String SHUTTING_DOWN_OPTION = "shuttingDown";
+
+ private static void setCurrentServers(final IteratorSetting cfg,
+ final Set<TServerInstance> goodServers) {
+ if (goodServers != null) {
+ List<String> servers = new ArrayList<>();
+ for (TServerInstance server : goodServers) {
+ servers.add(server.getHostPortSession());
+ }
+ cfg.addOption(SERVERS_OPTION, Joiner.on(",").join(servers));
+ }
+ }
+
+ private static void setOnlineTables(final IteratorSetting cfg, final Set<TableId> onlineTables) {
+ if (onlineTables != null) {
Review Comment:
This comment is no longer relevant after investigation and later comments.
--
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