You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2021/11/24 16:27:03 UTC

[GitHub] [accumulo] dlmarion commented on a change in pull request #2345: Create tool to validate Compaction configuration

dlmarion commented on a change in pull request #2345:
URL: https://github.com/apache/accumulo/pull/2345#discussion_r756243938



##########
File path: server/base/src/main/java/org/apache/accumulo/server/conf/CheckCompactionConfig.java
##########
@@ -0,0 +1,154 @@
+/*
+ * 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
+ *
+ *   http://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.conf;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+
+import org.apache.accumulo.core.clientImpl.ClientInfoImpl;
+import org.apache.accumulo.core.spi.compaction.DefaultCompactionPlanner;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.auto.service.AutoService;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+import com.google.gson.Gson;
+
+@AutoService(KeywordExecutable.class)
+public class CheckCompactionConfig implements KeywordExecutable {
+
+  private final static Logger log = LoggerFactory.getLogger(CheckCompactionConfig.class);
+
+  public static void main(String[] args) throws IOException {
+    if (args.length != 1)
+      throw new IllegalArgumentException("Only one argument is accepted (path to properties file)");
+
+    Path path = Path.of(args[0]);
+    if (!path.toFile().exists())
+      throw new FileNotFoundException("File at given path could not be found");
+
+    // Extract properties from props file at given path
+    Properties allProps = ClientInfoImpl.toProperties(path);
+    log.info("All props: {}", allProps);
+
+    // Extract server props from set of all props
+    Map<String,String> serverPropsMap = new HashMap<>();
+    String suffix = ".accumulo.server.props";
+    allProps.forEach((k, v) -> {
+      if (k.toString().endsWith(suffix))
+        serverPropsMap.put(k.toString(), v.toString());
+    });
+
+    // Ensure there is exactly one server prop in the map and get its value
+    // The value should be compaction properties
+    String compactionPropertiesString = Iterables.getOnlyElement(serverPropsMap.values());
+
+    // Create a props object for compaction props
+    StringReader sr = new StringReader(compactionPropertiesString.replace(' ', '\n'));
+    Properties serverProps = new Properties();
+    serverProps.load(sr);
+
+    // Extract executors options from compactions props
+    Map<String,String> executorsProperties =
+        getPropertiesWithSuffix(serverProps, ".planner.opts.executors");
+
+    // Ensure there is exactly one executor config in the map and get its value
+    String executorJson = Iterables.getOnlyElement(executorsProperties.values());
+
+    // Convert json string to array of ExecutorConfig objects
+    var executorConfigs =
+        new Gson().fromJson(executorJson, DefaultCompactionPlanner.ExecutorConfig[].class);
+    if (Objects.isNull(executorConfigs)) {
+      throw new RuntimeException("Compaction executors could not be parsed from given file");
+    }
+
+    boolean hasSeenNullMaxSize = false;
+
+    for (var executorConfig : executorConfigs) {

Review comment:
       Suggest re-using the logic at https://github.com/apache/accumulo/blob/main/core/src/main/java/org/apache/accumulo/core/spi/compaction/DefaultCompactionPlanner.java#L158 so that it's not done in two places.




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