You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by GitBox <gi...@apache.org> on 2022/03/16 10:46:42 UTC
[GitHub] [jackrabbit-oak] thomasmueller commented on a change in pull request #520: GRANITE-38542 Adding cronjob for call cleanup index command which imp…
thomasmueller commented on a change in pull request #520:
URL: https://github.com/apache/jackrabbit-oak/pull/520#discussion_r827865527
##########
File path: oak-run/src/main/java/org/apache/jackrabbit/oak/indexversion/PurgeOldIndexVersion.java
##########
@@ -38,43 +43,59 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
public class PurgeOldIndexVersion {
private static final Logger LOG = LoggerFactory.getLogger(PurgeOldIndexVersion.class);
- public void execute(Options opts, long purgeThresholdMillis, List<String> indexPaths) throws Exception {
- boolean isReadWriteRepository = opts.getCommonOpts().isReadWrite();
+ /**
+ * Execute purging index based on the index version naming and last time index time
+ *
+ * @param nodeStore the node store
+ * @param isReadWriteRepository bool to indicate if it's read write repository, if yes, the purge index will not execute
+ * @param purgeThresholdMillis the threshold of time length since last time index time to determine, will purge if exceed that
+ * @param indexPaths the index path or parent path
+ *
+ * @throws IOException
+ * @throws CommitFailedException
+ */
+ public void execute(NodeStore nodeStore, boolean isReadWriteRepository, long purgeThresholdMillis, List<String> indexPaths) throws IOException, CommitFailedException {
if (!isReadWriteRepository) {
- LOG.info("Repository connected in read-only mode. Use '--read-write' for write operations");
+ LOG.info("Repository is opened in read-only mode");
Review comment:
I prefer the message above (with --read-write)
##########
File path: oak-run/src/main/java/org/apache/jackrabbit/oak/indexversion/PurgeOldIndexVersion.java
##########
@@ -38,43 +43,59 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
public class PurgeOldIndexVersion {
private static final Logger LOG = LoggerFactory.getLogger(PurgeOldIndexVersion.class);
- public void execute(Options opts, long purgeThresholdMillis, List<String> indexPaths) throws Exception {
- boolean isReadWriteRepository = opts.getCommonOpts().isReadWrite();
+ /**
+ * Execute purging index based on the index version naming and last time index time
+ *
+ * @param nodeStore the node store
+ * @param isReadWriteRepository bool to indicate if it's read write repository, if yes, the purge index will not execute
+ * @param purgeThresholdMillis the threshold of time length since last time index time to determine, will purge if exceed that
+ * @param indexPaths the index path or parent path
+ *
+ * @throws IOException
+ * @throws CommitFailedException
+ */
+ public void execute(NodeStore nodeStore, boolean isReadWriteRepository, long purgeThresholdMillis, List<String> indexPaths) throws IOException, CommitFailedException {
if (!isReadWriteRepository) {
- LOG.info("Repository connected in read-only mode. Use '--read-write' for write operations");
+ LOG.info("Repository is opened in read-only mode");
+ return;
Review comment:
The old code allowed to just list the indexes that can be removed. Now this feature is gone... Why? I would prefer to keep it (it looks like it's quite easy to keep it).
##########
File path: oak-run/src/main/java/org/apache/jackrabbit/oak/indexversion/PurgeOldIndexVersion.java
##########
@@ -38,43 +43,59 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
public class PurgeOldIndexVersion {
private static final Logger LOG = LoggerFactory.getLogger(PurgeOldIndexVersion.class);
- public void execute(Options opts, long purgeThresholdMillis, List<String> indexPaths) throws Exception {
- boolean isReadWriteRepository = opts.getCommonOpts().isReadWrite();
+ /**
+ * Execute purging index based on the index version naming and last time index time
+ *
+ * @param nodeStore the node store
+ * @param isReadWriteRepository bool to indicate if it's read write repository, if yes, the purge index will not execute
+ * @param purgeThresholdMillis the threshold of time length since last time index time to determine, will purge if exceed that
+ * @param indexPaths the index path or parent path
+ *
+ * @throws IOException
+ * @throws CommitFailedException
+ */
+ public void execute(NodeStore nodeStore, boolean isReadWriteRepository, long purgeThresholdMillis, List<String> indexPaths) throws IOException, CommitFailedException {
if (!isReadWriteRepository) {
- LOG.info("Repository connected in read-only mode. Use '--read-write' for write operations");
+ LOG.info("Repository is opened in read-only mode");
+ return;
}
- try (NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts)) {
- NodeStore nodeStore = fixture.getStore();
- List<String> sanitisedIndexPaths = sanitiseUserIndexPaths(indexPaths);
- Set<String> indexPathSet = filterIndexPaths(getRepositoryIndexPaths(nodeStore), sanitisedIndexPaths);
- Map<String, Set<String>> segregateIndexes = segregateIndexes(indexPathSet);
- for (Map.Entry<String, Set<String>> entry : segregateIndexes.entrySet()) {
- String baseIndexPath = entry.getKey();
- String parentPath = PathUtils.getParentPath(entry.getKey());
- List<IndexName> indexNameObjectList = getIndexNameObjectList(entry.getValue());
- NodeState indexDefParentNode = NodeStateUtils.getNode(nodeStore.getRoot(),
- parentPath);
- List<IndexVersionOperation> toDeleteIndexNameObjectList =
- IndexVersionOperation.generateIndexVersionOperationList(indexDefParentNode, indexNameObjectList, purgeThresholdMillis);
- if (isReadWriteRepository && !toDeleteIndexNameObjectList.isEmpty()) {
- purgeOldIndexVersion(nodeStore, toDeleteIndexNameObjectList);
- } else {
- LOG.info("Repository is opened in read-only mode: IndexOperations" +
- " for index at path {} are : {}", baseIndexPath, toDeleteIndexNameObjectList);
- }
+ 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));
+ } 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);
Review comment:
I would log "Getting indexes to purge ..." as in this method we don't purge.
--
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: dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org