@@ -1243,14 +1243,15 @@ public boolean hasMoreEntries() {
12431243
12441244 @ Override
12451245 public long getNumberOfEntries () {
1246- if (readPosition .compareTo (ledger .getLastPosition ().getNext ()) > 0 ) {
1246+ Position lastPosition = ledger .getLastPosition ();
1247+ if (readPosition .compareTo (lastPosition .getNext ()) > 0 ) {
12471248 if (log .isDebugEnabled ()) {
12481249 log .debug ("[{}] [{}] Read position {} is ahead of last position {}. There are no entries to read" ,
1249- ledger .getName (), name , readPosition , ledger . getLastPosition () );
1250+ ledger .getName (), name , readPosition , lastPosition );
12501251 }
12511252 return 0 ;
12521253 } else {
1253- return getNumberOfEntries (Range .closedOpen (readPosition , ledger . getLastPosition () .getNext ()));
1254+ return getNumberOfEntries (Range .closedOpen (readPosition , lastPosition .getNext ()));
12541255 }
12551256 }
12561257
@@ -2182,25 +2183,41 @@ public void asyncMarkDelete(final Position position, Map<String, Long> propertie
21822183 }
21832184
21842185 Position newPosition = ackBatchPosition (position );
2185- if (ledger .getLastConfirmedEntry ().compareTo (newPosition ) < 0 ) {
2186+ Position markDeletePos = markDeletePosition ;
2187+ Position lastConfirmedEntry = ledger .getLastConfirmedEntry ();
2188+ if (lastConfirmedEntry .compareTo (newPosition ) < 0 ) {
2189+ // Extract local variables to here for debug reason.
21862190 boolean shouldCursorMoveForward = false ;
2191+ long ledgerEntries = 0 ;
2192+ Long nextValidLedger = null ;
21872193 try {
2188- long ledgerEntries = ledger .getLedgerInfo (markDeletePosition .getLedgerId ()).get ().getEntries ();
2189- Long nextValidLedger = ledger .getNextValidLedger (ledger .getLastConfirmedEntry ().getLedgerId ());
2190- shouldCursorMoveForward = nextValidLedger != null
2191- && (markDeletePosition .getEntryId () + 1 >= ledgerEntries )
2192- && (newPosition .getLedgerId () == nextValidLedger );
2194+ LedgerInfo markDeleteLedgerInfo = ledger .getLedgerInfo (markDeletePos .getLedgerId ()).get ();
2195+ LedgerInfo newPositionLedgerInfo = null ;
2196+ if (markDeleteLedgerInfo == null ) {
2197+ newPositionLedgerInfo = ledger .getLedgerInfo (newPosition .getLedgerId ()).get ();
2198+ shouldCursorMoveForward = newPositionLedgerInfo != null
2199+ && newPosition .getEntryId () + 1 == newPositionLedgerInfo .getEntries ();
2200+ } else {
2201+ ledgerEntries = markDeleteLedgerInfo .getEntries ();
2202+ nextValidLedger = ledger .getNextValidLedger (lastConfirmedEntry .getLedgerId ());
2203+ shouldCursorMoveForward = nextValidLedger != null
2204+ && (markDeletePos .getEntryId () + 1 >= ledgerEntries )
2205+ && (newPosition .getLedgerId () == nextValidLedger );
2206+ }
2207+ if (!shouldCursorMoveForward ) {
2208+ log .info ("test" );
2209+ }
21932210 } catch (Exception e ) {
21942211 log .warn ("Failed to get ledger entries while setting mark-delete-position" , e );
21952212 }
21962213
21972214 if (shouldCursorMoveForward ) {
21982215 log .info ("[{}] move mark-delete-position from {} to {} since all the entries have been consumed" ,
2199- ledger .getName (), markDeletePosition , newPosition );
2216+ ledger .getName (), markDeletePos , newPosition );
22002217 } else {
22012218 if (log .isDebugEnabled ()) {
22022219 log .debug ("[{}] Failed mark delete due to invalid markDelete {} is ahead of last-confirmed-entry {}"
2203- + " for cursor [{}]" , ledger .getName (), position , ledger . getLastConfirmedEntry () , name );
2220+ + " for cursor [{}]" , ledger .getName (), position , lastConfirmedEntry , name );
22042221 }
22052222 callback .markDeleteFailed (new ManagedLedgerException ("Invalid mark deleted position" ), ctx );
22062223 return ;
0 commit comments