Java Code Examples for org.apache.ratis.util.FileUtils#deleteFully()

The following examples show how to use org.apache.ratis.util.FileUtils#deleteFully() . 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: OzoneManagerRatisUtils.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Verify transaction info with provided lastAppliedIndex.
 *
 * If transaction info transaction Index is less than or equal to
 * lastAppliedIndex, return false, else return true.
 * @param omTransactionInfo
 * @param lastAppliedIndex
 * @param leaderId
 * @param newDBlocation
 * @return boolean
 */
public static boolean verifyTransactionInfo(
    OMTransactionInfo omTransactionInfo,
    long lastAppliedIndex,
    String leaderId, Path newDBlocation) {
  if (omTransactionInfo.getTransactionIndex() <= lastAppliedIndex) {
    OzoneManager.LOG.error("Failed to install checkpoint from OM leader: {}" +
            ". The last applied index: {} is greater than or equal to the " +
            "checkpoint's applied index: {}. Deleting the downloaded " +
            "checkpoint {}", leaderId, lastAppliedIndex,
        omTransactionInfo.getTransactionIndex(), newDBlocation);
    try {
      FileUtils.deleteFully(newDBlocation);
    } catch (IOException e) {
      OzoneManager.LOG.error("Failed to fully delete the downloaded DB " +
          "checkpoint {} from OM leader {}.", newDBlocation, leaderId, e);
    }
    return false;
  }

  return true;
}
 
Example 2
Source File: RaftStorageDirectory.java    From ratis with Apache License 2.0 5 votes vote down vote up
private static void clearDirectory(File dir) throws IOException {
  if (dir.exists()) {
    LOG.info(dir + " already exists.  Deleting it ...");
    FileUtils.deleteFully(dir);
  }
  FileUtils.createDirectories(dir);
}
 
Example 3
Source File: LogOutputStream.java    From ratis with Apache License 2.0 5 votes vote down vote up
public LogOutputStream(File file, boolean append, long segmentMaxSize,
    long preallocatedSize, int bufferSize)
    throws IOException {
  this.file = file;
  this.checksum = new PureJavaCrc32C();
  this.segmentMaxSize = segmentMaxSize;
  this.preallocatedSize = preallocatedSize;
  RandomAccessFile rp = new RandomAccessFile(file, "rw");
  fc = rp.getChannel();
  fc.position(fc.size());
  preallocatedPos = fc.size();
  out = new BufferedWriteChannel(fc, bufferSize);

  try {
    fc = rp.getChannel();
    fc.position(fc.size());
    preallocatedPos = fc.size();

    out = new BufferedWriteChannel(fc, bufferSize);
    if (!append) {
      create();
    }
  } catch (IOException ioe) {
    LOG.warn("Hit IOException while creating log segment " + file
        + ", delete the partial file.");
    // hit IOException, clean up the in-progress log file
    try {
      FileUtils.deleteFully(file);
    } catch (IOException e) {
      LOG.warn("Failed to delete the file " + file, e);
    }
    throw ioe;
  }
}
 
Example 4
Source File: MiniRaftCluster.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
private RaftServerProxy newRaftServer(RaftPeerId id, RaftGroup group, boolean format) {
  LOG.info("newRaftServer: {}, {}, format? {}", id, group, format);
  try {
    final File dir = getStorageDir(id);
    if (format) {
      FileUtils.deleteFully(dir);
      LOG.info("Formatted directory {}", dir);
    }
    final RaftProperties prop = new RaftProperties(properties);
    RaftServerConfigKeys.setStorageDir(prop, Collections.singletonList(dir));
    return newRaftServer(id, getStateMachineRegistry(properties), group, prop);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 5
Source File: RaftStorageDirectory.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
private static void clearDirectory(File dir) throws IOException {
  if (dir.exists()) {
    LOG.info(dir + " already exists.  Deleting it ...");
    FileUtils.deleteFully(dir);
  }
  FileUtils.createDirectories(dir);
}
 
Example 6
Source File: MiniRaftCluster.java    From ratis with Apache License 2.0 5 votes vote down vote up
private RaftServerProxy newRaftServer(RaftPeerId id, RaftGroup group, boolean format) {
  LOG.info("newRaftServer: {}, {}, format? {}", id, group, format);
  try {
    final File dir = getStorageDir(id);
    if (format) {
      FileUtils.deleteFully(dir);
      LOG.info("Formatted directory {}", dir);
    }
    final RaftProperties prop = new RaftProperties(properties);
    RaftServerConfigKeys.setStorageDirs(prop, Collections.singletonList(dir));
    return newRaftServer(id, getStateMachineRegistry(properties), group, prop);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 7
Source File: TestRaftStorage.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (storageDir != null) {
    FileUtils.deleteFully(storageDir.getParentFile());
  }
}
 
Example 8
Source File: TestRaftServerConfigKeys.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDown() throws IOException {
  FileUtils.deleteFully(rootTestDir.get());
}
 
Example 9
Source File: TestServerState.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDown() throws IOException {
  FileUtils.deleteFully(rootTestDir.get());
}
 
Example 10
Source File: TestRaftLogReadWrite.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (storageDir != null) {
    FileUtils.deleteFully(storageDir.getParentFile());
  }
}
 
Example 11
Source File: TestSegmentedRaftLog.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (storageDir != null) {
    FileUtils.deleteFully(storageDir.getParentFile());
  }
}
 
Example 12
Source File: TestServerState.java    From ratis with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDown() throws IOException {
  FileUtils.deleteFully(rootTestDir.get());
}
 
Example 13
Source File: TestRaftStorage.java    From ratis with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (storageDir != null) {
    FileUtils.deleteFully(storageDir.getParentFile());
  }
}
 
Example 14
Source File: TestSegmentedRaftLog.java    From ratis with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (storageDir != null) {
    FileUtils.deleteFully(storageDir.getParentFile());
  }
}
 
Example 15
Source File: TestRaftLogSegment.java    From ratis with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (storageDir != null) {
    FileUtils.deleteFully(storageDir.getParentFile());
  }
}
 
Example 16
Source File: TestRaftLogReadWrite.java    From ratis with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (storageDir != null) {
    FileUtils.deleteFully(storageDir.getParentFile());
  }
}
 
Example 17
Source File: TestRaftServerConfigKeys.java    From ratis with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDown() throws IOException {
  FileUtils.deleteFully(rootTestDir.get());
}
 
Example 18
Source File: MetadataServer.java    From ratis with Apache License 2.0 4 votes vote down vote up
public void cleanUp() throws IOException {
    FileUtils.deleteFully(new File(getServerOpts().getWorkingDir()));
}
 
Example 19
Source File: TestLogSegment.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (storageDir != null) {
    FileUtils.deleteFully(storageDir.getParentFile());
  }
}
 
Example 20
Source File: TestContainerMapper.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void shutdown() throws IOException {
  cluster.shutdown();
  FileUtils.deleteFully(new File(dbPath));
}