@Override public void operationComplete(Void result, Stat stat) { cursor.asyncDeleteCursorLedger(); cursors.removeCursor(consumerName); // Redo invalidation of entries in cache PositionImpl slowestConsumerPosition = cursors.getSlowestReaderPosition(); if (slowestConsumerPosition != null) { if (log.isDebugEnabled()) { log.debug("Doing cache invalidation up to {}", slowestConsumerPosition); } entryCache.invalidateEntries(slowestConsumerPosition); } else { entryCache.clear(); } trimConsumedLedgersInBackground(); log.info("[{}] [{}] Deleted cursor", name, consumerName); callback.deleteCursorComplete(ctx); }
@Test void removingCursor() throws Exception { ManagedCursorContainer container = new ManagedCursorContainer(); ManagedCursor cursor1 = new MockManagedCursor(container, "test1", new PositionImpl(5, 5)); container.add(cursor1); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 5)); assertEquals(container.get("test1"), cursor1); MockManagedCursor cursor2 = new MockManagedCursor(container, "test2", new PositionImpl(2, 2)); container.add(cursor2); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 2)); assertEquals(container.get("test2"), cursor2); MockManagedCursor cursor3 = new MockManagedCursor(container, "test3", new PositionImpl(1, 1)); container.add(cursor3); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(1, 1)); assertEquals(container.get("test3"), cursor3); assertEquals(container, Lists.newArrayList(cursor1, cursor2, cursor3)); // Remove the cursor in the middle container.removeCursor("test2"); assertEquals(container, Lists.newArrayList(cursor1, cursor3)); assertEquals(container.get("test2"), null); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(1, 1)); container.removeCursor("test3"); assertEquals(container, Lists.newArrayList(cursor1)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 5)); }
public void deactivateCursor(ManagedCursor cursor) { synchronized (activeCursors) { if (activeCursors.get(cursor.getName()) != null) { activeCursors.removeCursor(cursor.getName()); if (activeCursors.isEmpty()) { // cleanup cache if there is no active subscription entryCache.clear(); } else { // if removed subscription was the slowest subscription : update cursor and let it clear cache: // till new slowest-cursor's read-position discardEntriesFromCache((ManagedCursorImpl) activeCursors.getSlowestReader(), getPreviousPosition((PositionImpl) activeCursors.getSlowestReader().getReadPosition())); } } } }
@Test void ordering() throws Exception { ManagedCursorContainer container = new ManagedCursorContainer(); ManagedCursor cursor1 = new MockManagedCursor(container, "test1", new PositionImpl(5, 5)); ManagedCursor cursor2 = new MockManagedCursor(container, "test2", new PositionImpl(5, 1)); ManagedCursor cursor3 = new MockManagedCursor(container, "test3", new PositionImpl(7, 1)); ManagedCursor cursor4 = new MockManagedCursor(container, "test4", new PositionImpl(6, 4)); ManagedCursor cursor5 = new MockManagedCursor(container, "test5", new PositionImpl(7, 0)); container.add(cursor1); container.add(cursor2); container.add(cursor3); container.add(cursor4); container.add(cursor5); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 1)); container.removeCursor("test2"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 5)); container.removeCursor("test1"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(6, 4)); container.removeCursor("test4"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(7, 0)); container.removeCursor("test5"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(7, 1)); container.removeCursor("test3"); assertTrue(container.isEmpty()); }
assertEquals(container.getSlowestReaderPosition(), new PositionImpl(3, 0)); container.removeCursor(cursor3.getName()); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(3, 5)); container.removeCursor(cursor2.getName()); container.removeCursor(cursor5.getName()); container.removeCursor(cursor1.getName()); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(4, 0)); container.removeCursor(cursor4.getName()); assertEquals(container.getSlowestReaderPosition(), null);
container.removeCursor("test2"); container.removeCursor("test5"); container.removeCursor("test1"); container.removeCursor("test4"); container.removeCursor("test3");
container.removeCursor("test5"); container.removeCursor("test4"); container.removeCursor("test1"); container.removeCursor("test2"); container.removeCursor("test3");
@Override public void operationComplete(Void result, Stat stat) { cursor.asyncDeleteCursorLedger(); cursors.removeCursor(consumerName); // Redo invalidation of entries in cache PositionImpl slowestConsumerPosition = cursors.getSlowestReaderPosition(); if (slowestConsumerPosition != null) { if (log.isDebugEnabled()) { log.debug("Doing cache invalidation up to {}", slowestConsumerPosition); } entryCache.invalidateEntries(slowestConsumerPosition); } else { entryCache.clear(); } trimConsumedLedgersInBackground(); log.info("[{}] [{}] Deleted cursor", name, consumerName); callback.deleteCursorComplete(ctx); }
@Override public void operationComplete(Void result, Stat stat) { cursor.asyncDeleteCursorLedger(); cursors.removeCursor(consumerName); // Redo invalidation of entries in cache PositionImpl slowestConsumerPosition = cursors.getSlowestReaderPosition(); if (slowestConsumerPosition != null) { if (log.isDebugEnabled()) { log.debug("Doing cache invalidation up to {}", slowestConsumerPosition); } entryCache.invalidateEntries(slowestConsumerPosition); } else { entryCache.clear(); } trimConsumedLedgersInBackground(); log.info("[{}] [{}] Deleted cursor", name, consumerName); callback.deleteCursorComplete(ctx); }
public void deactivateCursor(ManagedCursor cursor) { if (activeCursors.get(cursor.getName()) != null) { activeCursors.removeCursor(cursor.getName()); if (activeCursors.isEmpty()) { // cleanup cache if there is no active subscription entryCache.clear(); } else { // if removed subscription was the slowest subscription : update cursor and let it clear cache: till // new slowest-cursor's read-position discardEntriesFromCache((ManagedCursorImpl) activeCursors.getSlowestReader(), getPreviousPosition((PositionImpl) activeCursors.getSlowestReader().getReadPosition())); } } }
public void deactivateCursor(ManagedCursor cursor) { synchronized (activeCursors) { if (activeCursors.get(cursor.getName()) != null) { activeCursors.removeCursor(cursor.getName()); if (activeCursors.isEmpty()) { // cleanup cache if there is no active subscription entryCache.clear(); } else { // if removed subscription was the slowest subscription : update cursor and let it clear cache: // till new slowest-cursor's read-position discardEntriesFromCache((ManagedCursorImpl) activeCursors.getSlowestReader(), getPreviousPosition((PositionImpl) activeCursors.getSlowestReader().getReadPosition())); } } } }