@Override public Iterable<IndexInfo> getAllIndexInfo() { return Iterables.filter(Iterables.transform(indexPathService.getIndexPaths(), new Function<String, IndexInfo>() { @Override public IndexInfo apply(String indexPath) { try { return getInfo(indexPath); } catch (Exception e) { log.warn("Error occurred while capturing IndexInfo for path {}", indexPath, e); return null; } } }), notNull()); }
@Override public Iterable<IndexInfo> getAllIndexInfo() { return Iterables.filter(Iterables.transform(indexPathService.getIndexPaths(), new Function<String, IndexInfo>() { @Override public IndexInfo apply(String indexPath) { try { return getInfo(indexPath); } catch (Exception e) { log.warn("Error occurred while capturing IndexInfo for path {}", indexPath, e); return null; } } }), notNull()); }
@Override public Iterable<IndexInfo> getAllIndexInfo() { return Iterables.filter(Iterables.transform(indexPathService.getIndexPaths(), new Function<String, IndexInfo>() { @Override public IndexInfo apply(String indexPath) { try { return getInfo(indexPath); } catch (Exception e) { log.warn("Error occurred while capturing IndexInfo for path {}", indexPath, e); return null; } } }), notNull()); }
static IndexPathService getIndexPathsService(List<String> indexPaths) { IndexPathService service = mock(IndexPathService.class); when(service.getIndexPaths()).thenReturn(indexPaths); return service; } }
List<String> getSyncIndexPaths() { List<String> indexPaths = new ArrayList<>(); NodeState root = nodeStore.getRoot(); for (String indexPath : indexPathService.getIndexPaths()) { NodeState idx = getNode(root, indexPath); if (TYPE_LUCENE.equals(idx.getString(TYPE_PROPERTY_NAME)) && idx.hasChildNode(PROPERTY_INDEX)) { indexPaths.add(indexPath); } } return indexPaths; }
@Override public String[] checkAndReportConsistencyOfAllIndexes(boolean fullCheck) throws IOException { Stopwatch watch = Stopwatch.createStarted(); List<String> results = new ArrayList<>(); NodeState root = nodeStore.getRoot(); for (String indexPath : indexPathService.getIndexPaths()) { NodeState idxState = NodeStateUtils.getNode(root, indexPath); if (LuceneIndexConstants.TYPE_LUCENE.equals(idxState.getString(IndexConstants.TYPE_PROPERTY_NAME))) { Result result = getConsistencyCheckResult(indexPath, fullCheck); String msg = "OK"; if (!result.clean) { msg = "NOT OK"; } results.add(String.format("%s : %s", indexPath, msg)); } } log.info("Checked index consistency in {}. Check result {}", watch, results); return Iterables.toArray(results, String.class); }
@Override public String[] checkAndReportConsistencyOfAllIndexes(boolean fullCheck) throws IOException { Stopwatch watch = Stopwatch.createStarted(); List<String> results = new ArrayList<>(); NodeState root = nodeStore.getRoot(); for (String indexPath : indexPathService.getIndexPaths()) { NodeState idxState = NodeStateUtils.getNode(root, indexPath); if (LuceneIndexConstants.TYPE_LUCENE.equals(idxState.getString(IndexConstants.TYPE_PROPERTY_NAME))) { Result result = getConsistencyCheckResult(indexPath, fullCheck); String msg = "OK"; if (!result.clean) { msg = "NOT OK"; } results.add(String.format("%s : %s", indexPath, msg)); } } log.info("Checked index consistency in {}. Check result {}", watch, results); return Iterables.toArray(results, String.class); }
List<String> getSyncIndexPaths() { List<String> indexPaths = new ArrayList<>(); NodeState root = nodeStore.getRoot(); for (String indexPath : indexPathService.getIndexPaths()) { NodeState idx = getNode(root, indexPath); if (TYPE_LUCENE.equals(idx.getString(TYPE_PROPERTY_NAME)) && idx.hasChildNode(PROPERTY_INDEX)) { indexPaths.add(indexPath); } } return indexPaths; }
@Override public boolean checkConsistencyOfAllIndexes(boolean fullCheck) throws IOException { Stopwatch watch = Stopwatch.createStarted(); NodeState root = nodeStore.getRoot(); boolean clean = true; for (String indexPath : indexPathService.getIndexPaths()) { NodeState idxState = NodeStateUtils.getNode(root, indexPath); if (LuceneIndexConstants.TYPE_LUCENE.equals(idxState.getString(IndexConstants.TYPE_PROPERTY_NAME))) { Result result = getConsistencyCheckResult(indexPath, fullCheck); if (!result.clean) { clean = false; break; } } } log.info("Checked index consistency in {}. Check result {}", watch, clean); return clean; }
@Override public boolean checkConsistencyOfAllIndexes(boolean fullCheck) throws IOException { Stopwatch watch = Stopwatch.createStarted(); NodeState root = nodeStore.getRoot(); boolean clean = true; for (String indexPath : indexPathService.getIndexPaths()) { NodeState idxState = NodeStateUtils.getNode(root, indexPath); if (LuceneIndexConstants.TYPE_LUCENE.equals(idxState.getString(IndexConstants.TYPE_PROPERTY_NAME))) { Result result = getConsistencyCheckResult(indexPath, fullCheck); if (!result.clean) { clean = false; break; } } } log.info("Checked index consistency in {}. Check result {}", watch, clean); return clean; }
@Test public void noErrorIfQueryDefinitionsNotIndexed() throws Exception{ Set<String> paths = Sets.newHashSet(indexPathService.getIndexPaths()); assertThat(paths, hasItem("/oak:index/uuid")); }
private void markCurrentIndexFilesUnsafeForActiveDeletion() throws CommitFailedException { NodeBuilder rootBuilder = store.getRoot().builder(); for (String indexPath : indexPathService.getIndexPaths()) { markCurrentIndexFilesUnsafeForActiveDeletionFor(rootBuilder, indexPath); } store.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); }
private void markCurrentIndexFilesUnsafeForActiveDeletion() throws CommitFailedException { NodeBuilder rootBuilder = store.getRoot().builder(); for (String indexPath : indexPathService.getIndexPaths()) { markCurrentIndexFilesUnsafeForActiveDeletionFor(rootBuilder, indexPath); } store.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); }
@Test public void nodeTypeIndexed() throws Exception{ enableIndexDefinitionIndex(); Set<String> paths = Sets.newHashSet(indexPathService.getIndexPaths()); assertThat(paths, hasItem("/oak:index/uuid")); assertThat(paths, hasItem("/oak:index/nodetype")); assertThat(paths, hasItem("/oak:index/reference")); }
@Override public void print(PrintWriter printWriter, Format format, boolean isZip) { if (format == Format.JSON) { NodeState root = nodeStore.getRoot(); JsopBuilder json = new JsopBuilder(); json.object(); for (String indexPath : indexPathService.getIndexPaths()) { json.key(indexPath); NodeState idxState = NodeStateUtils.getNode(root, indexPath); createSerializer(json).serialize(idxState); } json.endObject(); printWriter.print(JsopBuilder.prettyPrint(json.toString())); } }
@Override public void print(PrintWriter printWriter, Format format, boolean isZip) { if (format == Format.JSON) { NodeState root = nodeStore.getRoot(); JsopBuilder json = new JsopBuilder(); json.object(); for (String indexPath : indexPathService.getIndexPaths()) { json.key(indexPath); NodeState idxState = NodeStateUtils.getNode(root, indexPath); createSerializer(json).serialize(idxState); } json.endObject(); printWriter.print(JsopBuilder.prettyPrint(json.toString())); } }
@Override public void print(PrintWriter printWriter, Format format, boolean isZip) { if (format == Format.JSON) { NodeState root = nodeStore.getRoot(); JsopBuilder json = new JsopBuilder(); json.object(); for (String indexPath : indexPathService.getIndexPaths()) { json.key(indexPath); NodeState idxState = NodeStateUtils.getNode(root, indexPath); createSerializer(json).serialize(idxState); } json.endObject(); printWriter.print(JsopBuilder.prettyPrint(json.toString())); } }
@Test public void binaryProps() throws Exception{ NodeBuilder builder = store.getRoot().builder(); builder.child("a").setProperty("foo", new ArrayBasedBlob("hello".getBytes())); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); when(pathService.getIndexPaths()).thenReturn(Lists.newArrayList("/a")); String json = getJSON(); IndexDefinitionUpdater updater = new IndexDefinitionUpdater(json); assertTrue(updater.getIndexPaths().contains("/a")); }
@Test(expected = IllegalStateException.class) public void errorIfNodetypeIndexDisabled() throws Exception{ Tree tree = root.getTree("/oak:index/nodetype"); tree.setProperty("type", "disabled"); root.commit(); indexPathService.getIndexPaths(); }
@Test public void orderOfFlaggingWaitForIndexersAndUpdateIndexFiles() { final AtomicBoolean isPaused = new AtomicBoolean(); final AtomicBoolean hadWaitedForIndex = new AtomicBoolean(); IndexPathService indexPathService = mock(IndexPathService.class); when(indexPathService.getIndexPaths()).then(mockObj -> { assertTrue("Must wait for indexers before going to update index files", hadWaitedForIndex.get()); return indexPaths; }); AsyncIndexInfoService asyncIndexInfoService = MockRegistrar.getAsyncIndexInfoService(newArrayList( new IndexMBeanInfoSupplier("foo-async", () -> { assertTrue("Must pause before waiting for indexers", isPaused.get()); hadWaitedForIndex.set(true); return STATUS_DONE; }, () -> 2L) )); ActiveDeletedBlobCollectorMBeanImpl bean = new ActiveDeletedBlobCollectorMBeanImpl(new PauseNotifyingActiveDeletedBlobCollector(() -> { isPaused.set(true); return null; }), wb, nodeStore, indexPathService, asyncIndexInfoService, new MemoryBlobStore(), sameThreadExecutor()); bean.clock = clock; bean.flagActiveDeletionUnsafeForCurrentState(); }