|
void recover(final VoidCallback callback) { |
|
// Read the meta-data ledgerId from the store |
|
log.info("[{}] Recovering from bookkeeper ledger cursor: {}", ledger.getName(), name); |
|
ledger.getStore().asyncGetCursorInfo(ledger.getName(), name, new MetaStoreCallback<ManagedCursorInfo>() { |
|
@Override |
|
public void operationComplete(ManagedCursorInfo info, Stat stat) { |
|
|
|
updateCursorLedgerStat(info, stat); |
|
lastActive = info.getLastActive() != 0 ? info.getLastActive() : lastActive; |
|
|
|
if (log.isDebugEnabled()) { |
|
log.debug("[{}] [{}] Recover cursor last active to [{}]", ledger.getName(), name, lastActive); |
|
} |
|
|
|
Map<String, String> recoveredCursorProperties = Collections.emptyMap(); |
|
if (info.getCursorPropertiesCount() > 0) { |
|
// Recover properties map |
|
recoveredCursorProperties = new HashMap<>(); |
|
for (int i = 0; i < info.getCursorPropertiesCount(); i++) { |
|
StringProperty property = info.getCursorProperties(i); |
|
recoveredCursorProperties.put(property.getName(), property.getValue()); |
|
} |
|
} |
|
cursorProperties = recoveredCursorProperties; |
|
|
|
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. |
|
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 = new HashMap<>(); |
|
for (int i = 0; i < info.getPropertiesCount(); i++) { |
|
LongProperty property = info.getProperties(i); |
|
recoveredProperties.put(property.getName(), property.getValue()); |
|
} |
|
} |
|
|
|
recoveredCursor(recoveredPosition, recoveredProperties, recoveredCursorProperties, null); |
|
callback.operationComplete(); |