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);
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
Aggregations