/** * Delete the cluster container directory. */ public void deleteDirectory() { if (null != clusterDir) { IoUtil.delete(clusterDir, false); } }
private void closeRecordingSegment() { IoUtil.unmap(mappedSegmentBuffer); mappedSegmentBuffer = null; }
public static MappedByteBuffer mapExistingFile( final File markFile, final Consumer<String> logger, final long offset, final long length) { if (markFile.exists()) { if (null != logger) { logger.accept("INFO: Mark file exists: " + markFile); } return IoUtil.mapExistingFile(markFile, markFile.toString(), offset, length); } return null; }
/** * Is a media driver active in the given directory? * * @param directory to check * @param driverTimeoutMs for the driver liveness check. * @param logger for feedback as liveness checked. * @return true if a driver is active or false if not. */ public static boolean isDriverActive( final File directory, final long driverTimeoutMs, final Consumer<String> logger) { final File cncFile = new File(directory, CncFileDescriptor.CNC_FILE); if (cncFile.exists() && cncFile.length() > 0) { logger.accept("INFO: Aeron CnC file exists: " + cncFile); final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "CnC file"); try { return isDriverActive(driverTimeoutMs, logger, cncByteBuffer); } finally { IoUtil.unmap(cncByteBuffer); } } return false; }
/** * Create an empty file, and optionally fill with 0s, and return the {@link FileChannel} * * @param file to create * @param length of the file to create * @param fillWithZeros to the length of the file to force allocation. * @return {@link java.nio.channels.FileChannel} for the file */ public static FileChannel createEmptyFile(final File file, final long length, final boolean fillWithZeros) { ensureDirectoryExists(file.getParentFile(), file.getParent()); FileChannel templateFile = null; try { final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.setLength(length); templateFile = randomAccessFile.getChannel(); if (fillWithZeros) { fill(templateFile, 0, length, (byte)0); } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return templateFile; }
public static File makeTestDirectory() { final File archiveDir = new File(IoUtil.tmpDirName(), "archive-test"); if (archiveDir.exists()) { System.err.println("Warning archive directory exists, deleting: " + archiveDir.getAbsolutePath()); IoUtil.delete(archiveDir, false); } if (!archiveDir.mkdirs()) { throw new IllegalStateException("failed to make archive test directory: " + archiveDir.getAbsolutePath()); } return archiveDir; }
IoUtil.unmap(byteBuffer); IoUtil.delete(directory, false); IoUtil.ensureDirectoryExists(directory, directory.toString());
private static void ensureDirectoryIsRecreated(final Context ctx) { if (ctx.aeronDirectory().isDirectory()) { if (ctx.warnIfDirectoryExists()) { System.err.println("WARNING: " + ctx.aeronDirectory() + " already exists."); } if (!ctx.dirDeleteOnStart()) { final Consumer<String> logger = ctx.warnIfDirectoryExists() ? System.err::println : (s) -> {}; final MappedByteBuffer cncByteBuffer = ctx.mapExistingCncFile(logger); try { if (CommonContext.isDriverActive(ctx.driverTimeoutMs(), logger, cncByteBuffer)) { throw new ActiveDriverException("active driver detected"); } reportExistingErrors(ctx, cncByteBuffer); } finally { IoUtil.unmap(cncByteBuffer); } } ctx.deleteAeronDirectory(); } IoUtil.ensureDirectoryExists(ctx.aeronDirectory(), "aeron"); }
/** * Create a new file, fill with 0s, and return a {@link java.nio.MappedByteBuffer} for the file. * <p> * The file itself will be closed, but the mapping will persist. * * @param location of the file to create and map * @param length of the file to create and map * @return {@link java.nio.MappedByteBuffer} for the file */ public static MappedByteBuffer mapNewFile(final File location, final long length) { return mapNewFile(location, length, true); }
@Test(timeout = 20_000L) public void shouldReadRecordsFromBeforeARestart() throws IOException { indexExampleMessage(); // Fake restarting the gateway final File logFile = logFile(SESSION_ID); IoUtil.ensureDirectoryExists(new File(DEFAULT_LOG_FILE_DIR), DEFAULT_LOG_FILE_DIR); logFile.createNewFile(); try { newReplayIndex(); final int msgCount = query(); verifyMappedFile(SESSION_ID, 1); verifyMessagesRead(1); assertEquals(1, msgCount); } finally { IoUtil.delete(new File(DEFAULT_LOG_FILE_DIR), false); } }
public RawLogFactory( final String dataDirectoryName, final int filePageSize, final boolean checkStorage, final ErrorHandler errorHandler) { this.filePageSize = filePageSize; this.checkStorage = checkStorage; this.errorHandler = errorHandler; final File dataDir = new File(dataDirectoryName); publicationsDir = new File(dataDir, PUBLICATIONS); imagesDir = new File(dataDir, IMAGES); IoUtil.ensureDirectoryExists(publicationsDir, PUBLICATIONS); IoUtil.ensureDirectoryExists(imagesDir, IMAGES); FileStore fs = null; try { if (checkStorage) { fs = Files.getFileStore(dataDir.toPath()); } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } fileStore = fs; }
storageDir = new File(IoUtil.tmpDirName());
public static MappedByteBuffer mapNewFile(final File file, final int size) { final File parentDir = file.getParentFile(); IoUtil.ensureDirectoryExists(parentDir, parentDir.getAbsolutePath()); return IoUtil.mapNewFile(file, size); }
/** * Check that file exists, open file, and return MappedByteBuffer for entire file * <p> * The file itself will be closed, but the mapping will persist. * * @param location of the file to map * @param descriptionLabel to be associated for any exceptions * @return {@link java.nio.MappedByteBuffer} for the file */ public static MappedByteBuffer mapExistingFile(final File location, final String descriptionLabel) { checkFileExists(location, descriptionLabel); MappedByteBuffer mappedByteBuffer = null; try (RandomAccessFile file = new RandomAccessFile(location, "rw"); FileChannel channel = file.getChannel()) { mappedByteBuffer = channel.map(READ_WRITE, 0, channel.size()); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return mappedByteBuffer; }
IoUtil.unmap(byteBuffer); IoUtil.delete(directory, false); IoUtil.ensureDirectoryExists(directory, directory.toString());
private static void ensureDirectoryIsRecreated(final Context ctx) { if (ctx.aeronDirectory().isDirectory()) { if (ctx.warnIfDirectoryExists()) { System.err.println("WARNING: " + ctx.aeronDirectory() + " already exists."); } if (!ctx.dirDeleteOnStart()) { final Consumer<String> logger = ctx.warnIfDirectoryExists() ? System.err::println : (s) -> {}; final MappedByteBuffer cncByteBuffer = ctx.mapExistingCncFile(logger); try { if (CommonContext.isDriverActive(ctx.driverTimeoutMs(), logger, cncByteBuffer)) { throw new ActiveDriverException("active driver detected"); } reportExistingErrors(ctx, cncByteBuffer); } finally { IoUtil.unmap(cncByteBuffer); } } ctx.deleteAeronDirectory(); } IoUtil.ensureDirectoryExists(ctx.aeronDirectory(), "aeron"); }
/** * Map a new loss report in the Aeron directory for a given length. * * @param aeronDirectoryName in which to create the file. * @param reportFileLength for the file. * @return the newly mapped buffer for the file. */ public static MappedByteBuffer mapLossReport(final String aeronDirectoryName, final int reportFileLength) { return mapNewFile(file(aeronDirectoryName), reportFileLength, false); } }
/** * Create an empty file, fill with 0s, and return the {@link FileChannel} * * @param file to create * @param length of the file to create * @return {@link java.nio.channels.FileChannel} for the file */ public static FileChannel createEmptyFile(final File file, final long length) { ensureDirectoryExists(file.getParentFile(), file.getParent()); FileChannel templateFile = null; try { final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.setLength(length); templateFile = randomAccessFile.getChannel(); fill(templateFile, 0, length, (byte)0); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return templateFile; }
@Before public void createDataDir() { IoUtil.ensureDirectoryExists(DATA_DIR, "data"); rawLogFactory = new RawLogFactory( DATA_DIR.getAbsolutePath(), PAGE_SIZE, PERFORM_STORAGE_CHECKS, mock(ErrorHandler.class)); }