org.apache.cassandra.io.util.FileUtils类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(177)

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

FileUtils介绍

暂无

代码示例

代码示例来源:origin: hector-client/hector

public static void cleanup() throws IOException
{
  // clean up commitlog
  String[] directoryNames = { DatabaseDescriptor.getCommitLogLocation(), };
  for (String dirName : directoryNames)
  {
    File dir = new File(dirName);
    if (!dir.exists())
      throw new RuntimeException("No such directory: " + dir.getAbsolutePath());
    FileUtils.deleteRecursive(dir);
  }
  // clean up data directory which are stored as data directory/table/data files
  for (String dirName : DatabaseDescriptor.getAllDataFileLocations())
  {
    File dir = new File(dirName);
    if (!dir.exists())
      throw new RuntimeException("No such directory: " + dir.getAbsolutePath());
    FileUtils.deleteRecursive(dir);
  }
}

代码示例来源:origin: hector-client/hector

/**
 * Creates a directory
 * 
 * @param dir
 * @throws IOException
 */
private static void mkdir(String dir) throws IOException {
 FileUtils.createDirectory(dir);
}

代码示例来源:origin: Netflix/Priam

public ClearCredential() {
  FileInputStream fis = null;
  try {
    fis = new FileInputStream(CRED_FILE);
    final Properties props = new Properties();
    props.load(fis);
    AWS_ACCESS_ID =
        props.getProperty("AWSACCESSID") != null
            ? props.getProperty("AWSACCESSID").trim()
            : "";
    AWS_KEY = props.getProperty("AWSKEY") != null ? props.getProperty("AWSKEY").trim() : "";
  } catch (Exception e) {
    logger.error("Exception with credential file ", e);
    throw new RuntimeException("Problem reading credential file. Cannot start.", e);
  } finally {
    FileUtils.closeQuietly(fis);
  }
}

代码示例来源:origin: hector-client/hector

