org.apache.lucene.util.IOUtils.fsync()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(166)

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

IOUtils.fsync介绍

[英]Ensure that any writes to the given file is written to the storage device that contains it.
[中]确保对给定文件的任何写入都会写入包含该文件的存储设备。

代码示例

代码示例来源:origin: org.apache.lucene/lucene-core

protected void fsync(String name) throws IOException {
 IOUtils.fsync(directory.resolve(name), false);
}

代码示例来源:origin: org.apache.lucene/lucene-core

@Override
public void syncMetaData() throws IOException {
 // TODO: to improve listCommits(), IndexFileDeleter could call this after deleting segments_Ns
 ensureOpen();
 IOUtils.fsync(directory, true);
 maybeDeletePendingFiles();
}

代码示例来源:origin: harbby/presto-connectors

protected void fsync(String name) throws IOException {
  IOUtils.fsync(directory.resolve(name), false);
 }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

protected void fsync(String name) throws IOException {
  IOUtils.fsync(directory.resolve(name), false);
 }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene

protected void fsync(String name) throws IOException {
 IOUtils.fsync(directory.resolve(name), false);
}

代码示例来源:origin: harbby/presto-connectors

@Override
  public void move(String source, String target) throws IOException {
    Path sourcePath = path.resolve(source);
    Path targetPath = path.resolve(target);
    // If the target file exists then Files.move() behaviour is implementation specific
    // the existing file might be replaced or this method fails by throwing an IOException.
    assert !Files.exists(targetPath);
    Files.move(sourcePath, targetPath, StandardCopyOption.ATOMIC_MOVE);
    IOUtils.fsync(path, true);
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

@Override
  public void move(String source, String target) throws IOException {
    Path sourcePath = path.resolve(source);
    Path targetPath = path.resolve(target);
    // If the target file exists then Files.move() behaviour is implementation specific
    // the existing file might be replaced or this method fails by throwing an IOException.
    assert !Files.exists(targetPath);
    Files.move(sourcePath, targetPath, StandardCopyOption.ATOMIC_MOVE);
    IOUtils.fsync(path, true);
  }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void writeBlob(String blobName, BytesReference data) throws IOException {
  final Path file = path.resolve(blobName);
  try (OutputStream outputStream = Files.newOutputStream(file)) {
    data.writeTo(outputStream);
  }
  IOUtils.fsync(file, false);
  IOUtils.fsync(path, true);
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

@Override
public void renameFile(String source, String dest) throws IOException {
 ensureOpen();
 Files.move(directory.resolve(source), directory.resolve(dest), StandardCopyOption.ATOMIC_MOVE);
 // TODO: should we move directory fsync to a separate 'syncMetadata' method?
 // for example, to improve listCommits(), IndexFileDeleter could also call that after deleting segments_Ns
 IOUtils.fsync(directory, true);
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException {
  final Path file = path.resolve(blobName);
  try (OutputStream outputStream = Files.newOutputStream(file)) {
    Streams.copy(inputStream, outputStream, new byte[blobStore.bufferSizeInBytes()]);
  }
  IOUtils.fsync(file, false);
  IOUtils.fsync(path, true);
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void renameFile(String source, String dest) throws IOException {
 ensureOpen();
 Files.move(directory.resolve(source), directory.resolve(dest), StandardCopyOption.ATOMIC_MOVE);
 // TODO: should we move directory fsync to a separate 'syncMetadata' method?
 // for example, to improve listCommits(), IndexFileDeleter could also call that after deleting segments_Ns
 IOUtils.fsync(directory, true);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Moves the index folder found in <code>source</code> to <code>target</code>
 */
void upgrade(final Index index, final Path source, final Path target) throws IOException {
  boolean success = false;
  try {
    Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
    success = true;
  } catch (NoSuchFileException | FileNotFoundException exception) {
    // thrown when the source is non-existent because the folder was renamed
    // by another node (shared FS) after we checked if the target exists
    logger.error((Supplier<?>) () -> new ParameterizedMessage("multiple nodes trying to upgrade [{}] in parallel, retry " +
      "upgrading with single node", target), exception);
    throw exception;
  } finally {
    if (success) {
      logger.info("{} moved from [{}] to [{}]", index, source, target);
      logger.trace("{} syncing directory [{}]", index, target);
      IOUtils.fsync(target, true);
    }
  }
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Moves the index folder found in <code>source</code> to <code>target</code>
 */
void upgrade(final Index index, final Path source, final Path target) throws IOException {
  boolean success = false;
  try {
    Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
    success = true;
  } catch (NoSuchFileException | FileNotFoundException exception) {
    // thrown when the source is non-existent because the folder was renamed
    // by another node (shared FS) after we checked if the target exists
    logger.error((Supplier<?>) () -> new ParameterizedMessage("multiple nodes trying to upgrade [{}] in parallel, retry " +
      "upgrading with single node", target), exception);
    throw exception;
  } finally {
    if (success) {
      logger.info("{} moved from [{}] to [{}]", index, source, target);
      logger.trace("{} syncing directory [{}]", index, target);
      IOUtils.fsync(target, true);
    }
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

@Override
public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException {
  if (blobExists(blobName)) {
    throw new FileAlreadyExistsException("blob [" + blobName + "] already exists, cannot overwrite");
  }
  final Path file = path.resolve(blobName);
  try (OutputStream outputStream = Files.newOutputStream(file, StandardOpenOption.CREATE_NEW)) {
    Streams.copy(inputStream, outputStream, new byte[blobStore.bufferSizeInBytes()]);
  }
  IOUtils.fsync(file, false);
  IOUtils.fsync(path, true);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/** Write a checkpoint file to the given location with the given generation */
public static void writeEmptyCheckpoint(Path filename, int translogLength, long translogGeneration) throws IOException {
  Checkpoint emptyCheckpoint = new Checkpoint(translogLength, 0, translogGeneration);
  Checkpoint.write(FileChannel::open, filename, emptyCheckpoint,
    StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE_NEW);
  // fsync with metadata here to make sure.
  IOUtils.fsync(filename, false);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene

@Override
public void syncMetaData() throws IOException {
 // TODO: to improve listCommits(), IndexFileDeleter could call this after deleting segments_Ns
 ensureOpen();
 IOUtils.fsync(directory, true);
 maybeDeletePendingFiles();
}

代码示例来源:origin: harbby/presto-connectors

for (Path moved : movedFiles) {
  logger.info("{} syncing [{}]", shard, moved.getFileName());
  IOUtils.fsync(moved, false);
IOUtils.fsync(targetDir, true);

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

IOUtils.fsync(tmpStatePath, false); // fsync the state file
Files.move(tmpStatePath, finalStatePath, StandardCopyOption.ATOMIC_MOVE);
IOUtils.fsync(stateLocation, true);
for (int i = 1; i < locations.length; i++) {
  stateLocation = locations[i].resolve(STATE_DIR_NAME);
    IOUtils.fsync(stateLocation, true); // we just fsync the dir here..
  } finally {
    Files.deleteIfExists(tmpPath);

代码示例来源:origin: harbby/presto-connectors

IOUtils.fsync(tempFile, false);
Files.move(tempFile, commitCheckpoint, StandardCopyOption.ATOMIC_MOVE);
tempFileRenamed = true;
IOUtils.fsync(commitCheckpoint.getParent(), true);

代码示例来源:origin: harbby/presto-connectors

Path commitCheckpoint = location.resolve(getCommitCheckpointFileName(currentCommittingTranslog.getGeneration()));
Files.copy(checkpoint, commitCheckpoint);
IOUtils.fsync(commitCheckpoint, false);
IOUtils.fsync(commitCheckpoint.getParent(), true);

相关文章