rishabhdaim commented on code in PR #1805: URL: https://github.com/apache/jackrabbit-oak/pull/1805#discussion_r1831387856
########## oak-run/src/main/java/org/apache/jackrabbit/oak/run/CreateGarbageCommand.java: ########## @@ -0,0 +1,574 @@ +/* + * 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.JcrConstants; +import org.apache.jackrabbit.guava.common.base.Joiner; +import org.apache.jackrabbit.guava.common.io.Closer; +import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; +import org.apache.jackrabbit.oak.plugins.document.GenerateGarbageHelper; +import org.apache.jackrabbit.oak.plugins.document.LeaseCheckMode; +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.nodetype.NodeTypeConstants; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Closeable; +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.plugins.document.util.Utils.getIdFromPath; +import static org.apache.jackrabbit.oak.run.Utils.asCloseable; +import static org.apache.jackrabbit.oak.run.Utils.createDocumentMKBuilder; + +/** + * GenerateGarbageCommand generates garbage nodes in the repository in order to allow for testing fullGC functionality. + */ +public class CreateGarbageCommand implements Command, Closeable { + private static final Logger LOG = LoggerFactory.getLogger(CreateGarbageCommand.class); + + private final ScheduledExecutorService continuousRunExecutor = Executors.newScheduledThreadPool(1); + + private static final String USAGE = Joiner.on(System.lineSeparator()).join( + "create-test-garbage {<jdbc-uri> | <mongodb-uri>} <sub-command> [options] ", + "where sub-command is one of: ", + " clean - clean up all generated garbage under the specified root node", + " generate - generate garbage nodes in the repository, under the root node tmp/oak-run-generated-test-garbage. ", + " Use the --garbageType (required) option to specify the type of garbage to generate", Review Comment: ```suggestion " Use the --garbageType (required) option to specify the type of garbage to create", ``` ########## oak-run/src/main/java/org/apache/jackrabbit/oak/run/CreateGarbageCommand.java: ########## @@ -0,0 +1,574 @@ +/* + * 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.JcrConstants; +import org.apache.jackrabbit.guava.common.base.Joiner; +import org.apache.jackrabbit.guava.common.io.Closer; +import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; +import org.apache.jackrabbit.oak.plugins.document.GenerateGarbageHelper; +import org.apache.jackrabbit.oak.plugins.document.LeaseCheckMode; +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.nodetype.NodeTypeConstants; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Closeable; +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.plugins.document.util.Utils.getIdFromPath; +import static org.apache.jackrabbit.oak.run.Utils.asCloseable; +import static org.apache.jackrabbit.oak.run.Utils.createDocumentMKBuilder; + +/** + * GenerateGarbageCommand generates garbage nodes in the repository in order to allow for testing fullGC functionality. + */ +public class CreateGarbageCommand implements Command, Closeable { + private static final Logger LOG = LoggerFactory.getLogger(CreateGarbageCommand.class); + + private final ScheduledExecutorService continuousRunExecutor = Executors.newScheduledThreadPool(1); + + private static final String USAGE = Joiner.on(System.lineSeparator()).join( + "create-test-garbage {<jdbc-uri> | <mongodb-uri>} <sub-command> [options] ", + "where sub-command is one of: ", + " clean - clean up all generated garbage under the specified root node", + " generate - generate garbage nodes in the repository, under the root node tmp/oak-run-generated-test-garbage. ", Review Comment: ```suggestion " create - create garbage nodes in the repository, under the root node tmp/oak-run-created-test-garbage. ", ``` ########## oak-run/src/main/java/org/apache/jackrabbit/oak/run/CreateGarbageCommand.java: ########## @@ -0,0 +1,574 @@ +/* + * 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.JcrConstants; +import org.apache.jackrabbit.guava.common.base.Joiner; +import org.apache.jackrabbit.guava.common.io.Closer; +import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; +import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; +import org.apache.jackrabbit.oak.plugins.document.GenerateGarbageHelper; +import org.apache.jackrabbit.oak.plugins.document.LeaseCheckMode; +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.nodetype.NodeTypeConstants; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Closeable; +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.plugins.document.util.Utils.getIdFromPath; +import static org.apache.jackrabbit.oak.run.Utils.asCloseable; +import static org.apache.jackrabbit.oak.run.Utils.createDocumentMKBuilder; + +/** + * GenerateGarbageCommand generates garbage nodes in the repository in order to allow for testing fullGC functionality. + */ +public class CreateGarbageCommand implements Command, Closeable { + private static final Logger LOG = LoggerFactory.getLogger(CreateGarbageCommand.class); + + private final ScheduledExecutorService continuousRunExecutor = Executors.newScheduledThreadPool(1); + + private static final String USAGE = Joiner.on(System.lineSeparator()).join( + "create-test-garbage {<jdbc-uri> | <mongodb-uri>} <sub-command> [options] ", + "where sub-command is one of: ", + " clean - clean up all generated garbage under the specified root node", + " generate - generate garbage nodes in the repository, under the root node tmp/oak-run-generated-test-garbage. ", + " Use the --garbageType (required) option to specify the type of garbage to generate", + " the --garbageNodesCount option to specify the total number of garbage nodes to create,", + " the --garbageNodesParentCount option to specify the total number of parent nodes under which to create garbage nodes,", + " the --orphansDepth option to specify the depth in the tree at which to create garbage nodes,", + " the --orphansLevelGap option to specify the gap in the tree between the first leaf gap orphan garbage node and its parent,", + " the --numberOfRuns option to specify the number of garbage generation runs to do,", + " and the --generateIntervalSeconds option to specify the interval at which to generate a complete garbage count from createGarbageNotesCount."); + + + /** + * Garbage should be generated under tmp node. + */ + public static String GARBAGE_GEN_ROOT_PATH_BASE = "tmp"; + + /** + * The root node name for garbage generation, one level under tmp. + */ + public static String GARBAGE_GEN_ROOT_NODE_NAME = "oak-run-generated-test-garbage"; + + /** + * Root node for garbage generation. + * Necessary in order to allow cleanup of all generated garbage nodes by simply removing the root node. + */ + public static String GARBAGE_GEN_ROOT_PATH = GARBAGE_GEN_ROOT_PATH_BASE + "/" + GARBAGE_GEN_ROOT_NODE_NAME; + + /** + * Base path for 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 GEN_BASE_PATH = "GenTest_"; + + /** + * 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 GEN_PARENT_NODE_PREFIX = "Parent_"; + public static String GEN_NODE_PREFIX = "Node_"; + public static String GEN_NODE_LEVEL_PREFIX = "_Level_"; + + public static String EMPTY_PROPERTY_NAME = "prop"; + + /** + * The maximum depth in the tree at which to generate gap orphans garbage nodes. + * Used for validation of the orphansDepth / orphansLevelGap options. + */ + private final int GAP_ORPHANS_MAX_DEPTH = 15; + + private int continuousRunIndex = 0; + + private DocumentNodeStore documentNodeStore; + + public DocumentNodeStore getDocumentNodeStore() { + return documentNodeStore; + } + + private static class CreateGarbageOptions 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"; Review Comment: ```suggestion static final String CMD_CREATE = "create"; ``` -- 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]