private static void rmdir(String dir) throws IOException {
 File dirFile = new File(dir);
 if (dirFile.exists()) {
  FileUtils.deleteRecursive(new File(dir));
 }
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

private IndexSummary buildSummaryAtLevel(int newSamplingLevel) throws IOException
{
  // we read the positions in a BRAF so we don't have to worry about an entry spanning a mmap boundary.
  RandomAccessReader primaryIndex = RandomAccessReader.open(new File(descriptor.filenameFor(Component.PRIMARY_INDEX)));
  try
  {
    long indexSize = primaryIndex.length();
    try (IndexSummaryBuilder summaryBuilder = new IndexSummaryBuilder(estimatedKeys(), metadata.params.minIndexInterval, newSamplingLevel))
    {
      long indexPosition;
      while ((indexPosition = primaryIndex.getFilePointer()) != indexSize)
      {
        summaryBuilder.maybeAddEntry(decorateKey(ByteBufferUtil.readWithShortLength(primaryIndex)), indexPosition);
        RowIndexEntry.Serializer.skip(primaryIndex, descriptor.version);
      }
      return summaryBuilder.build(getPartitioner());
    }
  }
  finally
  {
    FileUtils.closeQuietly(primaryIndex);
  }
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public void release()
{
  int n = references.decrementAndGet();
  if (n == 0)
  {
    FileUtils.closeQuietly(index);
    sstableRef.release();
    if (obsolete.get() || sstableRef.globalCount() == 0)
      FileUtils.delete(index.getIndexPath());
  }
}

代码示例来源:origin: jsevellec/cassandra-unit

public void discard(CommitLogSegment segment, boolean delete)
{
  segment.close();
  addSize(-segment.onDiskSize());
  cdcSizeTracker.processDiscardedSegment(segment);
  if (segment.getCDCState() == CDCState.CONTAINS)
    FileUtils.renameWithConfirm(segment.logFile.getAbsolutePath(), DatabaseDescriptor.getCDCLogLocation() + File.separator + segment.logFile.getName());
  else
  {
    if (delete)
      FileUtils.deleteWithConfirm(segment.logFile);
  }
}

代码示例来源:origin: com.netflix.sstableadaptor/sstable-adaptor-cassandra

private void rewriteSSTableMetadata(Descriptor descriptor, Map<MetadataType, MetadataComponent> currentComponents) throws IOException
  {
    String filePath = descriptor.tmpFilenameFor(Component.STATS);
    try (DataOutputStreamPlus out = new BufferedDataOutputStreamPlus(new FileOutputStream(filePath)))
    {
      serialize(currentComponents, out, descriptor.version);
      out.flush();
    }
    // we cant move a file on top of another file in windows:
    if (FBUtilities.isWindows)
      FileUtils.delete(descriptor.filenameFor(Component.STATS));
    FileUtils.renameWithConfirm(filePath, descriptor.filenameFor(Component.STATS));

  }
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

private void saveSummary(SegmentedFile.Builder ibuilder, SegmentedFile.Builder dbuilder, IndexSummary summary)
{
  File summariesFile = new File(descriptor.filenameFor(Component.SUMMARY));
  if (summariesFile.exists())
    FileUtils.deleteWithConfirm(summariesFile);
  DataOutputStreamAndChannel oStream = null;
  try
  {
    oStream = new DataOutputStreamAndChannel(new FileOutputStream(summariesFile));
    IndexSummary.serializer.serialize(summary, oStream, descriptor.version.hasSamplingLevel);
    ByteBufferUtil.writeWithLength(first.getKey(), oStream);
    ByteBufferUtil.writeWithLength(last.getKey(), oStream);
    ibuilder.serializeBounds(oStream);
    dbuilder.serializeBounds(oStream);
    // write a magic number, to indicate this summary has been sampled correctly
    oStream.writeInt(ACCURATE_BOUNDARIES_MAGIC_NUMBER);
  }
  catch (IOException e)
  {
    logger.debug("Cannot save SSTable Summary: ", e);
    // corrupted hence delete it and let it load it now.
    if (summariesFile.exists())
      FileUtils.deleteWithConfirm(summariesFile);
  }
  finally
  {
    FileUtils.closeQuietly(oStream);
  }
}

代码示例来源:origin: jsevellec/cassandra-unit

/**
 * Save index summary to Summary.db file.
 */
public static void saveSummary(Descriptor descriptor, DecoratedKey first, DecoratedKey last, IndexSummary summary)
{
  File summariesFile = new File(descriptor.filenameFor(Component.SUMMARY));
  if (summariesFile.exists())
    FileUtils.deleteWithConfirm(summariesFile);
  try (DataOutputStreamPlus oStream = new BufferedDataOutputStreamPlus(new FileOutputStream(summariesFile));)
  {
    IndexSummary.serializer.serialize(summary, oStream, descriptor.version.hasSamplingLevel());
    ByteBufferUtil.writeWithLength(first.getKey(), oStream);
    ByteBufferUtil.writeWithLength(last.getKey(), oStream);
  }
  catch (IOException e)
  {
    logger.trace("Cannot save SSTable Summary: ", e);
    // corrupted hence delete it and let it load it now.
    if (summariesFile.exists())
      FileUtils.deleteWithConfirm(summariesFile);
  }
}

代码示例来源:origin: jsevellec/cassandra-unit

public void releaseBuffer(ByteBuffer buffer)
{
  usedBuffers.decrementAndGet();
  if (bufferPool.size() < maxBufferPoolSize)
    bufferPool.add(buffer);
  else
    FileUtils.clean(buffer);
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public static void createHardLink(String from, String to)
{
  createHardLink(new File(from), new File(to));
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

/**
 * Dump the inter arrival times for examination if necessary.
 */
public void dumpInterArrivalTimes()
{
  File file = FileUtils.createTempFile("failuredetector-", ".dat");
  OutputStream os = null;
  try
  {
    os = new BufferedOutputStream(new FileOutputStream(file, true));
    os.write(toString().getBytes());
  }
  catch (IOException e)
  {
    throw new FSWriteError(e, file);
  }
  finally
  {
    FileUtils.closeQuietly(os);
  }
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public static void close(Closeable... cs) throws IOException
{
  close(Arrays.asList(cs));
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

/**
 * Simply delete untracked segment files w/standard, as it'll be flushed to sstables during recovery
 *
 * @param file segment file that is no longer in use.
 */
void handleReplayedSegment(final File file)
{
  // (don't decrease managed size, since this was never a "live" segment)
  logger.trace("(Unopened) segment {} is no longer needed and will be deleted now", file);
  FileUtils.deleteWithConfirm(file);
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public static File createTempFile(String prefix, String suffix)
{
  return createTempFile(prefix, suffix, new File(System.getProperty("java.io.tmpdir")));
}

代码示例来源:origin: io.zipkin.brave.cassandra/brave-instrumentation-cassandra-tests

private static void cleanupSavedCaches() {
 File cachesDir = new File(DatabaseDescriptor.getSavedCachesLocation());
 if (!cachesDir.exists() || !cachesDir.isDirectory()) return;
 FileUtils.delete(cachesDir.listFiles());
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public static void renameWithOutConfirm(String from, String to)
{
  try
  {
    atomicMoveWithFallback(new File(from).toPath(), new File(to).toPath());
  }
  catch (IOException e)
  {
    if (logger.isTraceEnabled())
      logger.trace("Could not move file "+from+" to "+to, e);
  }
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

public void delete()
{
  FileUtils.delete(lockfile);
}

代码示例来源:origin: hector-client/hector

public static void startCassandraInstance(String pathToDataDir) throws TTransportException, IOException,
InterruptedException, SecurityException, IllegalArgumentException, NoSuchMethodException,
IllegalAccessException, InvocationTargetException {
 if (cassandraStarted) {
  return;
 }
 try {
  FileUtils.deleteRecursive(new File(pathToDataDir));
 }
 catch (AssertionError e) {
  // eat
 }
 embedded = new EmbeddedServerHelper();
 try {
  embedded.setup();
 } catch (ConfigurationException ce) {
  throw new RuntimeException(ce);
 }
 
 cassandraStarted = true;
}

相关文章