@Override public long getNumberOfActiveEntries() { long totalEntries = getNumberOfEntries(); PositionImpl pos = cursors.getSlowestReaderPosition(); if (pos == null) { // If there are no consumers, there are no active entries return 0; } else { // The slowest consumer will be in the first ledger in the list. We need to subtract the entries it has // already consumed in order to get the active entries count. return totalEntries - (pos.getEntryId() + 1); } }
@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 updatingCursorOutsideContainer() 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)); MockManagedCursor cursor2 = new MockManagedCursor(container, "test2", new PositionImpl(2, 2)); container.add(cursor2); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 2)); cursor2.position = new PositionImpl(8, 8); // Until we don't update the container, the ordering will not change assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 2)); container.cursorUpdated(cursor2, cursor2.position); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 5)); }
@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)); }
@Test void simple() throws Exception { ManagedCursorContainer container = new ManagedCursorContainer(); assertEquals(container.getSlowestReaderPosition(), null); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 5)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 2)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 0)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 0)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 0)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 2)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(3, 0)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(3, 5)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(4, 0)); assertEquals(container.getSlowestReaderPosition(), null); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(6, 5));
PositionImpl slowestReaderPosition = cursors.getSlowestReaderPosition(); if (slowestReaderPosition != null) { slowestReaderLedgerId = slowestReaderPosition.getLedgerId();
assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 1)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 1)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 1)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 6)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 6)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(6, 4)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(4, 4)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(4, 4)); container.removeCursor("test2"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(7, 0)); container.removeCursor("test5"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(7, 1)); container.removeCursor("test1"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(7, 1)); container.removeCursor("test4"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(8, 5)); container.removeCursor("test3");
assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 1)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 1)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 6)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 6)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 6)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 6)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(6, 4)); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(7, 0)); container.removeCursor("test5"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(7, 1)); container.removeCursor("test4"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(8, 4)); container.removeCursor("test1"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(8, 4)); container.removeCursor("test2"); assertEquals(container.getSlowestReaderPosition(), new PositionImpl(8, 5)); container.removeCursor("test3");
@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()); }
@Override public long getNumberOfActiveEntries() { long totalEntries = getNumberOfEntries(); PositionImpl pos = cursors.getSlowestReaderPosition(); if (pos == null) { // If there are no consumers, there are no active entries return 0; } else { // The slowest consumer will be in the first ledger in the list. We need to subtract the entries it has // already consumed in order to get the active entries count. return totalEntries - (pos.getEntryId() + 1); } }
@Override public long getNumberOfActiveEntries() { long totalEntries = getNumberOfEntries(); PositionImpl pos = cursors.getSlowestReaderPosition(); if (pos == null) { // If there are no consumers, there are no active entries return 0; } else { // The slowest consumer will be in the first ledger in the list. We need to subtract the entries it has // already consumed in order to get the active entries count. return totalEntries - (pos.getEntryId() + 1); } }
@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); }
PositionImpl slowestReaderPosition = cursors.getSlowestReaderPosition(); if (slowestReaderPosition != null) { slowestReaderLedgerId = slowestReaderPosition.getLedgerId();
PositionImpl slowestReaderPosition = cursors.getSlowestReaderPosition(); if (slowestReaderPosition != null) { slowestReaderLedgerId = slowestReaderPosition.getLedgerId();