use of io.pravega.segmentstore.storage.DurableDataLogException in project pravega by pravega.
the class BookKeeperLogTests method testAppendPermanentFailures.
/**
* Tests the ability to retry writes when Bookies fail.
*/
@Test
public void testAppendPermanentFailures() throws Exception {
try (DurableDataLog log = createDurableDataLog()) {
log.initialize(TIMEOUT);
List<CompletableFuture<LogAddress>> appendFutures = new ArrayList<>();
try {
// Suspend a bookie (this will trigger write errors).
stopFirstBookie();
// Issue appends in parallel.
int writeCount = getWriteCount();
for (int i = 0; i < writeCount; i++) {
appendFutures.add(log.append(new ByteArraySegment(getWriteData()), TIMEOUT));
}
// Verify that all writes failed or got cancelled.
AtomicBoolean cancellationEncountered = new AtomicBoolean(false);
for (val f : appendFutures) {
AssertExtensions.assertThrows("Write did not fail correctly.", () -> f.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS), ex -> {
cancellationEncountered.set(cancellationEncountered.get() || ex instanceof CancellationException);
if (cancellationEncountered.get()) {
return ex instanceof CancellationException;
} else {
return ex instanceof RetriesExhaustedException || ex instanceof DurableDataLogException;
}
});
}
} finally {
// Don't forget to resume the bookie, but only AFTER we are done testing.
restartFirstBookie();
}
}
}
use of io.pravega.segmentstore.storage.DurableDataLogException in project pravega by pravega.
the class BookKeeperCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
protected Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient());
return new Context(serviceConfig, bkConfig, zkClient, factory, bkAdmin);
}
use of io.pravega.segmentstore.storage.DurableDataLogException in project pravega by pravega.
the class ContainerCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
@Override
protected Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val containerConfig = getCommandArgs().getState().getConfigBuilder().build().getConfig(ContainerConfig::builder);
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient());
return new Context(serviceConfig, containerConfig, bkConfig, zkClient, factory, bkAdmin);
}
Aggregations