Search in sources :

Example 16 with DiskChecker

use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.

the class CompactionTest method testWhenNoLogsToCompact.

/**
 * Test that compaction should execute silently when there is no entry logs
 * to compact. {@see https://issues.apache.org/jira/browse/BOOKKEEPER-700}
 */
@Test
public void testWhenNoLogsToCompact() throws Exception {
    // I dont want the test infrastructure
    tearDown();
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    File tmpDir = createTempDir("bkTest", ".dir");
    File curDir = Bookie.getCurrentDirectory(tmpDir);
    Bookie.checkDirectoryStructure(curDir);
    conf.setLedgerDirNames(new String[] { tmpDir.toString() });
    LedgerDirsManager dirs = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));
    final Set<Long> ledgers = Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
    LedgerManager manager = getLedgerManager(ledgers);
    CheckpointSource checkpointSource = new CheckpointSource() {

        @Override
        public Checkpoint newCheckpoint() {
            return null;
        }

        @Override
        public void checkpointComplete(Checkpoint checkpoint, boolean compact) throws IOException {
        }
    };
    InterleavedLedgerStorage storage = new InterleavedLedgerStorage();
    storage.initialize(conf, manager, dirs, dirs, null, checkpointSource, Checkpointer.NULL, NullStatsLogger.INSTANCE);
    double threshold = 0.1;
    // shouldn't throw exception
    storage.gcThread.doCompactEntryLogs(threshold);
}
Also used : LedgerManager(org.apache.bookkeeper.meta.LedgerManager) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) DiskChecker(org.apache.bookkeeper.util.DiskChecker) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) File(java.io.File) Test(org.junit.Test)

Example 17 with DiskChecker

use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.

the class CreateNewLogTest method testCreateNewLog.

/**
 * Checks if new log file id is verified against all directories.
 *
 * {@link https://issues.apache.org/jira/browse/BOOKKEEPER-465}
 *
 * @throws Exception
 */
@Test
public void testCreateNewLog() throws Exception {
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    // Creating a new configuration with a number of
    // ledger directories.
    conf.setLedgerDirNames(ledgerDirs);
    LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));
    // Extracted from createNewLog()
    String logFileName = Long.toHexString(1) + ".log";
    File dir = ledgerDirsManager.pickRandomWritableDir();
    LOG.info("Picked this directory: " + dir);
    File newLogFile = new File(dir, logFileName);
    newLogFile.createNewFile();
    EntryLogger el = new EntryLogger(conf, ledgerDirsManager);
    // Calls createNewLog, and with the number of directories we
    // are using, if it picks one at random it will fail.
    el.createNewLog();
    LOG.info("This is the current log id: " + el.getCurrentLogId());
    assertTrue("Wrong log id", el.getCurrentLogId() > 1);
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) DiskChecker(org.apache.bookkeeper.util.DiskChecker) File(java.io.File) Test(org.junit.Test)

Example 18 with DiskChecker

use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.

the class CreateNewLogTest method testCreateNewLogWithNoWritableLedgerDirs.

@Test
public void testCreateNewLogWithNoWritableLedgerDirs() throws Exception {
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    // Creating a new configuration with a number of ledger directories.
    conf.setLedgerDirNames(ledgerDirs);
    conf.setIsForceGCAllowWhenNoSpace(true);
    LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));
    // Extracted from createNewLog()
    String logFileName = Long.toHexString(1) + ".log";
    File dir = ledgerDirsManager.pickRandomWritableDir();
    LOG.info("Picked this directory: " + dir);
    File newLogFile = new File(dir, logFileName);
    newLogFile.createNewFile();
    // Now let us move all dirs to filled dirs
    List<File> wDirs = ledgerDirsManager.getWritableLedgerDirs();
    for (File tdir : wDirs) {
        ledgerDirsManager.addToFilledDirs(tdir);
    }
    EntryLogger el = new EntryLogger(conf, ledgerDirsManager);
    // Calls createNewLog, and with the number of directories we
    // are using, if it picks one at random it will fail.
    el.createNewLog();
    LOG.info("This is the current log id: " + el.getCurrentLogId());
    assertTrue("Wrong log id", el.getCurrentLogId() > 1);
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) DiskChecker(org.apache.bookkeeper.util.DiskChecker) File(java.io.File) Test(org.junit.Test)

