private ManagedCursorInfo parseManagedCursorInfo(byte[] data) throws ParseException, InvalidProtocolBufferException { // First try binary format, then fallback to text try { return ManagedCursorInfo.parseFrom(data); } catch (InvalidProtocolBufferException e) { // Fallback to parsing protobuf text format ManagedCursorInfo.Builder builder = ManagedCursorInfo.newBuilder(); TextFormat.merge(new String(data, Encoding), builder); return builder.build(); } }
@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 Object answer(InvocationOnMock invocation) { ManagedCursorInfo info = ManagedCursorInfo.newBuilder().setCursorsLedgerId(cursorsLedgerId) .setMarkDeleteLedgerId(markDeleteLedgerId).setMarkDeleteEntryId(markDeleteEntryId) .setLastActive(0L).build(); Stat stat = mock(Stat.class); MetaStoreCallback<ManagedCursorInfo> callback = (MetaStoreCallback<ManagedCursorInfo>) invocation .getArguments()[2]; callback.operationComplete(info, stat); return null; } }).when(mockMetaStore).asyncGetCursorInfo(eq(mlName), eq(cursorName), any(MetaStoreCallback.class));
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 ManagedCursorInfo parseManagedCursorInfoFromBinary(byte[] data) throws InvalidProtocolBufferException { return ManagedCursorInfo.newBuilder().mergeFrom(data).build(); }
private ManagedCursorInfo parseManagedCursorInfo(byte[] data) throws ParseException, InvalidProtocolBufferException { // First try binary format, then fallback to text try { return ManagedCursorInfo.parseFrom(data); } catch (InvalidProtocolBufferException e) { // Fallback to parsing protobuf text format ManagedCursorInfo.Builder builder = ManagedCursorInfo.newBuilder(); TextFormat.merge(new String(data, Encoding), builder); return builder.build(); } }
private ManagedCursorInfo parseManagedCursorInfoFromText(byte[] data) throws ParseException { ManagedCursorInfo.Builder builder = ManagedCursorInfo.newBuilder(); TextFormat.merge(new String(data, Encoding), builder); return builder.build(); }
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); } }); }
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"); } }); } });