Java Code Examples for org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter#enterSafeMode()

The following examples show how to use org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter#enterSafeMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestOpenFilesWithSnapshot.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testOpenFilesWithRename() throws Exception {
  Path path = new Path("/test");
  doWriteAndAbort(fs, path);

  // check for zero sized blocks
  Path fileWithEmptyBlock = new Path("/test/test/test4");
  fs.create(fileWithEmptyBlock);
  NamenodeProtocols nameNodeRpc = cluster.getNameNodeRpc();
  String clientName = fs.getClient().getClientName();
  // create one empty block
  nameNodeRpc.addBlock(fileWithEmptyBlock.toString(), clientName, null, null,
      INodeId.GRANDFATHER_INODE_ID, null);
  fs.createSnapshot(path, "s2");

  fs.rename(new Path("/test/test"), new Path("/test/test-renamed"));
  fs.delete(new Path("/test/test-renamed"), true);
  NameNode nameNode = cluster.getNameNode();
  NameNodeAdapter.enterSafeMode(nameNode, false);
  NameNodeAdapter.saveNamespace(nameNode);
  NameNodeAdapter.leaveSafeMode(nameNode);
  cluster.restartNameNode(true);
}
 
Example 2
Source File: TestOpenFilesWithSnapshot.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testOpenFilesWithRename() throws Exception {
  Path path = new Path("/test");
  doWriteAndAbort(fs, path);

  // check for zero sized blocks
  Path fileWithEmptyBlock = new Path("/test/test/test4");
  fs.create(fileWithEmptyBlock);
  NamenodeProtocols nameNodeRpc = cluster.getNameNodeRpc();
  String clientName = fs.getClient().getClientName();
  // create one empty block
  nameNodeRpc.addBlock(fileWithEmptyBlock.toString(), clientName, null, null,
      INodeId.GRANDFATHER_INODE_ID, null);
  fs.createSnapshot(path, "s2");

  fs.rename(new Path("/test/test"), new Path("/test/test-renamed"));
  fs.delete(new Path("/test/test-renamed"), true);
  NameNode nameNode = cluster.getNameNode();
  NameNodeAdapter.enterSafeMode(nameNode, false);
  NameNodeAdapter.saveNamespace(nameNode);
  NameNodeAdapter.leaveSafeMode(nameNode);
  cluster.restartNameNode(true);
}
 
Example 3
Source File: TestSnapshotBlocksMap.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testReadSnapshotFileWithCheckpoint() throws Exception {
  Path foo = new Path("/foo");
  hdfs.mkdirs(foo);
  hdfs.allowSnapshot(foo);
  Path bar = new Path("/foo/bar");
  DFSTestUtil.createFile(hdfs, bar, 100, (short) 2, 100024L);
  hdfs.createSnapshot(foo, "s1");
  assertTrue(hdfs.delete(bar, true));

  // checkpoint
  NameNode nameNode = cluster.getNameNode();
  NameNodeAdapter.enterSafeMode(nameNode, false);
  NameNodeAdapter.saveNamespace(nameNode);
  NameNodeAdapter.leaveSafeMode(nameNode);

  // restart namenode to load snapshot files from fsimage
  cluster.restartNameNode(true);
  String snapshotPath = Snapshot.getSnapshotPath(foo.toString(), "s1/bar");
  DFSTestUtil.readFile(hdfs, new Path(snapshotPath));
}
 
Example 4
Source File: TestHASafeMode.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Regression test for a bug experienced while developing
 * HDFS-2742. The scenario here is:
 * - image contains some blocks
 * - edits log contains at least one block addition, followed
 *   by deletion of more blocks than were added.
 * - When node starts up, some incorrect accounting of block
 *   totals caused an assertion failure.
 */
