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


##########
server/base/src/main/java/org/apache/accumulo/server/manager/state/TabletManagementParameters.java:
##########
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.server.manager.state;
+
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toSet;
+import static java.util.stream.Collectors.toUnmodifiableMap;
+import static java.util.stream.Collectors.toUnmodifiableSet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Supplier;
+
+import org.apache.accumulo.core.data.AbstractId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.manager.balancer.TabletServerIdImpl;
+import org.apache.accumulo.core.manager.thrift.ManagerState;
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.core.spi.balancer.data.TabletServerId;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+
+import com.google.common.base.Suppliers;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * An immutable snapshot of the information needed by the TabletGroupWatcher 
and the
+ * {@link TabletManagementIterator} to make decisions about tablets.
+ */
+public class TabletManagementParameters {
+
+  private final ManagerState managerState;
+  private final Map<Ample.DataLevel,Boolean> parentUpgradeMap;
+  private final Set<TableId> onlineTables;
+  private final Set<TServerInstance> serversToShutdown;
+  private final Map<KeyExtent,TServerInstance> migrations;
+
+  private final Ample.DataLevel level;
+
+  private final Supplier<Map<TServerInstance,String>> resourceGroups;
+  private final Map<String,Set<TServerInstance>> tserverGroups;
+  private final Map<Long,Map<String,String>> compactionHints;
+  private final Set<TServerInstance> onlineTservers;
+
+  public TabletManagementParameters(ManagerState managerState,
+      Map<Ample.DataLevel,Boolean> parentUpgradeMap, Set<TableId> onlineTables,
+      Set<TServerInstance> onlineTservers, Set<TServerInstance> 
serversToShutdown,
+      Map<KeyExtent,TServerInstance> migrations, 
Map<String,Set<TServerInstance>> tserverGroups,
+      Ample.DataLevel level, Map<Long,Map<String,String>> compactionHints) {
+    this.managerState = managerState;
+    this.parentUpgradeMap = Map.copyOf(parentUpgradeMap);
+    // TODO could filter by level
+    this.onlineTables = Set.copyOf(onlineTables);
+    this.onlineTservers = Set.copyOf(onlineTservers);
+    this.serversToShutdown = Set.copyOf(serversToShutdown);
+    // TODO could filter by level
+    this.migrations = Map.copyOf(migrations);
+    this.level = level;
+    this.tserverGroups = tserverGroups.entrySet().stream()
+        .collect(toUnmodifiableMap(Map.Entry::getKey, entry -> 
Set.copyOf(entry.getValue())));
+    this.compactionHints = makeImmutable(compactionHints);
+    this.resourceGroups = Suppliers.memoize(() -> {
+      Map<TServerInstance,String> resourceGroups = new HashMap<>();
+      TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, 
tservers) -> tservers
+          .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+      return Map.copyOf(resourceGroups);
+    });
+  }
+
+  private TabletManagementParameters(JsonData jdata) {
+    this.managerState = jdata.managerState;
+    this.parentUpgradeMap = Map.copyOf(jdata.parentUpgradeMap);
+    this.onlineTables = 
jdata.onlineTables.stream().map(TableId::of).collect(toUnmodifiableSet());
+    this.onlineTservers =
+        
jdata.onlineTservers.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+    this.serversToShutdown =
+        
jdata.serversToShutdown.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
+    this.migrations = jdata.migrations.entrySet().stream()
+        .collect(toUnmodifiableMap(entry -> 
JsonData.strToExtent(entry.getKey()),
+            entry -> new TServerInstance(entry.getValue())));
+    this.level = jdata.level;
+    this.compactionHints = makeImmutable(jdata.compactionHints);
+    this.tserverGroups = 
jdata.tserverGroups.entrySet().stream().collect(toUnmodifiableMap(
+        Map.Entry::getKey,
+        entry -> 
entry.getValue().stream().map(TServerInstance::new).collect(toUnmodifiableSet())));
+    this.resourceGroups = Suppliers.memoize(() -> {
+      Map<TServerInstance,String> resourceGroups = new HashMap<>();
+      TabletManagementParameters.this.tserverGroups.forEach((resourceGroup, 
tservers) -> tservers
+          .forEach(tserver -> resourceGroups.put(tserver, resourceGroup)));
+      return Map.copyOf(resourceGroups);
+    });
+  }
+
+  public ManagerState getManagerState() {
+    return managerState;
+  }
+
+  public boolean isParentLevelUpgraded() {
+    return parentUpgradeMap.get(level);
+  }
+
+  public Set<TServerInstance> getOnlineTsevers() {
+    return onlineTservers;
+  }
+
+  public Set<TServerInstance> getServersToShutdown() {
+    return serversToShutdown;
+  }
+
+  public boolean isTableOnline(TableId tableId) {
+    return onlineTables.contains(tableId);
+  }
+
+  public Map<KeyExtent,TServerInstance> getMigrations() {
+    return migrations;
+  }
+
+  public Ample.DataLevel getLevel() {
+    return level;
+  }
+
+  public String getResourceGroup(TServerInstance tserver) {
+    return resourceGroups.get().get(tserver);
+  }
+
+  public Map<String,Set<TServerInstance>> getGroupedTservers() {
+    return tserverGroups;
+  }
+
+  public Set<TableId> getOnlineTables() {
+    return onlineTables;
+  }
+
+  public Map<Long,Map<String,String>> getCompactionHints() {
+    return compactionHints;
+  }
+
+  private static Map<Long,Map<String,String>>
+      makeImmutable(Map<Long,Map<String,String>> compactionHints) {
+    var copy = new HashMap<Long,Map<String,String>>();
+    compactionHints.forEach((ftxid, hints) -> copy.put(ftxid, 
Map.copyOf(hints)));
+    return Collections.unmodifiableMap(copy);
+  }
+
+  private static class JsonData {

Review Comment:
   Would something less generic than JsonData help when it is declared / used?  
Maybe TMParmsJson or even ParamsJason?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to