shodaaan commented on code in PR #1805:
URL: https://github.com/apache/jackrabbit-oak/pull/1805#discussion_r1809008015
##########
oak-run/src/main/java/org/apache/jackrabbit/oak/run/AvailableModes.java:
##########
@@ -75,5 +75,6 @@ public final class AvailableModes {
.put("segment-copy", new SegmentCopyCommand())
.put("server", new ServerCommand())
.put("purge-index-versions", new
LucenePurgeOldIndexVersionCommand())
+ .put("generateFullGC", new GenerateFullGCCommand())
Review Comment:
Changed. Thank you for the suggestion.
##########
oak-run/src/main/java/org/apache/jackrabbit/oak/run/GenerateFullGCCommand.java:
##########
@@ -0,0 +1,416 @@
+/*
+ * 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.jackrabbit.oak.run;
+
+import joptsimple.OptionSpec;
+import org.apache.jackrabbit.guava.common.io.Closer;
+import org.apache.jackrabbit.oak.plugins.document.Collection;
+import org.apache.jackrabbit.oak.plugins.document.Document;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
+import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector;
+import org.apache.jackrabbit.oak.run.commons.Command;
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+import static org.apache.jackrabbit.oak.run.Utils.createDocumentMKBuilder;
+
+/**
+ * GenerateFullGCCommand generates garbage nodes in the repository in order to
allow for testing fullGC functionality.
+ */
+public class GenerateFullGCCommand implements Command {
+ private static final Logger LOG =
LoggerFactory.getLogger(GenerateFullGCCommand.class);
+
+ private static final String USAGE = "generateFullGC {<jdbc-uri> |
<mongodb-uri>} [options]";
+
+ /**
+ * Root node for fullGC garbage generation.
+ * Necessary in order to allow cleanup of all generated garbage nodes by
simply removing the root node.
+ */
+ public static String FULLGC_GEN_ROOT_PATH = "fullGCGenRoot";
+
+ /**
+ * Base path for fullGC garbage generation. The timestamp of the run will
be appended to this path,
+ * which is necessary in order for each garbage generation run to be
unique and not overwrite previous ones.
+ * If continuous generation is enabled, the index of the run will also be
appended to this path.
+ */
+ public static String FULLGC_GEN_BASE_PATH = "fullGCGenTest_";
+
+ /**
+ * Prefix for parent nodes under which garbage nodes will be created.
+ * The index of the parent node will be appended to this prefix.
+ */
+ public static String FULLGC_GEN_PARENT_NODE_PREFIX = "fullGCParent_";
+ public static String FULLGC_GEN_NODE_PREFIX = "fullGCNode_";
+
+ public static String EMPTY_PROPERTY_NAME = "prop";
+
+ private int continuousRunIndex = 0;
+
+ private DocumentNodeStore documentNodeStore;
+
+ public DocumentNodeStore getDocumentNodeStore() {
+ return documentNodeStore;
+ }
+
+ private static class GenerateFullGCOptions extends Utils.NodeStoreOptions {
+
+ /**
+ * Sub-command for generating garbage.
+ * This is the default sub-command to run if none is specified.
+ */
+ static final String CMD_GENERATE = "generate";
+
+ /**
+ * Sub-command for cleaning up all generated garbage.
+ * Using this will remove the root node FULLGC_GEN_ROOT_PATH and all
of its children (recursively).
+ */
+ static final String CMD_CLEAN = "clean";
+
+ final OptionSpec<Integer> createGarbageNodesCount;
+ final OptionSpec<Integer> garbageNodesParentCount;
+ final OptionSpec<Integer> garbageType;
+ final OptionSpec<Integer> numberOfRuns;
+ final OptionSpec<Integer> generateIntervalSeconds;
+
+ public GenerateFullGCOptions(String usage) {
+ super(usage);
+ createGarbageNodesCount = parser
+ .accepts("garbageNodesCount", "the total number of garbage
nodes to create").withRequiredArg()
+ .ofType(Integer.class).defaultsTo(0);
+ garbageNodesParentCount = parser
+ .accepts("garbageNodesParentCount", "total number of
parent nodes under which to create garbage nodes").withRequiredArg()
+ .ofType(Integer.class).defaultsTo(1);
+ garbageType = parser
+ .accepts("garbageType", "garbage type to be generated -
must be a value from VersionGarbageCollector.fullGCMode").withRequiredArg()
+ .ofType(Integer.class).defaultsTo(1);
+ numberOfRuns = parser
+ .accepts("numberOfRuns", "the number of garbage generation
runs to do. Only applies if greater than 1, " +
+ "otherwise a single run will be
done.").withRequiredArg()
+ .ofType(Integer.class).defaultsTo(1);
+ generateIntervalSeconds = parser
+ .accepts("generateIntervalSeconds", "the interval at which
to generate a complete garbage count from createGarbageNotesCount. " +
+ "Applies only if numberOfRuns is greater than
1.").withRequiredArg()
+ .ofType(Integer.class).defaultsTo(60);
+ }
+
+ public GenerateFullGCOptions parse(String[] args) {
+ super.parse(args);
+ return this;
+ }
+
+ String getSubCmd() {
+ List<String> args = getOtherArgs();
+ if (args.size() > 0) {
+ return args.get(0);
+ }
+ return CMD_GENERATE;
+ }
+
+ public int getCreateGarbageNodesCount() {
+ return createGarbageNodesCount.value(options);
+ }
+
+ public int getGarbageNodesParentCount() {
+ return garbageNodesParentCount.value(options);
+ }
+
+ public int getGarbageType() {
+ return garbageType.value(options);
+ }
+
+ public int getNumberOfRuns() {
+ return numberOfRuns.value(options);
+ }
+
+ public int getGenerateIntervalSeconds() {
+ return generateIntervalSeconds.value(options);
+ }
+ }
+
+ public void execute(String... args) throws Exception {
+ Closer closer = Closer.create();
+ try {
+ execute(closer, args);
+ } catch (Throwable e) {
+ LOG.error("Command failed", e);
+ throw closer.rethrow(e);
+ } finally {
+ closer.close();
+ }
+ }
+
+ /**
+ * Method with passed closer is necessary in order to allow for unit tests
to check the output of the command.
+ * It is the responsibility of the caller to close the closer.
+ *
+ * Returns the list of generated garbage base paths (under the garbage
root node).
+ * @param closer
+ * @param args
+ * @throws Exception
+ */
+ public List<String> execute(Closer closer, String... args) throws
Exception {
+ continuousRunIndex = 0;
+
+ List<String> generateBasePaths = new ArrayList<>();
+
+ GenerateFullGCOptions options = new
GenerateFullGCOptions(USAGE).parse(args);
+ String subCmd = options.getSubCmd();
+
+ if (GenerateFullGCOptions.CMD_GENERATE.equals(subCmd)) {
+ if (options.getNumberOfRuns() > 1 &&
options.getGenerateIntervalSeconds() > 0) {
+ generateBasePaths.addAll(generateGarbageContinuously(options,
closer));
+ } else {
+ generateBasePaths.add(generateGarbage(options, closer, 0));
+ }
+ } else if (GenerateFullGCOptions.CMD_CLEAN.equals(subCmd)) {
+ cleanGarbage(options, closer);
+ } else {
+ System.err.println("unknown revisions command: " + subCmd);
+ }
+
+ return generateBasePaths;
+ }
+
+ private List<String> generateGarbageContinuously(GenerateFullGCOptions
options, Closer closer) throws IOException, Exception {
+ ScheduledExecutorService executor =
Executors.newScheduledThreadPool(1);
Review Comment:
Changed. Thank you for the 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]