@Test
public void testBlocksDeletedInEditLog() throws Exception {
  banner("Starting with NN0 active and NN1 standby, creating some blocks");
  // Make 4 blocks persisted in the image.
  DFSTestUtil.createFile(fs, new Path("/test"),
      4*BLOCK_SIZE, (short) 3, 1L);
  NameNodeAdapter.enterSafeMode(nn0, false);
  NameNodeAdapter.saveNamespace(nn0);
  NameNodeAdapter.leaveSafeMode(nn0);
  
  // OP_ADD for 2 blocks
  DFSTestUtil.createFile(fs, new Path("/test2"),
      2*BLOCK_SIZE, (short) 3, 1L);
  
  // OP_DELETE for 4 blocks
  fs.delete(new Path("/test"), true);

  restartActive();
}
 
Example 5
Source File: TestSnapshotBlocksMap.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testReadSnapshotFileWithCheckpoint() throws Exception {
  Path foo = new Path("/foo");
  hdfs.mkdirs(foo);
  hdfs.allowSnapshot(foo);
  Path bar = new Path("/foo/bar");
  DFSTestUtil.createFile(hdfs, bar, 100, (short) 2, 100024L);
  hdfs.createSnapshot(foo, "s1");
  assertTrue(hdfs.delete(bar, true));

  // checkpoint
  NameNode nameNode = cluster.getNameNode();
  NameNodeAdapter.enterSafeMode(nameNode, false);
  NameNodeAdapter.saveNamespace(nameNode);
  NameNodeAdapter.leaveSafeMode(nameNode);

  // restart namenode to load snapshot files from fsimage
  cluster.restartNameNode(true);
  String snapshotPath = Snapshot.getSnapshotPath(foo.toString(), "s1/bar");
  DFSTestUtil.readFile(hdfs, new Path(snapshotPath));
}
 
Example 6
Source File: TestXAttrConfigFlag.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Restart the cluster, optionally saving a new checkpoint.
 *
 * @param checkpoint boolean true to save a new checkpoint
 * @param xattrsEnabled if true, XAttr support is enabled
 * @throws Exception if restart fails
 */
private void restart(boolean checkpoint, boolean xattrsEnabled)
    throws Exception {
  NameNode nameNode = cluster.getNameNode();
  if (checkpoint) {
    NameNodeAdapter.enterSafeMode(nameNode, false);
    NameNodeAdapter.saveNamespace(nameNode);
  }
  shutdown();
  initCluster(false, xattrsEnabled);
}
 
Example 7
Source File: TestBootstrapStandby.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Test for downloading a checkpoint made at a later checkpoint
 * from the active.
 */
@Test
public void testDownloadingLaterCheckpoint() throws Exception {
  // Roll edit logs a few times to inflate txid
  nn0.getRpcServer().rollEditLog();
  nn0.getRpcServer().rollEditLog();
  // Make checkpoint
  NameNodeAdapter.enterSafeMode(nn0, false);
  NameNodeAdapter.saveNamespace(nn0);
  NameNodeAdapter.leaveSafeMode(nn0);
  long expectedCheckpointTxId = NameNodeAdapter.getNamesystem(nn0)
    .getFSImage().getMostRecentCheckpointTxId();
  assertEquals(6, expectedCheckpointTxId);

  int rc = BootstrapStandby.run(
      new String[]{"-force"},
      cluster.getConfiguration(1));
  assertEquals(0, rc);
  
  // Should have copied over the namespace from the active
  FSImageTestUtil.assertNNHasCheckpoints(cluster, 1,
      ImmutableList.of((int)expectedCheckpointTxId));
  FSImageTestUtil.assertNNFilesMatch(cluster);

  // We should now be able to start the standby successfully.
  cluster.restartNameNode(1);
}
 
Example 8
Source File: TestDFSHAAdminMiniCluster.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testTryFailoverToSafeMode() throws Exception {
  conf.set(DFSConfigKeys.DFS_HA_FENCE_METHODS_KEY, 
           TestDFSHAAdmin.getFencerTrueCommand());
  tool.setConf(conf);

  NameNodeAdapter.enterSafeMode(cluster.getNameNode(0), false);
  assertEquals(-1, runTool("-failover", "nn2", "nn1"));
  assertTrue("Bad output: " + errOutput,
      errOutput.contains("is not ready to become active: " +
          "The NameNode is in safemode"));
}
 
