Search in sources :

Example 1 with NoWritableLedgerDirException

use of org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException in project bookkeeper by apache.

the class Bookie method setExplicitLac.

public void setExplicitLac(ByteBuf entry, Object ctx, byte[] masterKey) throws IOException, BookieException {
    try {
        long ledgerId = entry.getLong(entry.readerIndex());
        LedgerDescriptor handle = handles.getHandle(ledgerId, masterKey);
        synchronized (handle) {
            handle.setExplicitLac(entry);
        }
    } catch (NoWritableLedgerDirException e) {
        stateManager.transitionToReadOnlyMode();
        throw new IOException(e);
    }
}
Also used : NoWritableLedgerDirException(org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException) IOException(java.io.IOException)

Example 2 with NoWritableLedgerDirException

use of org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException in project bookkeeper by apache.

the class Bookie method addEntry.

/**
 * Add entry to a ledger.
 * @throws BookieException.LedgerFencedException if the ledger is fenced
 */
public void addEntry(ByteBuf entry, boolean ackBeforeSync, WriteCallback cb, Object ctx, byte[] masterKey) throws IOException, BookieException.LedgerFencedException, BookieException {
    long requestNanos = MathUtils.nowInNano();
    boolean success = false;
    int entrySize = 0;
    try {
        LedgerDescriptor handle = getLedgerForEntry(entry, masterKey);
        synchronized (handle) {
            if (handle.isFenced()) {
                throw BookieException.create(BookieException.Code.LedgerFencedException);
            }
            entrySize = entry.readableBytes();
            addEntryInternal(handle, entry, ackBeforeSync, cb, ctx, masterKey);
        }
        success = true;
    } catch (NoWritableLedgerDirException e) {
        stateManager.transitionToReadOnlyMode();
        throw new IOException(e);
    } finally {
        long elapsedNanos = MathUtils.elapsedNanos(requestNanos);
        if (success) {
            addEntryStats.registerSuccessfulEvent(elapsedNanos, TimeUnit.NANOSECONDS);
            addBytesStats.registerSuccessfulValue(entrySize);
        } else {
            addEntryStats.registerFailedEvent(elapsedNanos, TimeUnit.NANOSECONDS);
            addBytesStats.registerFailedValue(entrySize);
        }
        entry.release();
    }
}
Also used : NoWritableLedgerDirException(org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException) IOException(java.io.IOException) Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)

Example 3 with NoWritableLedgerDirException

use of org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException in project bookkeeper by apache.

the class Bookie method recoveryAddEntry.

/**
 * Add entry to a ledger, even if the ledger has previous been fenced. This should only
 * happen in bookie recovery or ledger recovery cases, where entries are being replicates
 * so that they exist on a quorum of bookies. The corresponding client side call for this
 * is not exposed to users.
 */
public void recoveryAddEntry(ByteBuf entry, WriteCallback cb, Object ctx, byte[] masterKey) throws IOException, BookieException {
    long requestNanos = MathUtils.nowInNano();
    boolean success = false;
    int entrySize = 0;
    try {
        LedgerDescriptor handle = getLedgerForEntry(entry, masterKey);
        synchronized (handle) {
            entrySize = entry.readableBytes();
            addEntryInternal(handle, entry, false, /* ackBeforeSync */
            cb, ctx, masterKey);
        }
        success = true;
    } catch (NoWritableLedgerDirException e) {
        stateManager.transitionToReadOnlyMode();
        throw new IOException(e);
    } finally {
        long elapsedNanos = MathUtils.elapsedNanos(requestNanos);
        if (success) {
            recoveryAddEntryStats.registerSuccessfulEvent(elapsedNanos, TimeUnit.NANOSECONDS);
            addBytesStats.registerSuccessfulValue(entrySize);
        } else {
            recoveryAddEntryStats.registerFailedEvent(elapsedNanos, TimeUnit.NANOSECONDS);
            addBytesStats.registerFailedValue(entrySize);
        }
        entry.release();
    }
}
Also used : NoWritableLedgerDirException(org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException) IOException(java.io.IOException) Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)

Example 4 with NoWritableLedgerDirException

use of org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException in project bookkeeper by apache.

the class SyncThread method flush.

private void flush() {
    Checkpoint checkpoint = checkpointSource.newCheckpoint();
    try {
        ledgerStorage.flush();
    } catch (NoWritableLedgerDirException e) {
        log.error("No writeable ledger directories", e);
        dirsListener.allDisksFull();
        return;
    } catch (IOException e) {
        log.error("Exception flushing ledgers", e);
        return;
    }
    if (disableCheckpoint) {
        return;
    }
    log.info("Flush ledger storage at checkpoint {}.", checkpoint);
    try {
        checkpointSource.checkpointComplete(checkpoint, false);
    } catch (IOException e) {
        log.error("Exception marking checkpoint as complete", e);
        dirsListener.allDisksFull();
    }
}
Also used : NoWritableLedgerDirException(org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException) Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint) IOException(java.io.IOException)

Example 5 with NoWritableLedgerDirException

use of org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException in project bookkeeper by apache.

the class TestSyncThread method testSyncThreadDisksFull.

/**
 * Test that if the ledger storage throws
 * a disk full exception, the owner of the sync
 * thread will be notified.
 */
@Test
public void testSyncThreadDisksFull() throws Exception {
    int flushInterval = 100;
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    conf.setFlushInterval(flushInterval);
    CheckpointSource checkpointSource = new DummyCheckpointSource();
    final CountDownLatch diskFullLatch = new CountDownLatch(1);
    LedgerDirsListener listener = new DummyLedgerDirsListener() {

        @Override
        public void allDisksFull() {
            diskFullLatch.countDown();
        }
    };
    LedgerStorage storage = new DummyLedgerStorage() {

        @Override
        public void checkpoint(Checkpoint checkpoint) throws IOException {
            throw new NoWritableLedgerDirException("Disk full error in sync thread");
        }
    };
    final SyncThread t = new SyncThread(conf, listener, storage, checkpointSource);
    t.startCheckpoint(Checkpoint.MAX);
    assertTrue("Should have disk full error", diskFullLatch.await(10, TimeUnit.SECONDS));
    t.shutdown();
}
Also used : NoWritableLedgerDirException(org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException) Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint) LedgerDirsListener(org.apache.bookkeeper.bookie.LedgerDirsManager.LedgerDirsListener) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint) Test(org.junit.Test)

Aggregations

NoWritableLedgerDirException (org.apache.bookkeeper.bookie.LedgerDirsManager.NoWritableLedgerDirException)9 IOException (java.io.IOException)5 File (java.io.File)4 Checkpoint (org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)4 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)4 Test (org.junit.Test)4 LedgerDirsListener (org.apache.bookkeeper.bookie.LedgerDirsManager.LedgerDirsListener)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)2 BookieServer (org.apache.bookkeeper.proto.BookieServer)2 ArrayList (java.util.ArrayList)1 DiskErrorException (org.apache.bookkeeper.util.DiskChecker.DiskErrorException)1 DiskOutOfSpaceException (org.apache.bookkeeper.util.DiskChecker.DiskOutOfSpaceException)1 DiskWarnThresholdException (org.apache.bookkeeper.util.DiskChecker.DiskWarnThresholdException)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1