@Override public void run() { async.run(); } });
@Override protected void postIndexUpdate() { executed.set(true); assertRunKo(new AsyncIndexUpdate(name, store, provider)); } };
public void registerAsyncIndexer(AsyncIndexUpdate task, long delayInSeconds) { task.setIndexMBeanRegistration(this); Map<String, Object> config = ImmutableMap.<String, Object>of( AsyncIndexUpdate.PROP_ASYNC_NAME, task.getName(), "scheduler.name", AsyncIndexUpdate.class.getName() + "-" + task.getName() ); regs.add(scheduleWithFixedDelay(whiteboard, task, config, delayInSeconds, RUN_ON_LEADER, true)); regs.add(registerMBean(whiteboard, IndexStatsMBean.class, task.getIndexStats(), IndexStatsMBean.TYPE, task.getName())); }
@Override public String call() throws Exception { long t0 = nanoTime(); boolean done = false; while (!done) { async.run(); done = async.isFinished(); } return "Reindex completed in " + formatTime(nanoTime() - t0); } });
public AsyncIndexUpdate(@Nonnull String name, @Nonnull NodeStore store, @Nonnull IndexEditorProvider provider, StatisticsProvider statsProvider, boolean switchOnSync) { this.name = checkValidName(name); this.lastIndexedTo = lastIndexedTo(name); this.store = checkNotNull(store); this.provider = checkNotNull(provider); this.switchOnSync = switchOnSync; this.leaseTimeOut = DEFAULT_ASYNC_TIMEOUT; this.statisticsProvider = statsProvider; this.indexStats = new AsyncIndexStats(name, statsProvider); }
if (isLeaseCheckEnabled(leaseTimeOut)) { long leaseEndTime = async.getLong(leasify(name)); long currentTime = System.currentTimeMillis(); if (leaseEndTime > currentTime) { String err = String.format("Another copy of the index update is already running; skipping this update. " + "Time left for lease to expire %d s. Indexing can resume by %tT", leaseExpMsg, leaseEndTime); indexStats.failed(new Exception(err, newConcurrentUpdateException())); return; preAsyncRunStatsStats(indexStats); AsyncUpdateCallback callback = newAsyncUpdateCallback(store, name, leaseTimeOut, beforeCheckpoint, indexStats, forcedStopFlag); callback.setCheckpoint(beforeCheckpoint); before = MISSING_NODE; } else if (noVisibleChanges(state, root) && !switchOnSync) { log.debug( "[{}] No changes since last checkpoint; skipping the index update", name); postAsyncRunStatsStatus(indexStats); return; } else { String afterTime = now(); String oldThreadName = Thread.currentThread().getName();
@Test public void names() throws Exception{ AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider); async.run(); AsyncIndexUpdate async2 = new AsyncIndexUpdate("foo-async", store, provider); async2.run(); Set<String> names = ImmutableSet.copyOf(service.getAsyncLanes()); assertThat(names, containsInAnyOrder("async", "foo-async")); service.bindStatsMBeans(async.getIndexStats()); service.bindStatsMBeans(async2.getIndexStats()); }
@Test public void testPrePrepare() throws Exception { // take care of initial reindex before new AsyncIndexUpdate(name, store, provider).run(); final IndexStatusListener l1 = new IndexStatusListener() { @Override protected void prePrepare() { executed.set(true); assertRunOk(new AsyncIndexUpdate(name, store, provider)); } }; assertRunKo(new SpecialAsyncIndexUpdate(name, store, provider, l1)); }
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); AsyncIndexUpdate pre = new AsyncIndexUpdate("async", store, provider); pre.run(); builder.child("testRoot2").setProperty("foo", "abc"); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); pre.run(); pre.close(); String checkpointName = async.getString("async"); if (store.retrieve(checkpointName) == null && async.getProperty(AsyncIndexUpdate.leasify("async")) == null){ oldRootState.set(ns); break; async.run(); assertTrue(async.getIndexStats().isFailing()); async.close();
@Test public void locking() throws Exception{ new AsyncIndexUpdate(name, store, provider).run(); assertFalse(getAsync().hasProperty(AsyncIndexUpdate.leasify(name))); ClusterNodeStoreLock lock = new ClusterNodeStoreLock(store); ClusteredLockToken token = lock.lock("async"); assertTrue(getAsync().hasProperty(AsyncIndexUpdate.leasify(name))); assertTrue(lock.isLocked(name)); lock.unlock(token); assertFalse(getAsync().hasProperty(AsyncIndexUpdate.leasify(name))); assertFalse(lock.isLocked(name)); }
@Test public void cpCleanupNoChanges() throws Exception { MemoryNodeStore store = new MemoryNodeStore(); IndexEditorProvider provider = new PropertyIndexEditorProvider(); AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider); assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0); // no changes on diff, no checkpoints left behind async.run(); assertTrue(async.isFinished()); Set<String> checkpoints = newHashSet(store.listCheckpoints()); assertTrue("Expecting the initial checkpoint", checkpoints.size() == 1); assertEquals(store.getRoot().getChildNode(ASYNC) .getString("async"), checkpoints.iterator().next()); async.run(); assertEquals("Expecting no checkpoint changes", checkpoints, store.listCheckpoints()); }
AsyncIndexUpdate async = new AsyncIndexUpdate(missingAsync, store, provider); async.run(); assertFalse(async.isFailing()); assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1); async = new AsyncIndexUpdate(missingAsync, store, provider); async.run(); assertTrue(async.isFailing());
@Test public void testLeaseDisabled() throws Exception { // take care of initial reindex before AsyncIndexUpdate async = new AsyncIndexUpdate(name, store, provider).setLeaseTimeOut(0); async.run(); testContent(store); assertRunOk(async); testContent(store); assertRunOk(async); executed.set(true); }
private void registerAsyncReindexSupport(Whiteboard whiteboard) { // async reindex String name = IndexConstants.ASYNC_REINDEX_VALUE; AsyncIndexUpdate task = new AsyncIndexUpdate(name, nodeStore, indexEditorProvider, statisticsProvider, true); PropertyIndexAsyncReindex asyncPI = new PropertyIndexAsyncReindex(task, executor); final Registration reg = new CompositeRegistration( registerMBean(whiteboard, PropertyIndexAsyncReindexMBean.class, asyncPI, PropertyIndexAsyncReindexMBean.TYPE, "async"), registerMBean(whiteboard, IndexStatsMBean.class, task.getIndexStats(), IndexStatsMBean.TYPE, name)); closer.register(new Closeable() { @Override public void close() throws IOException { reg.unregister(); } }); }
@Test public void testAsyncPropertyNoChanges() throws Exception { NodeStore store = new MemoryNodeStore(); assertTrue(Iterables.isEmpty(store.checkpoints())); AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true); async.run(); async.run(); async.close(); assertTrue(Iterables.isEmpty(store.checkpoints())); } }
@Test public void asyncStateChanged() throws Exception{ AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider); async.run(); AsyncIndexUpdate async2 = new AsyncIndexUpdate("foo-async", store, provider); async2.run(); NodeState root = store.getRoot(); assertFalse(service.hasIndexerUpdatedForAnyLane(root, root)); NodeBuilder builder = store.getRoot().builder(); builder.child(":async").setProperty(AsyncIndexUpdate.lastIndexedTo("async"), 42L); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); assertTrue(service.hasIndexerUpdatedForAnyLane(root, store.getRoot())); }
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider); async.getCorruptIndexHandler().setClock(clock); async.run(); async.run(); assertTrue(async.getIndexStats().isFailing()); assertTrue(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/barIndex")); assertFalse(async.getCorruptIndexHandler().getCorruptIndexData("async").containsKey("/oak:index/barIndex")); CorruptIndexInfo barIndexInfo = async.getCorruptIndexHandler().getFailingIndexData("async").get("/oak:index/barIndex"); assertFalse(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/fooIndex")); clock.waitUntil(clock.getTime() + async.getCorruptIndexHandler().getCorruptIntervalMillis() + 1); async.run(); assertTrue(async.getIndexStats().isFailing()); assertEquals(IndexStatsMBean.STATUS_FAILING, async.getIndexStats().getStatus()); assertTrue(async.getCorruptIndexHandler().getCorruptIndexData("async").containsKey("/oak:index/barIndex")); async.run(); assertTrue(async.getIndexStats().isFailing()); async.run(); assertFalse(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/barIndex"));
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider); async.run(); assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1); async.run(); assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1); c.setTimeInMillis(clock.getTime() - 2 * async.getLeaseTimeOut()); info.put("created", ISO8601.format(c)); assertNotNull(store.checkpoint(TimeUnit.HOURS.toMillis(1), info)); store.listCheckpoints().size() == 2); async.cleanUpCheckpoints(); assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
public AsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String checkpoint, AsyncIndexStats indexStats, AtomicBoolean forcedStop) { this.store = store; this.name = name; this.forcedStop = forcedStop; this.leaseTimeOut = leaseTimeOut; this.checkpoint = checkpoint; this.tempCpName = getTempCpName(name); this.indexStats = indexStats; this.leaseName = leasify(name); }