Example 9
Source File: TestDFSHAAdminMiniCluster.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testTryFailoverToSafeMode() throws Exception {
  conf.set(DFSConfigKeys.DFS_HA_FENCE_METHODS_KEY, 
           TestDFSHAAdmin.getFencerTrueCommand());
  tool.setConf(conf);

  NameNodeAdapter.enterSafeMode(cluster.getNameNode(0), false);
  assertEquals(-1, runTool("-failover", "nn2", "nn1"));
  assertTrue("Bad output: " + errOutput,
      errOutput.contains("is not ready to become active: " +
          "The NameNode is in safemode"));
}
 
Example 10
Source File: TestAclConfigFlag.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Restart the cluster, optionally saving a new checkpoint.
 *
 * @param checkpoint boolean true to save a new checkpoint
 * @param aclsEnabled if true, ACL support is enabled
 * @throws Exception if restart fails
 */
private void restart(boolean checkpoint, boolean aclsEnabled)
    throws Exception {
  NameNode nameNode = cluster.getNameNode();
  if (checkpoint) {
    NameNodeAdapter.enterSafeMode(nameNode, false);
    NameNodeAdapter.saveNamespace(nameNode);
  }
  shutdown();
  initCluster(false, aclsEnabled);
}
 
Example 11
Source File: TestSnapshotDeletion.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Delete a snapshot that is taken before a directory deletion (recursively),
 * directory diff list should be combined correctly.
 */
@Test (timeout=60000)
public void testDeleteSnapshot2() throws Exception {
  final Path root = new Path("/");

  Path dir = new Path("/dir1");
  Path file1 = new Path(dir, "file1");
  DFSTestUtil.createFile(hdfs, file1, BLOCKSIZE, REPLICATION, seed);

  hdfs.allowSnapshot(root);
  hdfs.createSnapshot(root, "s1");

  Path file2 = new Path(dir, "file2");
  DFSTestUtil.createFile(hdfs, file2, BLOCKSIZE, REPLICATION, seed);
  INodeFile file2Node = fsdir.getINode(file2.toString()).asFile();
  long file2NodeId = file2Node.getId();

  hdfs.createSnapshot(root, "s2");

  // delete directory recursively
  assertTrue(hdfs.delete(dir, true));
  assertNotNull(fsdir.getInode(file2NodeId));

  // delete second snapshot
  hdfs.deleteSnapshot(root, "s2");
  assertTrue(fsdir.getInode(file2NodeId) == null);

  NameNodeAdapter.enterSafeMode(cluster.getNameNode(), false);
  NameNodeAdapter.saveNamespace(cluster.getNameNode());

  // restart NN
  cluster.restartNameNodes();
}
 
Example 12
Source File: TestSnapshotBlocksMap.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30000)
public void testReadRenamedSnapshotFileWithCheckpoint() throws Exception {
  final Path foo = new Path("/foo");
  final Path foo2 = new Path("/foo2");
  hdfs.mkdirs(foo);
  hdfs.mkdirs(foo2);

  hdfs.allowSnapshot(foo);
  hdfs.allowSnapshot(foo2);
  final Path bar = new Path(foo, "bar");
  final Path bar2 = new Path(foo2, "bar");
  DFSTestUtil.createFile(hdfs, bar, 100, (short) 2, 100024L);
  hdfs.createSnapshot(foo, "s1");
  // rename to another snapshottable directory and take snapshot
  assertTrue(hdfs.rename(bar, bar2));
  hdfs.createSnapshot(foo2, "s2");
  // delete the original renamed file to make sure blocks are not updated by
  // the original file
  assertTrue(hdfs.delete(bar2, true));

  // checkpoint
  NameNode nameNode = cluster.getNameNode();
  NameNodeAdapter.enterSafeMode(nameNode, false);
  NameNodeAdapter.saveNamespace(nameNode);
  NameNodeAdapter.leaveSafeMode(nameNode);
  // restart namenode to load snapshot files from fsimage
  cluster.restartNameNode(true);
  // file in first snapshot
  String barSnapshotPath = Snapshot.getSnapshotPath(foo.toString(), "s1/bar");
  DFSTestUtil.readFile(hdfs, new Path(barSnapshotPath));
  // file in second snapshot after rename+delete
  String bar2SnapshotPath = Snapshot.getSnapshotPath(foo2.toString(),
      "s2/bar");
  DFSTestUtil.readFile(hdfs, new Path(bar2SnapshotPath));
}
 
