org.apache.hadoop.io.nativeio.NativeIO.renameTo()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.apache.hadoop.io.nativeio.NativeIO.renameTo()方法的一些代码示例,展示了NativeIO.renameTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NativeIO.renameTo()方法的具体详情如下:
包路径:org.apache.hadoop.io.nativeio.NativeIO
类名称:NativeIO
方法名:renameTo

NativeIO.renameTo介绍

[英]A version of renameTo that throws a descriptive exception when it fails.
[中]renameTo的一个版本,失败时会引发描述性异常。

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

public static void rename(File from, File to) throws IOException {
 try {
  NativeIO.renameTo(from, to);
 } catch (NativeIOException e) {
  throw new IOException("Failed to rename " + from.getCanonicalPath()
   + " to " + to.getCanonicalPath() + " due to failure in native rename. "
   + e.toString());
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

private void renameSelf(String newSuffix) throws IOException {
 File src = file;
 File dst = new File(src.getParent(), src.getName() + newSuffix);
 // renameTo fails on Windows if the destination file already exists.
 try {
  if (dst.exists()) {
   if (!dst.delete()) {
    throw new IOException("Couldn't delete " + dst);
   }
  }
  NativeIO.renameTo(src, dst);
 } catch (IOException e) {
  throw new IOException(
    "Couldn't rename log " + src + " to " + dst, e);
 }
 file = dst;
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

@Override
synchronized public void finalizeLogSegment(long firstTxId, long lastTxId)
  throws IOException {
 File inprogressFile = NNStorage.getInProgressEditsFile(sd, firstTxId);
 File dstFile = NNStorage.getFinalizedEditsFile(
   sd, firstTxId, lastTxId);
 LOG.info("Finalizing edits file " + inprogressFile + " -> " + dstFile);
 
 Preconditions.checkState(!dstFile.exists(),
   "Can't finalize edits file " + inprogressFile + " since finalized file " +
   "already exists");
 try {
  NativeIO.renameTo(inprogressFile, dstFile);
 } catch (IOException e) {
  errorReporter.reportErrorOnFile(dstFile);
  throw new IllegalStateException("Unable to finalize edits file " + inprogressFile, e);
 }
 if (inprogressFile.equals(currentInProgress)) {
  currentInProgress = null;
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

NativeIO.renameTo(tmpFile, origFile);
} catch (NativeIOException e) {
 throw new IOException("Could not rename temporary file " + tmpFile

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

public static void rename(File from, File to) throws IOException {
 try {
  NativeIO.renameTo(from, to);
 } catch (NativeIOException e) {
  throw new IOException("Failed to rename " + from.getCanonicalPath()
   + " to " + to.getCanonicalPath() + " due to failure in native rename. "
   + e.toString());
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

public static void rename(File from, File to) throws IOException {
 try {
  NativeIO.renameTo(from, to);
 } catch (NativeIOException e) {
  throw new IOException("Failed to rename " + from.getCanonicalPath()
   + " to " + to.getCanonicalPath() + " due to failure in native rename. "
   + e.toString());
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

private void renameSelf(String newSuffix) throws IOException {
 File src = file;
 File dst = new File(src.getParent(), src.getName() + newSuffix);
 // renameTo fails on Windows if the destination file already exists.
 try {
  if (dst.exists()) {
   if (!dst.delete()) {
    throw new IOException("Couldn't delete " + dst);
   }
  }
  NativeIO.renameTo(src, dst);
 } catch (IOException e) {
  throw new IOException(
    "Couldn't rename log " + src + " to " + dst, e);
 }
 file = dst;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

private void renameSelf(String newSuffix) throws IOException {
 File src = file;
 File dst = new File(src.getParent(), src.getName() + newSuffix);
 // renameTo fails on Windows if the destination file already exists.
 try {
  if (dst.exists()) {
   if (!dst.delete()) {
    throw new IOException("Couldn't delete " + dst);
   }
  }
  NativeIO.renameTo(src, dst);
 } catch (IOException e) {
  throw new IOException(
    "Couldn't rename log " + src + " to " + dst, e);
 }
 file = dst;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

@Override
synchronized public void finalizeLogSegment(long firstTxId, long lastTxId)
  throws IOException {
 File inprogressFile = NNStorage.getInProgressEditsFile(sd, firstTxId);
 File dstFile = NNStorage.getFinalizedEditsFile(
   sd, firstTxId, lastTxId);
 LOG.info("Finalizing edits file " + inprogressFile + " -> " + dstFile);
 
 Preconditions.checkState(!dstFile.exists(),
   "Can't finalize edits file " + inprogressFile + " since finalized file " +
   "already exists");
 try {
  NativeIO.renameTo(inprogressFile, dstFile);
 } catch (IOException e) {
  errorReporter.reportErrorOnFile(dstFile);
  throw new IllegalStateException("Unable to finalize edits file " + inprogressFile, e);
 }
 if (inprogressFile.equals(currentInProgress)) {
  currentInProgress = null;
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

static File moveBlockFiles(Block b, File srcfile, File destdir)
  throws IOException {
 final File dstfile = new File(destdir, b.getBlockName());
 final File srcmeta = FsDatasetUtil.getMetaFile(srcfile, b.getGenerationStamp());
 final File dstmeta = FsDatasetUtil.getMetaFile(dstfile, b.getGenerationStamp());
 try {
  NativeIO.renameTo(srcmeta, dstmeta);
 } catch (IOException e) {
  throw new IOException("Failed to move meta file for " + b
    + " from " + srcmeta + " to " + dstmeta, e);
 }
 try {
  NativeIO.renameTo(srcfile, dstfile);
 } catch (IOException e) {
  throw new IOException("Failed to move block file for " + b
    + " from " + srcfile + " to " + dstfile.getAbsolutePath(), e);
 }
 if (LOG.isDebugEnabled()) {
  LOG.debug("addFinalizedBlock: Moved " + srcmeta + " to " + dstmeta
    + " and " + srcfile + " to " + dstfile);
 }
 return dstfile;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

NativeIO.renameTo(tmpFile, origFile);
} catch (NativeIOException e) {
 throw new IOException("Could not rename temporary file " + tmpFile

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

NativeIO.renameTo(tmpFile, origFile);
} catch (NativeIOException e) {
 throw new IOException("Could not rename temporary file " + tmpFile

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

NativeIO.renameTo(metaFile, targetMetaFile);
} catch (IOException e) {
 LOG.warn("Failed to move meta file from "
 NativeIO.renameTo(blockFile, targetBlockFile);
} catch (IOException e) {
 LOG.warn("Failed to move block file from "

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

static File moveBlockFiles(Block b, File srcfile, File destdir)
  throws IOException {
 final File dstfile = new File(destdir, b.getBlockName());
 final File srcmeta = FsDatasetUtil.getMetaFile(srcfile, b.getGenerationStamp());
 final File dstmeta = FsDatasetUtil.getMetaFile(dstfile, b.getGenerationStamp());
 try {
  NativeIO.renameTo(srcmeta, dstmeta);
 } catch (IOException e) {
  throw new IOException("Failed to move meta file for " + b
    + " from " + srcmeta + " to " + dstmeta, e);
 }
 try {
  NativeIO.renameTo(srcfile, dstfile);
 } catch (IOException e) {
  throw new IOException("Failed to move block file for " + b
    + " from " + srcfile + " to " + dstfile.getAbsolutePath(), e);
 }
 if (LOG.isDebugEnabled()) {
  LOG.debug("addFinalizedBlock: Moved " + srcmeta + " to " + dstmeta
    + " and " + srcfile + " to " + dstfile);
 }
 return dstfile;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

@Override
synchronized public void finalizeLogSegment(long firstTxId, long lastTxId)
  throws IOException {
 File inprogressFile = NNStorage.getInProgressEditsFile(sd, firstTxId);
 File dstFile = NNStorage.getFinalizedEditsFile(
   sd, firstTxId, lastTxId);
 LOG.info("Finalizing edits file " + inprogressFile + " -> " + dstFile);
 
 Preconditions.checkState(!dstFile.exists(),
   "Can't finalize edits file " + inprogressFile + " since finalized file " +
   "already exists");
 try {
  NativeIO.renameTo(inprogressFile, dstFile);
 } catch (IOException e) {
  errorReporter.reportErrorOnFile(dstFile);
  throw new IllegalStateException("Unable to finalize edits file " + inprogressFile, e);
 }
 if (inprogressFile.equals(currentInProgress)) {
  currentInProgress = null;
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

/**
 * Bump a replica's generation stamp to a new one.
 * Its on-disk meta file name is renamed to be the new one too.
 * 
 * @param replicaInfo a replica
 * @param newGS new generation stamp
 * @throws IOException if rename fails
 */
private void bumpReplicaGS(ReplicaInfo replicaInfo, 
  long newGS) throws IOException { 
 long oldGS = replicaInfo.getGenerationStamp();
 File oldmeta = replicaInfo.getMetaFile();
 replicaInfo.setGenerationStamp(newGS);
 File newmeta = replicaInfo.getMetaFile();
 // rename meta file to new GS
 if (LOG.isDebugEnabled()) {
  LOG.debug("Renaming " + oldmeta + " to " + newmeta);
 }
 try {
  NativeIO.renameTo(oldmeta, newmeta);
 } catch (IOException e) {
  replicaInfo.setGenerationStamp(oldGS); // restore old GS
  throw new IOException("Block " + replicaInfo + " reopen failed. " +
             " Unable to move meta file  " + oldmeta +
             " to " + newmeta, e);
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

NativeIO.renameTo(metaFile, targetMetaFile);
} catch (IOException e) {
 LOG.warn("Failed to move meta file from "
 NativeIO.renameTo(blockFile, targetBlockFile);
} catch (IOException e) {
 LOG.warn("Failed to move block file from "

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Bump a replica's generation stamp to a new one.
 * Its on-disk meta file name is renamed to be the new one too.
 * 
 * @param replicaInfo a replica
 * @param newGS new generation stamp
 * @throws IOException if rename fails
 */
private void bumpReplicaGS(ReplicaInfo replicaInfo, 
  long newGS) throws IOException { 
 long oldGS = replicaInfo.getGenerationStamp();
 File oldmeta = replicaInfo.getMetaFile();
 replicaInfo.setGenerationStamp(newGS);
 File newmeta = replicaInfo.getMetaFile();
 // rename meta file to new GS
 if (LOG.isDebugEnabled()) {
  LOG.debug("Renaming " + oldmeta + " to " + newmeta);
 }
 try {
  NativeIO.renameTo(oldmeta, newmeta);
 } catch (IOException e) {
  replicaInfo.setGenerationStamp(oldGS); // restore old GS
  throw new IOException("Block " + replicaInfo + " reopen failed. " +
             " Unable to move meta file  " + oldmeta +
             " to " + newmeta, e);
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

NativeIO.renameTo(nonExistentFile, targetFile);
 Assert.fail();
} catch (NativeIOException e) {
NativeIO.renameTo(sourceFile, sourceFile);
NativeIO.renameTo(sourceFile, targetFile);
File badTarget = new File(targetFile, "subdir");
try {
 NativeIO.renameTo(sourceFile, badTarget);
 Assert.fail();
} catch (NativeIOException e) {
NativeIO.renameTo(sourceFile, targetFile);

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

NativeIO.renameTo(nonExistentFile, targetFile);
 Assert.fail();
} catch (NativeIOException e) {
NativeIO.renameTo(sourceFile, sourceFile);
NativeIO.renameTo(sourceFile, targetFile);
File badTarget = new File(targetFile, "subdir");
try {
 NativeIO.renameTo(sourceFile, badTarget);
 Assert.fail();
} catch (NativeIOException e) {

相关文章