long ledgerId = info.getCursorsLedgerId(); bookkeeper.asyncOpenLedger(ledgerId, digestType, config.getPassword(), (rc, lh, ctx) -> { if (log.isDebugEnabled()) {
hash = (19 * hash) + getDescriptor().hashCode(); if (hasCursorsLedgerId()) { hash = (37 * hash) + CURSORSLEDGERID_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getCursorsLedgerId()); if (hasMarkDeleteLedgerId()) { hash = (37 * hash) + MARKDELETELEDGERID_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getMarkDeleteLedgerId()); if (hasMarkDeleteEntryId()) { hash = (37 * hash) + MARKDELETEENTRYID_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getMarkDeleteEntryId()); if (getIndividualDeletedMessagesCount() > 0) { hash = (37 * hash) + INDIVIDUALDELETEDMESSAGES_FIELD_NUMBER; hash = (53 * hash) + getIndividualDeletedMessagesList().hashCode(); if (getPropertiesCount() > 0) { hash = (37 * hash) + PROPERTIES_FIELD_NUMBER; hash = (53 * hash) + getPropertiesList().hashCode(); if (hasLastActive()) { hash = (37 * hash) + LASTACTIVE_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getLastActive());
@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(); }
long ledgerId = info.getCursorsLedgerId(); bookkeeper.asyncOpenLedger(ledgerId, digestType, config.getPassword(), (rc, lh, ctx) -> { if (log.isDebugEnabled()) {
public Builder mergeFrom(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo other) { if (other == org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo.getDefaultInstance()) return this; if (other.hasCursorsLedgerId()) { setCursorsLedgerId(other.getCursorsLedgerId()); if (other.hasMarkDeleteLedgerId()) { setMarkDeleteLedgerId(other.getMarkDeleteLedgerId()); if (other.hasMarkDeleteEntryId()) { setMarkDeleteEntryId(other.getMarkDeleteEntryId()); if (other.hasLastActive()) { setLastActive(other.getLastActive());
long ledgerId = info.getCursorsLedgerId(); bookkeeper.asyncOpenLedger(ledgerId, config.getDigestType(), config.getPassword(), (rc, lh, ctx) -> { if (log.isDebugEnabled()) {
public org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo buildPartial() { org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo result = new org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0;
public Builder mergeFrom(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo other) { if (other == org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo.getDefaultInstance()) return this; if (other.hasCursorsLedgerId()) { setCursorsLedgerId(other.getCursorsLedgerId()); if (other.hasMarkDeleteLedgerId()) { setMarkDeleteLedgerId(other.getMarkDeleteLedgerId()); if (other.hasMarkDeleteEntryId()) { setMarkDeleteEntryId(other.getMarkDeleteEntryId()); this.mergeUnknownFields(other.getUnknownFields()); return this;
Stat stat, final MetaStoreCallback<Void> callback) { log.info("[{}] [{}] Updating cursor info ledgerId={} mark-delete={}:{}", ledgerName, cursorName, info.getCursorsLedgerId(), info.getMarkDeleteLedgerId(), info.getMarkDeleteEntryId()); byte[] content = info.toByteArray(); // Binary format
Stat stat, final MetaStoreCallback<Void> callback) { log.info("[{}] [{}] Updating cursor info ledgerId={} mark-delete={}:{}", ledgerName, cursorName, info.getCursorsLedgerId(), info.getMarkDeleteLedgerId(), info.getMarkDeleteEntryId()); info.toString().getBytes(Encoding) : // Text format info.toByteArray(); // Binary format
result = result && (hasCursorsLedgerId() == other.hasCursorsLedgerId()); if (hasCursorsLedgerId()) { result = result && (getCursorsLedgerId() == other.getCursorsLedgerId()); result = result && (hasMarkDeleteLedgerId() == other.hasMarkDeleteLedgerId()); if (hasMarkDeleteLedgerId()) { result = result && (getMarkDeleteLedgerId() == other.getMarkDeleteLedgerId()); result = result && (hasMarkDeleteEntryId() == other.hasMarkDeleteEntryId()); if (hasMarkDeleteEntryId()) { result = result && (getMarkDeleteEntryId() == other.getMarkDeleteEntryId()); result = result && getIndividualDeletedMessagesList() .equals(other.getIndividualDeletedMessagesList()); result = result && getPropertiesList() .equals(other.getPropertiesList()); result = result && (hasLastActive() == other.hasLastActive()); if (hasLastActive()) { result = result && (getLastActive() == other.getLastActive());
hash = (19 * hash) + getDescriptor().hashCode(); if (hasCursorsLedgerId()) { hash = (37 * hash) + CURSORSLEDGERID_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getCursorsLedgerId()); if (hasMarkDeleteLedgerId()) { hash = (37 * hash) + MARKDELETELEDGERID_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getMarkDeleteLedgerId()); if (hasMarkDeleteEntryId()) { hash = (37 * hash) + MARKDELETEENTRYID_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getMarkDeleteEntryId()); if (getIndividualDeletedMessagesCount() > 0) { hash = (37 * hash) + INDIVIDUALDELETEDMESSAGES_FIELD_NUMBER; hash = (53 * hash) + getIndividualDeletedMessagesList().hashCode(); if (getPropertiesCount() > 0) { hash = (37 * hash) + PROPERTIES_FIELD_NUMBER; hash = (53 * hash) + getPropertiesList().hashCode(); if (hasLastActive()) { hash = (37 * hash) + LASTACTIVE_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getLastActive());
public org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo buildPartial() { org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo result = new org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } result.cursorsLedgerId_ = cursorsLedgerId_; if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000002; } result.markDeleteLedgerId_ = markDeleteLedgerId_; if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } result.markDeleteEntryId_ = markDeleteEntryId_; if (individualDeletedMessagesBuilder_ == null) { if (((bitField0_ & 0x00000008) == 0x00000008)) { individualDeletedMessages_ = java.util.Collections.unmodifiableList(individualDeletedMessages_); bitField0_ = (bitField0_ & ~0x00000008); } result.individualDeletedMessages_ = individualDeletedMessages_; } else { result.individualDeletedMessages_ = individualDeletedMessagesBuilder_.build(); } result.bitField0_ = to_bitField0_; onBuilt(); return result; }
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); } }); }
@Override public void operationComplete(ManagedCursorInfo info, Stat stat) { cursorLedgerStat = stat; lastActive = info.getLastActive() != 0 ? info.getLastActive() : lastActive; if (info.getCursorsLedgerId() == -1L) { // There is no cursor ledger to read the last position from. It means the cursor has been properly // closed and the last mark-delete position is stored in the ManagedCursorInfo itself.s PositionImpl recoveredPosition = new PositionImpl(info.getMarkDeleteLedgerId(), info.getMarkDeleteEntryId()); if (info.getIndividualDeletedMessagesCount() > 0) { recoverIndividualDeletedMessages(info.getIndividualDeletedMessagesList()); } Map<String, Long> recoveredProperties = Collections.emptyMap(); if (info.getPropertiesCount() > 0) { // Recover properties map recoveredProperties = Maps.newHashMap(); for (int i = 0; i < info.getPropertiesCount(); i++) { LongProperty property = info.getProperties(i); recoveredProperties.put(property.getName(), property.getValue()); } } recoveredCursor(recoveredPosition, recoveredProperties, null); callback.operationComplete(); } else { // Need to proceed and read the last entry in the specified ledger to find out the last position log.info("[{}] Consumer {} meta-data recover from ledger {}", ledger.getName(), name, info.getCursorsLedgerId()); recoverFromLedger(info, callback); } }
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); } }); }
public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; if (isInitialized == 0) return false; if (!hasCursorsLedgerId()) { memoizedIsInitialized = 0; return false; } for (int i = 0; i < getIndividualDeletedMessagesCount(); i++) { if (!getIndividualDeletedMessages(i).isInitialized()) { memoizedIsInitialized = 0; return false; } } for (int i = 0; i < getPropertiesCount(); i++) { if (!getProperties(i).isInitialized()) { memoizedIsInitialized = 0; return false; } } memoizedIsInitialized = 1; return true; }
/** * If we fail to recover the cursor ledger, we want to still open the ML and rollback * * @param info */ private PositionImpl getRollbackPosition(ManagedCursorInfo info) { PositionImpl firstPosition = ledger.getFirstPosition(); PositionImpl snapshottedPosition = new PositionImpl(info.getMarkDeleteLedgerId(), info.getMarkDeleteEntryId()); if (firstPosition == null) { // There are no ledgers in the ML, any position is good return snapshottedPosition; } else if (snapshottedPosition.compareTo(firstPosition) < 0) { // The snapshotted position might be pointing to a ledger that was already deleted return firstPosition; } else { return snapshottedPosition; } }
@Override public void operationComplete(ManagedCursorInfo info, Stat stat) { cursorLedgerStat = stat; if (info.getCursorsLedgerId() == -1L) { // There is no cursor ledger to read the last position from. It means the cursor has been properly // closed and the last mark-delete position is stored in the ManagedCursorInfo itself.s PositionImpl recoveredPosition = new PositionImpl(info.getMarkDeleteLedgerId(), info.getMarkDeleteEntryId()); if (info.getIndividualDeletedMessagesCount() > 0) { recoverIndividualDeletedMessages(info.getIndividualDeletedMessagesList()); } recoveredCursor(recoveredPosition); callback.operationComplete(); } else { // Need to proceed and read the last entry in the specified ledger to find out the last position log.info("[{}] Consumer {} meta-data recover from ledger {}", ledger.getName(), name, info.getCursorsLedgerId()); recoverFromLedger(info, callback); } }
/** * If we fail to recover the cursor ledger, we want to still open the ML and rollback. * * @param info */ private PositionImpl getRollbackPosition(ManagedCursorInfo info) { PositionImpl firstPosition = ledger.getFirstPosition(); PositionImpl snapshottedPosition = new PositionImpl(info.getMarkDeleteLedgerId(), info.getMarkDeleteEntryId()); if (firstPosition == null) { // There are no ledgers in the ML, any position is good return snapshottedPosition; } else if (snapshottedPosition.compareTo(firstPosition) < 0) { // The snapshotted position might be pointing to a ledger that was already deleted return firstPosition; } else { return snapshottedPosition; } }