Example 13
Source File: TestXAttrWithSnapshot.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Restart the cluster, optionally saving a new checkpoint.
 * 
 * @param checkpoint boolean true to save a new checkpoint
 * @throws Exception if restart fails
 */
private static void restart(boolean checkpoint) throws Exception {
  NameNode nameNode = cluster.getNameNode();
  if (checkpoint) {
    NameNodeAdapter.enterSafeMode(nameNode, false);
    NameNodeAdapter.saveNamespace(nameNode);
  }
  shutdown();
  initCluster(false);
}
 
Example 14
Source File: TestHASafeMode.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for enter safemode in standby namenode, when it is already in startup safemode.
 * It is a regression test for HDFS-2747.
 */
@Test
public void testEnterSafeModeInSBNShouldNotThrowNPE() throws Exception {
  banner("Starting with NN0 active and NN1 standby, creating some blocks");
  DFSTestUtil
      .createFile(fs, new Path("/test"), 3 * BLOCK_SIZE, (short) 3, 1L);
  // Roll edit log so that, when the SBN restarts, it will load
  // the namespace during startup and enter safemode.
  nn0.getRpcServer().rollEditLog();
  banner("Creating some blocks that won't be in the edit log");
  DFSTestUtil.createFile(fs, new Path("/test2"), 5 * BLOCK_SIZE, (short) 3,
      1L);
  banner("Deleting the original blocks");
  fs.delete(new Path("/test"), true);
  banner("Restarting standby");
  restartStandby();
  FSNamesystem namesystem = nn1.getNamesystem();
  String status = namesystem.getSafemode();
  assertTrue("Bad safemode status: '" + status + "'", status
      .startsWith("Safe mode is ON."));
  NameNodeAdapter.enterSafeMode(nn1, false);
  assertTrue("Failed to enter into safemode in standby", namesystem
      .isInSafeMode());
  NameNodeAdapter.enterSafeMode(nn1, false);
  assertTrue("Failed to enter into safemode in standby", namesystem
      .isInSafeMode());
}
 
Example 15
Source File: TestDFSHAAdminMiniCluster.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetServiceState() throws Exception {
  assertEquals(0, runTool("-getServiceState", "nn1"));
  assertEquals(0, runTool("-getServiceState", "nn2"));
  
  cluster.transitionToActive(0);
  assertEquals(0, runTool("-getServiceState", "nn1"));
  
  NameNodeAdapter.enterSafeMode(cluster.getNameNode(0), false);
  assertEquals(0, runTool("-getServiceState", "nn1"));
}
 
Example 16
Source File: TestDelegationToken.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Test that the delegation token secret manager only runs when the
 * NN is out of safe mode. This is because the secret manager
 * has to log to the edit log, which should not be written in
 * safe mode. Regression test for HDFS-2579.
 */
