@Test(timeOut = 20000) void updatingCursorNode() throws Exception { final MetaStore store = new MetaStoreImplZookeeper(zkc, executor); zkc.create("/managed-ledgers/my_test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); final CountDownLatch latch = new CountDownLatch(1); ManagedCursorInfo info = ManagedCursorInfo.newBuilder().setCursorsLedgerId(1).build(); store.asyncUpdateCursorInfo("my_test", "c1", info, null, new MetaStoreCallback<Void>() { public void operationFailed(MetaStoreException e) { fail("should have succeeded"); } public void operationComplete(Void result, Stat version) { // Update again using the version zkc.failNow(Code.CONNECTIONLOSS); ManagedCursorInfo info = ManagedCursorInfo.newBuilder().setCursorsLedgerId(2).build(); store.asyncUpdateCursorInfo("my_test", "c1", info, version, new MetaStoreCallback<Void>() { public void operationFailed(MetaStoreException e) { // ok latch.countDown(); } @Override public void operationComplete(Void result, Stat version) { fail("should have failed"); } }); } }); latch.await(); }
public void operationComplete(Void result, Stat version) { // Update again using the version zkc.failNow(Code.CONNECTIONLOSS); ManagedCursorInfo info = ManagedCursorInfo.newBuilder().setCursorsLedgerId(2).build(); store.asyncUpdateCursorInfo("my_test", "c1", info, version, new MetaStoreCallback<Void>() { public void operationFailed(MetaStoreException e) { // ok latch.countDown(); } @Override public void operationComplete(Void result, Stat version) { fail("should have failed"); } }); } });
private void persistPositionMetaStore(long cursorsLedgerId, PositionImpl position, Map<String, Long> properties, MetaStoreCallback<Void> callback, boolean persistIndividualDeletedMessageRanges) { // When closing we store the last mark-delete position in the z-node itself, so we won't need the cursor ledger, // hence we write it as -1. The cursor ledger is deleted once the z-node write is confirmed. ManagedCursorInfo.Builder info = ManagedCursorInfo.newBuilder() // .setCursorsLedgerId(cursorsLedgerId) // .setMarkDeleteLedgerId(position.getLedgerId()) // .setMarkDeleteEntryId(position.getEntryId()) // .setLastActive(lastActive); // info.addAllProperties(buildPropertiesMap(properties)); if (persistIndividualDeletedMessageRanges) { info.addAllIndividualDeletedMessages(buildIndividualDeletedMessageRanges()); } if (log.isDebugEnabled()) { log.debug("[{}][{}] Closing cursor at md-position: {}", ledger.getName(), name, position); } ledger.getStore().asyncUpdateCursorInfo(ledger.getName(), name, info.build(), cursorLedgerStat, new MetaStoreCallback<Void>() { @Override public void operationComplete(Void result, Stat stat) { cursorLedgerStat = stat; callback.operationComplete(result, stat); } @Override public void operationFailed(MetaStoreException e) { callback.operationFailed(e); } }); }
private void persistPositionMetaStore(long cursorsLedgerId, PositionImpl position, MetaStoreCallback<Void> callback) { // When closing we store the last mark-delete position in the z-node itself, so we won't need the cursor ledger, // hence we write it as -1. The cursor ledger is deleted once the z-node write is confirmed. ManagedCursorInfo.Builder info = ManagedCursorInfo.newBuilder() // .setCursorsLedgerId(cursorsLedgerId) // .setMarkDeleteLedgerId(position.getLedgerId()) // .setMarkDeleteEntryId(position.getEntryId()); // if (protobufFormat == ZNodeProtobufFormat.Binary) { info.addAllIndividualDeletedMessages(buildIndividualDeletedMessageRanges()); } if (log.isDebugEnabled()) { log.debug("[{}][{}] Closing cursor at md-position: {}", ledger.getName(), name, markDeletePosition); } ledger.getStore().asyncUpdateCursorInfo(ledger.getName(), name, info.build(), cursorLedgerStat, new MetaStoreCallback<Void>() { @Override public void operationComplete(Void result, Stat stat) { callback.operationComplete(result, stat); } @Override public void operationFailed(MetaStoreException e) { callback.operationFailed(e); } }); }
private void persistPositionMetaStore(long cursorsLedgerId, PositionImpl position, Map<String, Long> properties, MetaStoreCallback<Void> callback, boolean persistIndividualDeletedMessageRanges) { // When closing we store the last mark-delete position in the z-node itself, so we won't need the cursor ledger, // hence we write it as -1. The cursor ledger is deleted once the z-node write is confirmed. ManagedCursorInfo.Builder info = ManagedCursorInfo.newBuilder() // .setCursorsLedgerId(cursorsLedgerId) // .setMarkDeleteLedgerId(position.getLedgerId()) // .setMarkDeleteEntryId(position.getEntryId()) // .setLastActive(lastActive); // info.addAllProperties(buildPropertiesMap(properties)); if (persistIndividualDeletedMessageRanges) { info.addAllIndividualDeletedMessages(buildIndividualDeletedMessageRanges()); } if (log.isDebugEnabled()) { log.debug("[{}][{}] Closing cursor at md-position: {}", ledger.getName(), name, position); } ledger.getStore().asyncUpdateCursorInfo(ledger.getName(), name, info.build(), cursorLedgerStat, new MetaStoreCallback<Void>() { @Override public void operationComplete(Void result, Stat stat) { cursorLedgerStat = stat; callback.operationComplete(result, stat); } @Override public void operationFailed(MetaStoreException e) { callback.operationFailed(e); } }); }