Skip to content
Permalink
Browse files
GRANITE-38542 Adding cronjob for call cleanup index command which imp…
…lemented in oak-run: adjust log messages etc. per code review
  • Loading branch information
FrancoisZhang committed Mar 16, 2022
1 parent c968da1 commit 773794afa2fb04073d83e049b0854f331d3e0edd
Showing 2 changed files with 18 additions and 10 deletions.
@@ -57,25 +57,26 @@ public class PurgeOldIndexVersion {
* @throws IOException
* @throws CommitFailedException
*/
public void execute(NodeStore nodeStore, boolean isReadWriteRepository, long purgeThresholdMillis, List<String> indexPaths) throws IOException, CommitFailedException {
if (!isReadWriteRepository) {
LOG.info("Repository is opened in read-only mode");
return;
}
public void execute(NodeStore nodeStore, boolean isReadWriteRepository, long purgeThresholdMillis, List<String> indexPaths) throws
IOException, CommitFailedException {
List<IndexVersionOperation> purgeIndexList = getPurgeIndexes(nodeStore, purgeThresholdMillis, indexPaths);
if (!purgeIndexList.isEmpty()) {
LOG.info("Found indexes for purging: '{}'", purgeIndexList);
long purgeStart = System.currentTimeMillis();
purgeOldIndexVersion(nodeStore, purgeIndexList);
LOG.info("Index purging done, took '{}' ms", (System.currentTimeMillis() - purgeStart));
if (isReadWriteRepository) {
LOG.info("Found indexes for purging: '{}'", purgeIndexList);
long purgeStart = System.currentTimeMillis();
purgeOldIndexVersion(nodeStore, purgeIndexList);
LOG.info("Index purging done, took '{}' ms", (System.currentTimeMillis() - purgeStart));
} else {
LOG.info("Repository is opened in read-only mode, the purging indexes for '{}' are: {}", indexPaths, purgeIndexList);
}
} else {
LOG.info("No indexes are found to be purged");
}
}

public List<IndexVersionOperation> getPurgeIndexes(NodeStore nodeStore, long purgeThresholdMillis, List<String> indexPaths) throws IOException, CommitFailedException {
List<IndexVersionOperation> purgeIndexList = new ArrayList<>();
LOG.info("Start execute purge index over node type '{}' over index paths '{}'", nodeStore.getClass().getSimpleName(), indexPaths);
LOG.info("Getting indexes to purge over node type '{}' and index paths '{}'", nodeStore.getClass().getSimpleName(), indexPaths);
List<String> sanitisedIndexPaths = sanitiseUserIndexPaths(indexPaths);
Set<String> indexPathSet = filterIndexPaths(getRepositoryIndexPaths(nodeStore), sanitisedIndexPaths);
Map<String, Set<String>> segregateIndexes = segregateIndexes(indexPathSet);
@@ -25,12 +25,16 @@
import org.apache.jackrabbit.oak.run.cli.NodeStoreFixtureProvider;
import org.apache.jackrabbit.oak.run.cli.Options;
import org.apache.jackrabbit.oak.run.commons.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;

public class PurgeOldIndexVersionCommand implements Command {
private static final Logger LOG = LoggerFactory.getLogger(PurgeOldIndexVersionCommand.class);

private long threshold;
private List<String> indexPaths;
private long DEFAULT_PURGE_THRESHOLD = TimeUnit.DAYS.toMillis(5); // 5 days in millis
@@ -40,6 +44,9 @@ public class PurgeOldIndexVersionCommand implements Command {
public void execute(String... args) throws Exception {
Options opts = parseCommandLineParams(args);
try (NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts)) {
if (!opts.getCommonOpts().isReadWrite()) {
LOG.info("Repository connected in read-only mode. Use '--read-write' for write operations");
}
new PurgeOldIndexVersion().execute(fixture.getStore(), opts.getCommonOpts().isReadWrite(), threshold, indexPaths);
}
}

0 comments on commit 773794a

Please sign in to comment.