@Test
public void testDTManagerInSafeMode() throws Exception {
  cluster.startDataNodes(config, 1, true, StartupOption.REGULAR, null);
  FileSystem fs = cluster.getFileSystem();
  for (int i = 0; i < 5; i++) {
    DFSTestUtil.createFile(fs, new Path("/test-" + i), 100, (short)1, 1L);
  }
  cluster.getConfiguration(0).setInt(
      DFSConfigKeys.DFS_NAMENODE_DELEGATION_KEY_UPDATE_INTERVAL_KEY, 500); 
  cluster.getConfiguration(0).setInt(
      DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, 30000);
  cluster.setWaitSafeMode(false);
  cluster.restartNameNode();
  NameNode nn = cluster.getNameNode();
  assertTrue(nn.isInSafeMode());
  DelegationTokenSecretManager sm =
    NameNodeAdapter.getDtSecretManager(nn.getNamesystem());
  assertFalse("Secret manager should not run in safe mode", sm.isRunning());
  
  NameNodeAdapter.leaveSafeMode(nn);
  assertTrue("Secret manager should start when safe mode is exited",
      sm.isRunning());
  
  LOG.info("========= entering safemode again");
  
  NameNodeAdapter.enterSafeMode(nn, false);
  assertFalse("Secret manager should stop again when safe mode " +
      "is manually entered", sm.isRunning());
  
  // Set the cluster to leave safemode quickly on its own.
  cluster.getConfiguration(0).setInt(
      DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, 0);
  cluster.setWaitSafeMode(true);
  cluster.restartNameNode();
  nn = cluster.getNameNode();
  sm = NameNodeAdapter.getDtSecretManager(nn.getNamesystem());

  assertFalse(nn.isInSafeMode());
  assertTrue(sm.isRunning());
}
 
Example 17
Source File: TestFileCreation.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * 1. Check the blocks of old file are cleaned after creating with overwrite
 * 2. Restart NN, check the file
 * 3. Save new checkpoint and restart NN, check the file
 */
