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


Java HardLink类代码示例

本文整理汇总了Java中org.apache.hadoop.fs.FileUtil.HardLink的典型用法代码示例。如果您正苦于以下问题:Java HardLink类的具体用法?Java HardLink怎么用?Java HardLink使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HardLink类属于org.apache.hadoop.fs.FileUtil包,在下文中一共展示了HardLink类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unlinkBlock

import org.apache.hadoop.fs.FileUtil.HardLink; //导入依赖的package包/类
/**
 * Remove a hard link by copying the block to a temporary place and 
 * then moving it back
 * @param numLinks number of hard links
 * @return true if copy is successful; 
 *         false if it is already detached or no need to be detached
 * @throws IOException if there is any copy error
 */
boolean unlinkBlock(int numLinks) throws IOException {
  if (isUnlinked()) {
    return false;
  }
  File file = getBlockFile();
  if (file == null || getVolume() == null) {
    throw new IOException("detachBlock:Block not found. " + this);
  }
  File meta = getMetaFile();
  if (meta == null) {
    throw new IOException("Meta file not found for block " + this);
  }

  if (HardLink.getLinkCount(file) > numLinks) {
    DataNode.LOG.info("CopyOnWrite for block " + this);
    unlinkFile(file, this);
  }
  if (HardLink.getLinkCount(meta) > numLinks) {
    unlinkFile(meta, this);
  }
  setUnlinked();
  return true;
}
 
开发者ID:cumulusyebl,项目名称:cumulus,代码行数:32,代码来源:ReplicaInfo.java

示例2: detachBlock

import org.apache.hadoop.fs.FileUtil.HardLink; //导入依赖的package包/类
/**
 * Returns true if this block was copied, otherwise returns false.
 */
boolean detachBlock(Block block, int numLinks) throws IOException {
  if (isDetached()) {
    return false;
  }
  if (file == null || volume == null) {
    throw new IOException("detachBlock:Block not found. " + block);
  }
  File meta = FSDataset.getMetaFile(file, block);
  if (meta == null) {
    throw new IOException("Meta file not found for block " + block);
  }

  if (HardLink.getLinkCount(file) > numLinks) {
    DataNode.LOG.info("CopyOnWrite for block " + block);
    detachFile(file, block);
  }
  if (HardLink.getLinkCount(meta) > numLinks) {
    detachFile(meta, block);
  }
  setDetached();
  return true;
}
 
开发者ID:thisisvoa,项目名称:hadoop-0.20,代码行数:26,代码来源:DatanodeBlockInfo.java

示例3: linkBlocks

import org.apache.hadoop.fs.FileUtil.HardLink; //导入依赖的package包/类
static void linkBlocks(File from, File to, int oldLV) throws IOException {
  if (!from.isDirectory()) {
    if (from.getName().startsWith(COPY_FILE_PREFIX)) {
      IOUtils.copyBytes(new FileInputStream(from), 
                        new FileOutputStream(to), 16*1024, true);
    } else {
      
      //check if we are upgrading from pre-generation stamp version.
      if (oldLV >= PRE_GENERATIONSTAMP_LAYOUT_VERSION) {
        // Link to the new file name.
        to = new File(convertMetatadataFileName(to.getAbsolutePath()));
      }
      
      HardLink.createHardLink(from, to);
    }
    return;
  }
  // from is a directory
  if (!to.mkdir())
    throw new IOException("Cannot create directory " + to);
  String[] blockNames = from.list(new java.io.FilenameFilter() {
      public boolean accept(File dir, String name) {
        return name.startsWith(BLOCK_SUBDIR_PREFIX) 
          || name.startsWith(BLOCK_FILE_PREFIX)
          || name.startsWith(COPY_FILE_PREFIX);
      }
    });
  
  for(int i = 0; i < blockNames.length; i++)
    linkBlocks(new File(from, blockNames[i]), 
               new File(to, blockNames[i]), oldLV);
}
 
开发者ID:thisisvoa,项目名称:hadoop-0.20,代码行数:33,代码来源:DataStorage.java

示例4: linkBlocks

import org.apache.hadoop.fs.FileUtil.HardLink; //导入依赖的package包/类
static void linkBlocks(File from, File to, int oldLV) throws IOException {
  if (!from.exists()) {
    return;
  }
  if (!from.isDirectory()) {
    if (from.getName().startsWith(COPY_FILE_PREFIX)) {
      FileInputStream in = new FileInputStream(from);
      try {
        FileOutputStream out = new FileOutputStream(to);
        try {
          IOUtils.copyBytes(in, out, 16*1024);
        } finally {
          out.close();
        }
      } finally {
        in.close();
      }
    } else {
      
      //check if we are upgrading from pre-generation stamp version.
      if (oldLV >= PRE_GENERATIONSTAMP_LAYOUT_VERSION) {
        // Link to the new file name.
        to = new File(convertMetatadataFileName(to.getAbsolutePath()));
      }
      
      HardLink.createHardLink(from, to);
    }
    return;
  }
  // from is a directory
  if (!to.mkdirs())
    throw new IOException("Cannot create directory " + to);
  String[] blockNames = from.list(new java.io.FilenameFilter() {
      public boolean accept(File dir, String name) {
        return name.startsWith(BLOCK_SUBDIR_PREFIX) 
          || name.startsWith(BLOCK_FILE_PREFIX)
          || name.startsWith(COPY_FILE_PREFIX);
      }
    });
  
  for(int i = 0; i < blockNames.length; i++)
    linkBlocks(new File(from, blockNames[i]), 
               new File(to, blockNames[i]), oldLV);
}
 
开发者ID:cumulusyebl,项目名称:cumulus,代码行数:45,代码来源:DataStorage.java


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