当前位置: 首页>>代码示例>>Java>>正文


Java DistributedFileSystem.setSafeMode方法代码示例

本文整理汇总了Java中org.apache.hadoop.hdfs.DistributedFileSystem.setSafeMode方法的典型用法代码示例。如果您正苦于以下问题:Java DistributedFileSystem.setSafeMode方法的具体用法?Java DistributedFileSystem.setSafeMode怎么用?Java DistributedFileSystem.setSafeMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hdfs.DistributedFileSystem的用法示例。


在下文中一共展示了DistributedFileSystem.setSafeMode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSaveNamespaceWithRenamedLease

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
/**
 * Test for save namespace should succeed when parent directory renamed with
 * open lease and destination directory exist. 
 * This test is a regression for HDFS-2827
 */
@Test
public void testSaveNamespaceWithRenamedLease() throws Exception {
  MiniDFSCluster cluster = new MiniDFSCluster.Builder(new Configuration())
      .numDataNodes(1).build();
  cluster.waitActive();
  DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
  OutputStream out = null;
  try {
    fs.mkdirs(new Path("/test-target"));
    out = fs.create(new Path("/test-source/foo")); // don't close
    fs.rename(new Path("/test-source/"), new Path("/test-target/"));

    fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    cluster.getNameNodeRpc().saveNamespace();
    fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
  } finally {
    IOUtils.cleanup(LOG, out, fs);
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestSaveNamespace.java

示例2: testSaveNamespaceWithDanglingLease

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
@Test (timeout=30000)
public void testSaveNamespaceWithDanglingLease() throws Exception {
  MiniDFSCluster cluster = new MiniDFSCluster.Builder(new Configuration())
      .numDataNodes(1).build();
  cluster.waitActive();
  DistributedFileSystem fs = cluster.getFileSystem();
  try {
    cluster.getNamesystem().leaseManager.addLease("me", "/non-existent");      
    fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    cluster.getNameNodeRpc().saveNamespace();
    fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
  } finally {
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:TestSaveNamespace.java

示例3: testDigest

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
/**
 * Ensure that the digest written by the saver equals to the digest of the
 * file.
 */
@Test
public void testDigest() throws IOException {
  Configuration conf = new Configuration();
  MiniDFSCluster cluster = null;
  try {
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
    DistributedFileSystem fs = cluster.getFileSystem();
    fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    fs.saveNamespace();
    fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
    File currentDir = FSImageTestUtil.getNameNodeCurrentDirs(cluster, 0).get(
        0);
    File fsimage = FSImageTestUtil.findNewestImageFile(currentDir
        .getAbsolutePath());
    assertEquals(MD5FileUtils.readStoredMd5ForFile(fsimage),
        MD5FileUtils.computeMd5ForFile(fsimage));
  } finally {
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:TestFSImage.java

示例4: isInSafeMode

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
/**
 * We use reflection because {@link DistributedFileSystem#setSafeMode(
 * HdfsConstants.SafeModeAction action, boolean isChecked)} is not in hadoop 1.1
 *
 * @param dfs
 * @return whether we're in safe mode
 * @throws IOException
 */
private static boolean isInSafeMode(DistributedFileSystem dfs) throws IOException {
  boolean inSafeMode = false;
  try {
    Method m = DistributedFileSystem.class.getMethod("setSafeMode", new Class<?> []{
        org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.class, boolean.class});
    inSafeMode = (Boolean) m.invoke(dfs,
      org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.SAFEMODE_GET, true);
  } catch (Exception e) {
    if (e instanceof IOException) throw (IOException) e;

    // Check whether dfs is on safemode.
    inSafeMode = dfs.setSafeMode(
      org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.SAFEMODE_GET);
  }
  return inSafeMode;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:25,代码来源:FSUtils.java

示例5: waitExitSafeMode

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
private boolean waitExitSafeMode(DistributedFileSystem dfs, boolean inSafeMode)
    throws IOException {
  while (inSafeMode) {
    try {
      Thread.sleep(5000);
    } catch (java.lang.InterruptedException e) {
      throw new IOException("Wait Interrupted");
    }
    inSafeMode = dfs.setSafeMode(SafeModeAction.SAFEMODE_GET, false);
  }
  return inSafeMode;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:DFSAdmin.java

示例6: restart

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
/**
 * Restart the NameNode, optionally saving a new checkpoint.
 *
 * @param fs DistributedFileSystem used for saving namespace
 * @param persistNamespace boolean true to save a new checkpoint
 * @throws IOException if restart fails
 */
private void restart(DistributedFileSystem fs, boolean persistNamespace)
    throws IOException {
  if (persistNamespace) {
    fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    fs.saveNamespace();
    fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
  }

  cluster.restartNameNode();
  cluster.waitActive();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestFSImageWithAcl.java

示例7: testAcl

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
private void testAcl(boolean persistNamespace) throws IOException {
  Path p = new Path("/p");
  DistributedFileSystem fs = cluster.getFileSystem();
  fs.create(p).close();
  fs.mkdirs(new Path("/23"));

  AclEntry e = new AclEntry.Builder().setName("foo")
      .setPermission(READ_EXECUTE).setScope(ACCESS).setType(USER).build();
  fs.modifyAclEntries(p, Lists.newArrayList(e));

  restart(fs, persistNamespace);

  AclStatus s = cluster.getNamesystem().getAclStatus(p.toString());
  AclEntry[] returned = Lists.newArrayList(s.getEntries()).toArray(
      new AclEntry[0]);
  Assert.assertArrayEquals(new AclEntry[] {
      aclEntry(ACCESS, USER, "foo", READ_EXECUTE),
      aclEntry(ACCESS, GROUP, READ) }, returned);

  fs.removeAcl(p);

  if (persistNamespace) {
    fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    fs.saveNamespace();
    fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
  }

  cluster.restartNameNode();
  cluster.waitActive();

  s = cluster.getNamesystem().getAclStatus(p.toString());
  returned = Lists.newArrayList(s.getEntries()).toArray(new AclEntry[0]);
  Assert.assertArrayEquals(new AclEntry[] { }, returned);

  fs.modifyAclEntries(p, Lists.newArrayList(e));
  s = cluster.getNamesystem().getAclStatus(p.toString());
  returned = Lists.newArrayList(s.getEntries()).toArray(new AclEntry[0]);
  Assert.assertArrayEquals(new AclEntry[] {
      aclEntry(ACCESS, USER, "foo", READ_EXECUTE),
      aclEntry(ACCESS, GROUP, READ) }, returned);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:42,代码来源:TestFSImageWithAcl.java

示例8: testPersistHelper

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
private void testPersistHelper(Configuration conf) throws IOException {
  MiniDFSCluster cluster = null;
  try {
    cluster = new MiniDFSCluster.Builder(conf).build();
    cluster.waitActive();
    FSNamesystem fsn = cluster.getNamesystem();
    DistributedFileSystem fs = cluster.getFileSystem();

    final Path dir = new Path("/abc/def");
    final Path file1 = new Path(dir, "f1");
    final Path file2 = new Path(dir, "f2");

    // create an empty file f1
    fs.create(file1).close();

    // create an under-construction file f2
    FSDataOutputStream out = fs.create(file2);
    out.writeBytes("hello");
    ((DFSOutputStream) out.getWrappedStream()).hsync(EnumSet
        .of(SyncFlag.UPDATE_LENGTH));

    // checkpoint
    fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    fs.saveNamespace();
    fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);

    cluster.restartNameNode();
    cluster.waitActive();
    fs = cluster.getFileSystem();

    assertTrue(fs.isDirectory(dir));
    assertTrue(fs.exists(file1));
    assertTrue(fs.exists(file2));

    // check internals of file2
    INodeFile file2Node = fsn.dir.getINode4Write(file2.toString()).asFile();
    assertEquals("hello".length(), file2Node.computeFileSize());
    assertTrue(file2Node.isUnderConstruction());
    BlockInfoContiguous[] blks = file2Node.getBlocks();
    assertEquals(1, blks.length);
    assertEquals(BlockUCState.UNDER_CONSTRUCTION, blks[0].getBlockUCState());
    // check lease manager
    Lease lease = fsn.leaseManager.getLeaseByPath(file2.toString());
    Assert.assertNotNull(lease);
  } finally {
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:51,代码来源:TestFSImage.java

示例9: testLoadMtimeAtime

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类
/**
 * Ensure mtime and atime can be loaded from fsimage.
 */
@Test(timeout=60000)
public void testLoadMtimeAtime() throws Exception {
  Configuration conf = new Configuration();
  MiniDFSCluster cluster = null;
  try {
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
    cluster.waitActive();
    DistributedFileSystem hdfs = cluster.getFileSystem();
    String userDir = hdfs.getHomeDirectory().toUri().getPath().toString();
    Path file = new Path(userDir, "file");
    Path dir = new Path(userDir, "/dir");
    Path link = new Path(userDir, "/link");
    hdfs.createNewFile(file);
    hdfs.mkdirs(dir);
    hdfs.createSymlink(file, link, false);

    long mtimeFile = hdfs.getFileStatus(file).getModificationTime();
    long atimeFile = hdfs.getFileStatus(file).getAccessTime();
    long mtimeDir = hdfs.getFileStatus(dir).getModificationTime();
    long mtimeLink = hdfs.getFileLinkStatus(link).getModificationTime();
    long atimeLink = hdfs.getFileLinkStatus(link).getAccessTime();

    // save namespace and restart cluster
    hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER);
    hdfs.saveNamespace();
    hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE);
    cluster.shutdown();
    cluster = new MiniDFSCluster.Builder(conf).format(false)
        .numDataNodes(1).build();
    cluster.waitActive();
    hdfs = cluster.getFileSystem();
    
    assertEquals(mtimeFile, hdfs.getFileStatus(file).getModificationTime());
    assertEquals(atimeFile, hdfs.getFileStatus(file).getAccessTime());
    assertEquals(mtimeDir, hdfs.getFileStatus(dir).getModificationTime());
    assertEquals(mtimeLink, hdfs.getFileLinkStatus(link).getModificationTime());
    assertEquals(atimeLink, hdfs.getFileLinkStatus(link).getAccessTime());
  } finally {
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:47,代码来源:TestFSImage.java


注:本文中的org.apache.hadoop.hdfs.DistributedFileSystem.setSafeMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。