@Test(timeout = 120000)
public void testFileCreationWithOverwrite() throws Exception {
  Configuration conf = new Configuration();
  conf.setInt("dfs.blocksize", blockSize);
  MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).
      numDataNodes(3).build();
  DistributedFileSystem dfs = cluster.getFileSystem();
  try {
    dfs.mkdirs(new Path("/foo/dir"));
    String file = "/foo/dir/file";
    Path filePath = new Path(file);
    
    // Case 1: Create file with overwrite, check the blocks of old file
    // are cleaned after creating with overwrite
    NameNode nn = cluster.getNameNode();
    FSNamesystem fsn = NameNodeAdapter.getNamesystem(nn);
    BlockManager bm = fsn.getBlockManager();
    
    FSDataOutputStream out = dfs.create(filePath);
    byte[] oldData = AppendTestUtil.randomBytes(seed, fileSize);
    try {
      out.write(oldData);
    } finally {
      out.close();
    }
    
    LocatedBlocks oldBlocks = NameNodeAdapter.getBlockLocations(
        nn, file, 0, fileSize);
    assertBlocks(bm, oldBlocks, true);
    
    out = dfs.create(filePath, true);
    byte[] newData = AppendTestUtil.randomBytes(seed, fileSize);
    try {
      out.write(newData);
    } finally {
      out.close();
    }
    dfs.deleteOnExit(filePath);
    
    LocatedBlocks newBlocks = NameNodeAdapter.getBlockLocations(
        nn, file, 0, fileSize);
    assertBlocks(bm, newBlocks, true);
    assertBlocks(bm, oldBlocks, false);
    
    FSDataInputStream in = dfs.open(filePath);
    byte[] result = null;
    try {
      result = readAll(in);
    } finally {
      in.close();
    }
    Assert.assertArrayEquals(newData, result);
    
    // Case 2: Restart NN, check the file
    cluster.restartNameNode();
    nn = cluster.getNameNode();
    in = dfs.open(filePath);
    try {
      result = readAll(in);
    } finally {
      in.close();
    }
    Assert.assertArrayEquals(newData, result);
    
    // Case 3: Save new checkpoint and restart NN, check the file
    NameNodeAdapter.enterSafeMode(nn, false);
    NameNodeAdapter.saveNamespace(nn);
    cluster.restartNameNode();
    nn = cluster.getNameNode();
    
    in = dfs.open(filePath);
    try {
      result = readAll(in);
    } finally {
      in.close();
    }
    Assert.assertArrayEquals(newData, result);
  } finally {
    if (dfs != null) {
      dfs.close();
    }
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
Example 18
Source File: TestHASafeMode.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Make sure the client retries when the active NN is in safemode
 */
@Test (timeout=300000)
public void testClientRetrySafeMode() throws Exception {
  final Map<Path, Boolean> results = Collections
      .synchronizedMap(new HashMap<Path, Boolean>());
  final Path test = new Path("/test");
  // let nn0 enter safemode
  NameNodeAdapter.enterSafeMode(nn0, false);
  SafeModeInfo safeMode = (SafeModeInfo) Whitebox.getInternalState(
      nn0.getNamesystem(), "safeMode");
  Whitebox.setInternalState(safeMode, "extension", Integer.valueOf(30000));
  LOG.info("enter safemode");
  new Thread() {
    @Override
    public void run() {
      try {
        boolean mkdir = fs.mkdirs(test);
        LOG.info("mkdir finished, result is " + mkdir);
        synchronized (TestHASafeMode.this) {
          results.put(test, mkdir);
          TestHASafeMode.this.notifyAll();
        }
      } catch (Exception e) {
        LOG.info("Got Exception while calling mkdir", e);
      }
    }
  }.start();
  
  // make sure the client's call has actually been handled by the active NN
  assertFalse("The directory should not be created while NN in safemode",
      fs.exists(test));
  
  Thread.sleep(1000);
  // let nn0 leave safemode
  NameNodeAdapter.leaveSafeMode(nn0);
  LOG.info("leave safemode");
  
  synchronized (this) {
    while (!results.containsKey(test)) {
      this.wait();
    }
    assertTrue(results.get(test));
  }
}
 
Example 19
Source File: TestDNFencing.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Test case that reduces replication of a file with a lot of blocks
 * and then fails over right after those blocks enter the DN invalidation
 * queues on the active. Ensures that fencing is correct and no replicas
 * are lost.
 */
@Test
public void testNNClearsCommandsOnFailoverWithReplChanges()
    throws Exception {
  // Make lots of blocks to increase chances of triggering a bug.
  DFSTestUtil.createFile(fs, TEST_FILE_PATH, 30*SMALL_BLOCK, (short)1, 1L);

  banner("rolling NN1's edit log, forcing catch-up");
  HATestUtil.waitForStandbyToCatchUp(nn1, nn2);
  
  // Get some new replicas reported so that NN2 now considers
  // them over-replicated and schedules some more deletions
  nn1.getRpcServer().setReplication(TEST_FILE, (short) 2);
  while (BlockManagerTestUtil.getComputedDatanodeWork(
      nn1.getNamesystem().getBlockManager()) > 0) {
    LOG.info("Getting more replication work computed");
  }
  BlockManager bm1 = nn1.getNamesystem().getBlockManager();
  while (bm1.getPendingReplicationBlocksCount() > 0) {
    BlockManagerTestUtil.updateState(bm1);
    cluster.triggerHeartbeats();
    Thread.sleep(1000);
  }
  
  banner("triggering BRs");
  cluster.triggerBlockReports();
  
  nn1.getRpcServer().setReplication(TEST_FILE, (short) 1);

  
  banner("computing invalidation on nn1");

  BlockManagerTestUtil.computeInvalidationWork(
      nn1.getNamesystem().getBlockManager());
  doMetasave(nn1);

  banner("computing invalidation on nn2");
  BlockManagerTestUtil.computeInvalidationWork(
      nn2.getNamesystem().getBlockManager());
  doMetasave(nn2);

  // Dump some info for debugging purposes.
  banner("Metadata immediately before failover");
  doMetasave(nn2);


  // Transition nn2 to active even though nn1 still thinks it's active
  banner("Failing to NN2 but let NN1 continue to think it's active");
  NameNodeAdapter.abortEditLogs(nn1);
  NameNodeAdapter.enterSafeMode(nn1, false);

  
  BlockManagerTestUtil.computeInvalidationWork(
      nn2.getNamesystem().getBlockManager());
  cluster.transitionToActive(1);

  // Check that the standby picked up the replication change.
  assertEquals(1,
      nn2.getRpcServer().getFileInfo(TEST_FILE).getReplication());

  // Dump some info for debugging purposes.
  banner("Metadata immediately after failover");
  doMetasave(nn2);
  
  banner("Triggering heartbeats and block reports so that fencing is completed");
  cluster.triggerHeartbeats();
  cluster.triggerBlockReports();
  
  banner("Metadata after nodes have all block-reported");
  doMetasave(nn2);
  
  // Force a rescan of postponedMisreplicatedBlocks.
  BlockManager nn2BM = nn2.getNamesystem().getBlockManager();
  BlockManagerTestUtil.checkHeartbeat(nn2BM);
  BlockManagerTestUtil.rescanPostponedMisreplicatedBlocks(nn2BM);

  // The block should no longer be postponed.
  assertEquals(0, nn2.getNamesystem().getPostponedMisreplicatedBlocks());
  
  // Wait for NN2 to enact its deletions (replication monitor has to run, etc)
  BlockManagerTestUtil.computeInvalidationWork(
      nn2.getNamesystem().getBlockManager());

  HATestUtil.waitForNNToIssueDeletions(nn2);
  cluster.triggerHeartbeats();
  HATestUtil.waitForDNDeletions(cluster);
  cluster.triggerDeletionReports();
  assertEquals(0, nn2.getNamesystem().getUnderReplicatedBlocks());
  assertEquals(0, nn2.getNamesystem().getPendingReplicationBlocks());
  
  banner("Making sure the file is still readable");
  FileSystem fs2 = cluster.getFileSystem(1);
  DFSTestUtil.readFile(fs2, TEST_FILE_PATH);
}
 
Example 20
Source File: TestDelegationToken.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Test that the delegation token secret manager only runs when the
 * NN is out of safe mode. This is because the secret manager
 * has to log to the edit log, which should not be written in
 * safe mode. Regression test for HDFS-2579.
 */
@Test
public void testDTManagerInSafeMode() throws Exception {
  cluster.startDataNodes(config, 1, true, StartupOption.REGULAR, null);
  FileSystem fs = cluster.getFileSystem();
  for (int i = 0; i < 5; i++) {
    DFSTestUtil.createFile(fs, new Path("/test-" + i), 100, (short)1, 1L);
  }
  cluster.getConfiguration(0).setInt(
      DFSConfigKeys.DFS_NAMENODE_DELEGATION_KEY_UPDATE_INTERVAL_KEY, 500); 
  cluster.getConfiguration(0).setInt(
      DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, 30000);
  cluster.setWaitSafeMode(false);
  cluster.restartNameNode();
  NameNode nn = cluster.getNameNode();
  assertTrue(nn.isInSafeMode());
  DelegationTokenSecretManager sm =
    NameNodeAdapter.getDtSecretManager(nn.getNamesystem());
  assertFalse("Secret manager should not run in safe mode", sm.isRunning());
  
  NameNodeAdapter.leaveSafeMode(nn);
  assertTrue("Secret manager should start when safe mode is exited",
      sm.isRunning());
  
  LOG.info("========= entering safemode again");
  
  NameNodeAdapter.enterSafeMode(nn, false);
  assertFalse("Secret manager should stop again when safe mode " +
      "is manually entered", sm.isRunning());
  
  // Set the cluster to leave safemode quickly on its own.
  cluster.getConfiguration(0).setInt(
      DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, 0);
  cluster.setWaitSafeMode(true);
  cluster.restartNameNode();
  nn = cluster.getNameNode();
  sm = NameNodeAdapter.getDtSecretManager(nn.getNamesystem());

  assertFalse(nn.isInSafeMode());
  assertTrue(sm.isRunning());
}