@@ -328,34 +328,37 @@ public Void run() throws Exception {
328328
329329 @ VisibleForTesting
330330 public long doTailEdits () throws IOException , InterruptedException {
331+ Collection <EditLogInputStream > streams ;
332+ FSImage image = namesystem .getFSImage ();
333+
334+ long lastTxnId = image .getLastAppliedTxId ();
335+ LOG .debug ("lastTxnId: {}" , lastTxnId );
336+ long startTime = timer .monotonicNow ();
337+ try {
338+ streams = editLog .selectInputStreams (lastTxnId + 1 , 0 ,
339+ null , inProgressOk , true );
340+ } catch (IOException ioe ) {
341+ // This is acceptable. If we try to tail edits in the middle of an edits
342+ // log roll, i.e. the last one has been finalized but the new inprogress
343+ // edits file hasn't been started yet.
344+ LOG .warn ("Edits tailer failed to find any streams. Will try again " +
345+ "later." , ioe );
346+ return 0 ;
347+ } finally {
348+ NameNode .getNameNodeMetrics ().addEditLogFetchTime (
349+ timer .monotonicNow () - startTime );
350+ }
331351 // Write lock needs to be interruptible here because the
332352 // transitionToActive RPC takes the write lock before calling
333353 // tailer.stop() -- so if we're not interruptible, it will
334354 // deadlock.
335355 namesystem .writeLockInterruptibly ();
336356 try {
337- FSImage image = namesystem .getFSImage ();
338-
339- long lastTxnId = image .getLastAppliedTxId ();
340-
341- if (LOG .isDebugEnabled ()) {
342- LOG .debug ("lastTxnId: " + lastTxnId );
343- }
344- Collection <EditLogInputStream > streams ;
345- long startTime = timer .monotonicNow ();
346- try {
347- streams = editLog .selectInputStreams (lastTxnId + 1 , 0 ,
348- null , inProgressOk , true );
349- } catch (IOException ioe ) {
350- // This is acceptable. If we try to tail edits in the middle of an edits
351- // log roll, i.e. the last one has been finalized but the new inprogress
352- // edits file hasn't been started yet.
353- LOG .warn ("Edits tailer failed to find any streams. Will try again " +
354- "later." , ioe );
357+ long currentLastTxnId = image .getLastAppliedTxId ();
358+ if (lastTxnId != currentLastTxnId ) {
359+ LOG .warn ("The currentLastTxnId({}) is different from preLastTxtId({})" ,
360+ currentLastTxnId , lastTxnId );
355361 return 0 ;
356- } finally {
357- NameNode .getNameNodeMetrics ().addEditLogFetchTime (
358- timer .monotonicNow () - startTime );
359362 }
360363 if (LOG .isDebugEnabled ()) {
361364 LOG .debug ("edit streams to load from: " + streams .size ());
0 commit comments