OAK-12010 Simplified index management (without optimizer)#2689
OAK-12010 Simplified index management (without optimizer)#2689thomasmueller wants to merge 6 commits intotrunkfrom
Conversation
|
bhabegger
left a comment
There was a problem hiding this comment.
Nice clean work 👍
I like the test coverage and the comments among the rest !
I don't see anything blocking and just have a few comments/suggestions.
| if (!diffContent.exists()) { | ||
| continue; | ||
| } | ||
| PropertyState lastMod = diffContent.getProperty("jcr:lastModified"); |
There was a problem hiding this comment.
Is there not a constant definition for this type of "well-known" entries ? (same for :lastProcessed, jcr:data, /oak:index/, etc.)
In my opinion this helps a lot to understand, identify in one go what are the 'system' properties, paths, etc., and know where they are used. But also have them documented in the code base as javadoc.
(Not a blocker, just a curiosity 😉)
There was a problem hiding this comment.
There probably is. I agree we are not consistently using these constants, so there is a risk of typos.
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/diff/DiffIndex.java
Outdated
Show resolved
Hide resolved
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/diff/DiffIndex.java
Outdated
Show resolved
Hide resolved
| * @param store the node store | ||
| * @param indexDefinitions the /oak:index node | ||
| */ | ||
| public static void applyDiffIndexChanges(NodeStore store, NodeBuilder indexDefinitions) { |
There was a problem hiding this comment.
To ease readability maybe we could split this method in :
- parsing entries
- diffing entries
and delegate the orchestration to a caller method ?
| JsonObject repositoryDefinitions = RootIndexesListService.getRootIndexDefinitions(indexDefinitions); | ||
| LOG.debug("Index list {}", repositoryDefinitions.toString()); | ||
| try { | ||
| DiffIndexMerger.instance().merge(newImageLuceneDefinitions, repositoryDefinitions, store); |
There was a problem hiding this comment.
merge also seams to do something with diff.index and diff.index.optimizer couldn't we call the mergeDiff directly instead (without a dependency to the NodeStore)?
|
|
||
| // merge | ||
| JsonObject merged = null; | ||
| if (indexDiff == null) { |
There was a problem hiding this comment.
As an example, maybe this premerge null checking logic could be moved down into the processMerge itself ? (The "nothing to do" case could be handled by a null or Optional merged result)
| * | ||
| * "null" entries are not supported. | ||
| */ | ||
| public class JsonNodeBuilder { |
There was a problem hiding this comment.
The Builder in the name could be misleading as, unless I missed something. this class doesn't seem to follow the "Builder" pattern, and seams more like a Helper class (but then there are different style tastes out their).
There was a problem hiding this comment.
Right... It's a converter from "Json" to "NodeBuilder". It's confusing.
What about JsonNodeWriter, or JsonToNodeConverter?
There was a problem hiding this comment.
I would prefer Converter among the two as Writer is quite connotated (PrintWriter, StringWriter, etc.). However, both Writer and Converter still suggests some sort of instantiation and don't highlight that this class is a utility class.
There was a problem hiding this comment.
JsonNodeConversionUtil ?
JsonNodeConversionHelper ?
| import java.util.ArrayList; | ||
|
|
||
| import org.apache.felix.inventory.Format; | ||
| import org.apache.jackrabbit.oak.commons.json.JsonObject; |
There was a problem hiding this comment.
I'm guessing that OAK has it's own JSON processing library for historical reasons ?
| + " } }"); | ||
|
|
||
| repositoryDefinitions = RootIndexesListService.getRootIndexDefinitions(store, "lucene"); | ||
| assertSameJson("{\n" |
There was a problem hiding this comment.
It's a shame Java 11 is a bit too early for text blocks :)
There was a problem hiding this comment.
I agree (btw. text blocks are not "raw" and still need escaping).
But I think it's readable as is.
| public void createDummy() { | ||
| // when enabling "deleteCreatesDummyIndex", then a dummy index is created | ||
| // (that indexes /dummy, which doesn't exist) | ||
| String merged = new DiffIndexMerger(new String[0], true, true, false).processMerge(JsonObject.fromJson("{}" |
There was a problem hiding this comment.
Which true is it ?
| String merged = new DiffIndexMerger(new String[0], true, true, false).processMerge(JsonObject.fromJson("{}" | |
| boolean deleteCreatesDummyIndex = true; | |
| String merged = new DiffIndexMerger(new String[0], deleteCreatesDummyIndex, true, false).processMerge(JsonObject.fromJson("{}" |
Would make it explicit
There was a problem hiding this comment.
Hm, "list of boolean flags" is not user friendly... thinking about an alternative.
…/diff/DiffIndex.java Co-authored-by: Benjamin Habegger <benjamin@habegger.tech>
…/diff/DiffIndex.java Co-authored-by: Benjamin Habegger <benjamin@habegger.tech>
amit-jain
left a comment
There was a problem hiding this comment.
Overall looks good to me!!
A few minor suggestions added.
| InputStream in = jcrData.getValue(Type.BINARY).getNewStream(); | ||
| try { |
There was a problem hiding this comment.
| InputStream in = jcrData.getValue(Type.BINARY).getNewStream(); | |
| try { | |
| try (InputStream in = jcrData.getValue(Type.BINARY).getNewStream()) { |
| return result; | ||
| } | ||
|
|
||
| public static Collection<String> filterNewestIndexes(Collection<String> indexPaths, NodeState rootState) { |
There was a problem hiding this comment.
rootState ununsed parameter, consider removing
| return StringUtils.convertBytesToHex(md.digest(bytes)); | ||
| } catch (NoSuchAlgorithmException e) { | ||
| // SHA-256 is guaranteed to be available in standard Java platforms | ||
| throw new RuntimeException("SHA-256 algorithm not available", e); |
There was a problem hiding this comment.
Maybe IllegalStateException is better?
| merged.getProperties().remove("reindex"); | ||
| if (!deleteCopiesOutOfTheBoxIndex && indexDiff.toString().equals("{}")) { | ||
| merged.getProperties().put("type", "\"disabled\""); | ||
| merged.getProperties().put("mergeComment", "\"This index is superseeded and can be removed\""); |
There was a problem hiding this comment.
| merged.getProperties().put("mergeComment", "\"This index is superseeded and can be removed\""); | |
| merged.getProperties().put("mergeComment", "\"This index is superseded and can be removed\""); |
| } | ||
| } | ||
| for (String r : toRemove) { | ||
| LOG.info("Removing old index " + r); |
There was a problem hiding this comment.
| LOG.info("Removing old index " + r); | |
| LOG.info("Removing old index {}", r); |
| * (input) | ||
| * @return whether a new version of an index was added | ||
| */ | ||
| public boolean processMerge(String indexName, JsonObject indexDiff, JsonObject newImageLuceneDefinitions, JsonObject combined) { |
There was a problem hiding this comment.
yes recommend breaking this method, example (from comments)
- findLatestVersions
- performMerge
- isChanged
- addMetadata
| } | ||
| LOG.info("Processing a new diff.index with node store {}", store); | ||
| JsonObject repositoryDefinitions = RootIndexesListService.getRootIndexDefinitions(indexDefinitions); | ||
| LOG.debug("Index list {}", repositoryDefinitions.toString()); |
There was a problem hiding this comment.
| LOG.debug("Index list {}", repositoryDefinitions.toString()); | |
| LOG.debug("Index list {}", repositoryDefinitions); |
| */ | ||
| public static void addOrReplace(NodeBuilder builder, NodeStore nodeStore, String targetPath, String nodeType, String jsonString) throws CommitFailedException, IOException { | ||
| LOG.info("Storing {}: {}", targetPath, jsonString); | ||
| if (nodeType.indexOf("/") >= 0) { |
There was a problem hiding this comment.
| if (nodeType.indexOf("/") >= 0) { | |
| if (nodeType.contains("/")) { |



This is a subset of the (much) larger draft PR #2652
This is just support for the "diff.index"; without the optimizer.