IndexDisabler { public List<String> disableOldIndexes(String currentIndexPath, NodeBuilder idxBuilder) { PropertyState indexPathsProp = idxBuilder.getProperty(SUPERSEDED_INDEX_PATHS); if (indexPathsProp == null) { return emptyList(); } if (!idxBuilder.getBoolean(DISABLE_INDEXES_ON_NEXT_CYCLE)) { return emptyList(); } if (!idxBuilder.getBaseState().getBoolean(DISABLE_INDEXES_ON_NEXT_CYCLE)){ return emptyList(); } Iterable<String> indexPaths = indexPathsProp.getValue(Type.STRINGS); List<String> disabledIndexes = new ArrayList<>(); for (final String indexPath : indexPaths) { if (isNodeTypePath(indexPath)) { String nodeTypeName = PathUtils.getName(indexPath).substring(1); String nodeTypeIndexPath = PathUtils.getParentPath(indexPath); NodeBuilder nodeTypeIndexBuilder = child(rootBuilder, nodeTypeIndexPath); PropertyState declaringNodeTypes = nodeTypeIndexBuilder.getProperty(DECLARING_NODE_TYPES); if (nodeTypeIndexBuilder.exists() && declaringNodeTypes != null){ Set<String> existingTypes = Sets.newHashSet(declaringNodeTypes.getValue(Type.NAMES)); if (existingTypes.remove(nodeTypeName)) { disabledIndexes.add(indexPath); nodeTypeIndexBuilder.setProperty(DECLARING_NODE_TYPES, existingTypes, Type.NAMES); } } } else { NodeBuilder disabledIndexBuilder = child(rootBuilder, indexPath); if (disabledIndexBuilder.exists()) { disabledIndexBuilder.setProperty(TYPE_PROPERTY_NAME, TYPE_DISABLED); disabledIndexes.add(indexPath); } } } if (!disabledIndexes.isEmpty()) { log.info("Index at [{}] supersedes indexes {}. Marking those as disabled", currentIndexPath, disabledIndexes); idxBuilder.removeProperty(DISABLE_INDEXES_ON_NEXT_CYCLE); } return disabledIndexes; } IndexDisabler(NodeBuilder rootBuilder); boolean markDisableFlagIfRequired(String currentIndexPath, NodeBuilder idxBuilder); List<String> disableOldIndexes(String currentIndexPath, NodeBuilder idxBuilder);  }
@Test public void simpleIndex() throws Exception{ List<String> disabledIndexes = disabler.disableOldIndexes("/oak:index/foo", builder); assertTrue(disabledIndexes.isEmpty()); }
@Test public void nodeTypeIndexDisabling_noop() throws Exception{ builder.setProperty(IndexConstants.DISABLE_INDEXES_ON_NEXT_CYCLE, true); builder.setProperty(IndexConstants.SUPERSEDED_INDEX_PATHS, asList("/oak:index/fooIndex/@bar"), Type.STRINGS); refreshBuilder(); List<String> disabledIndexes = disabler.disableOldIndexes("/oak:index/foo", builder); assertTrue(disabledIndexes.isEmpty()); }