Example 19 with DiskChecker

use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.

the class EntryLogTest method testEntryLoggerShouldThrowFNFEIfDirectoriesDoesNotExist.

@Test
public /**
 * Test that EntryLogger Should fail with FNFE, if entry logger directories does not exist.
 */
void testEntryLoggerShouldThrowFNFEIfDirectoriesDoesNotExist() throws Exception {
    File tmpDir = createTempDir("bkTest", ".dir");
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    conf.setLedgerDirNames(new String[] { tmpDir.toString() });
    EntryLogger entryLogger = null;
    try {
        entryLogger = new EntryLogger(conf, new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold())));
        fail("Expecting FileNotFoundException");
    } catch (FileNotFoundException e) {
        assertEquals("Entry log directory does not exist", e.getLocalizedMessage());
    } finally {
        if (entryLogger != null) {
            entryLogger.shutdown();
        }
    }
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) FileNotFoundException(java.io.FileNotFoundException) DiskChecker(org.apache.bookkeeper.util.DiskChecker) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 20 with DiskChecker

use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.

the class TestLedgerDirsManager method setUp.

@Before
public void setUp() throws Exception {
    PowerMockito.mockStatic(Executors.class);
    File tmpDir = createTempDir("bkTest", ".dir");
    curDir = Bookie.getCurrentDirectory(tmpDir);
    Bookie.checkDirectoryStructure(curDir);
    conf = TestBKConfiguration.newServerConfiguration();
    conf.setLedgerDirNames(new String[] { tmpDir.toString() });
    conf.setDiskLowWaterMarkUsageThreshold(conf.getDiskUsageThreshold());
    conf.setDiskCheckInterval(diskCheckInterval);
    conf.setIsForceGCAllowWhenNoSpace(true);
    executor = PowerMockito.mock(ScheduledExecutorService.class);
    executorController = new MockExecutorController().controlScheduleAtFixedRate(executor, 10);
    PowerMockito.when(Executors.newSingleThreadScheduledExecutor(any())).thenReturn(executor);
    mockDiskChecker = new MockDiskChecker(threshold, warnThreshold);
    statsProvider = new TestStatsProvider();
    statsLogger = statsProvider.getStatsLogger("test");
    dirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()), statsLogger);
    ledgerMonitor = new LedgerDirsMonitor(conf, mockDiskChecker, dirsManager);
    ledgerMonitor.init();
}
Also used : TestStatsProvider(org.apache.bookkeeper.test.TestStatsProvider) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) DiskChecker(org.apache.bookkeeper.util.DiskChecker) File(java.io.File) Before(org.junit.Before)

Aggregations

DiskChecker (org.apache.bookkeeper.util.DiskChecker)21 File (java.io.File)17 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)12 Test (org.junit.Test)11 LedgerDirsManager (org.apache.bookkeeper.bookie.LedgerDirsManager)7 ByteBuf (io.netty.buffer.ByteBuf)4 IOException (java.io.IOException)4 Checkpoint (org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)4 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 BookieShell (org.apache.bookkeeper.bookie.BookieShell)3 Before (org.junit.Before)3 InterleavedLedgerStorage (org.apache.bookkeeper.bookie.InterleavedLedgerStorage)2 Journal (org.apache.bookkeeper.bookie.Journal)2 NoWritableLedgerDirException (org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException)2 LogMark (org.apache.bookkeeper.bookie.LogMark)2 TestStatsProvider (org.apache.bookkeeper.test.TestStatsProvider)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ByteString (com.google.protobuf.ByteString)1 FileNotFoundException (java.io.FileNotFoundException)1