Skip to content

Commit e525d98

Browse files
author
eddy.cao
committed
Add Ut for test lastCheckpointTime
1 parent 63e6466 commit e525d98

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public long getMostRecentCheckpointTxId() {
487487
/**
488488
* @return the time of the most recent checkpoint in millis since the epoch.
489489
*/
490-
long getMostRecentCheckpointTime() {
490+
public long getMostRecentCheckpointTime() {
491491
return mostRecentCheckpointTime;
492492
}
493493

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/StandbyCheckpointer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class StandbyCheckpointer {
6969
private final CheckpointConf checkpointConf;
7070
private final Configuration conf;
7171
private final FSNamesystem namesystem;
72-
private long lastCheckpointTime;
72+
private static long lastCheckpointTime;
7373
private final CheckpointerThread thread;
7474
private final ThreadFactory uploadThreadFactory;
7575
private List<URL> activeNNAddresses;
@@ -375,6 +375,11 @@ static int getCanceledCount() {
375375
return canceledCount;
376376
}
377377

378+
@VisibleForTesting
379+
static long getLastCheckpointTime() {
380+
return lastCheckpointTime;
381+
}
382+
378383
private long countUncheckpointedTxns() {
379384
FSImage img = namesystem.getFSImage();
380385
return img.getCorrectLastAppliedOrWrittenTxId() -

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,50 @@ public void testCheckpointSucceedsWithLegacyOIVException() throws Exception {
649649
HATestUtil.waitForCheckpoint(cluster, 0, ImmutableList.of(12));
650650
}
651651

652+
/**
653+
* Test that lastCheckpointTime is correctly updated at each checkpoint
654+
*/
655+
@Test(timeout = 300000)
656+
public void testLastCheckpointTime() throws Exception {
657+
for (int i = 1; i < NUM_NNS; i++) {
658+
cluster.shutdownNameNode(i);
659+
660+
// Make true checkpoint for DFS_NAMENODE_CHECKPOINT_PERIOD_KEY
661+
cluster.getConfiguration(i).setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_PERIOD_KEY, 3);
662+
cluster.getConfiguration(i).setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_TXNS_KEY, 1000);
663+
}
664+
665+
doEdits(0, 10);
666+
cluster.transitionToStandby(0);
667+
668+
// Standby NNs do checkpoint without active NN available.
669+
for (int i = 1; i < NUM_NNS; i++) {
670+
cluster.restartNameNode(i, false);
671+
}
672+
cluster.waitClusterUp();
673+
674+
cluster.transitionToActive(0);
675+
cluster.transitionToStandby(1);
676+
677+
HATestUtil.waitForCheckpoint(cluster, 1, ImmutableList.of(12));
678+
679+
Thread.sleep(3000);
680+
Long snnCheckpointTime1 = StandbyCheckpointer.getLastCheckpointTime();
681+
long annCheckpointTime1 = nns[0].getFSImage().getStorage().getMostRecentCheckpointTime();
682+
683+
doEdits(11, 20);
684+
nns[0].getRpcServer().rollEditLog();
685+
686+
HATestUtil.waitForCheckpoint(cluster, 1, ImmutableList.of(23));
687+
Thread.sleep(3000);
688+
Long snnCheckpointTime2 = StandbyCheckpointer.getLastCheckpointTime();
689+
long annCheckpointTime2 = nns[0].getFSImage().getStorage().getMostRecentCheckpointTime();
690+
691+
// Make sure the interv
692+
assertTrue(snnCheckpointTime2 - snnCheckpointTime1 >= 3000
693+
&& annCheckpointTime2 - annCheckpointTime1 >= 3000);
694+
}
695+
652696
private void doEdits(int start, int stop) throws IOException {
653697
for (int i = start; i < stop; i++) {
654698
Path p = new Path("/test" + i);

0 commit comments

Comments
 (0)