Skip to content

Commit d585b7b

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

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

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()
657+
throws Exception {
658+
for (int i = 1; i < NUM_NNS; i++) {
659+
cluster.shutdownNameNode(i);
660+
661+
// Make true checkpoint for DFS_NAMENODE_CHECKPOINT_PERIOD_KEY
662+
cluster.getConfiguration(i).setInt(
663+
DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_PERIOD_KEY, 3);
664+
cluster.getConfiguration(i).setInt(
665+
DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_TXNS_KEY, 1000);
666+
}
667+
668+
doEdits(0, 10);
669+
cluster.transitionToStandby(0);
670+
671+
// Standby NNs do checkpoint without active NN available.
672+
for (int i = 1; i < NUM_NNS; i++) {
673+
cluster.restartNameNode(i, false);
674+
}
675+
cluster.waitClusterUp();
676+
677+
cluster.transitionToActive(0);
678+
cluster.transitionToStandby(1);
679+
680+
HATestUtil.waitForCheckpoint(cluster, 1, ImmutableList.of(12));
681+
Thread.sleep(3000);
682+
683+
// Wait for 2 seconds to expire last upload time.
684+
Long lastCheckpointTime1 = StandbyCheckpointer.getLastCheckpointTime();
685+
686+
doEdits(11, 20);
687+
nns[0].getRpcServer().rollEditLog();
688+
689+
HATestUtil.waitForCheckpoint(cluster, 1, ImmutableList.of(23));
690+
Thread.sleep(3000);
691+
Long lastCheckpointTime2 = StandbyCheckpointer.getLastCheckpointTime();
692+
// Make sure the interv
693+
assertTrue(lastCheckpointTime2 - lastCheckpointTime1 > 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)