use of org.apache.distributedlog.injector.AsyncFailureInjector in project bookkeeper by apache.
the class NamespaceBuilder method build.
/**
* Build the namespace.
*
* @return the namespace instance.
* @throws IllegalArgumentException when there is illegal argument provided in the builder
* @throws NullPointerException when there is null argument provided in the builder
* @throws IOException when fail to build the backend
*/
public Namespace build() throws IllegalArgumentException, NullPointerException, IOException {
// Check arguments
checkNotNull(_conf, "No DistributedLog Configuration.");
checkNotNull(_uri, "No DistributedLog URI");
// validate the configuration
_conf.validate();
if (null == _dynConf) {
_dynConf = ConfUtils.getConstDynConf(_conf);
}
// retrieve the namespace driver
NamespaceDriver driver = NamespaceDriverManager.getDriver(_uri);
URI normalizedUri = DLUtils.normalizeURI(_uri);
// build the feature provider
FeatureProvider featureProvider;
if (null == _featureProvider) {
featureProvider = new SettableFeatureProvider("", 0);
logger.info("No feature provider is set. All features are disabled now.");
} else {
featureProvider = _featureProvider;
}
// build the failure injector
AsyncFailureInjector failureInjector = AsyncRandomFailureInjector.newBuilder().injectDelays(_conf.getEIInjectReadAheadDelay(), _conf.getEIInjectReadAheadDelayPercent(), _conf.getEIInjectMaxReadAheadDelayMs()).injectErrors(false, 10).injectStops(_conf.getEIInjectReadAheadStall(), 10).injectCorruption(_conf.getEIInjectReadAheadBrokenEntries()).build();
// normalize the per log stats logger
StatsLogger perLogStatsLogger = normalizePerLogStatsLogger(_statsLogger, _perLogStatsLogger, _conf);
// build the scheduler
OrderedScheduler scheduler = OrderedScheduler.newSchedulerBuilder().name("DLM-" + normalizedUri.getPath()).numThreads(_conf.getNumWorkerThreads()).build();
// initialize the namespace driver
driver.initialize(_conf, _dynConf, normalizedUri, scheduler, featureProvider, failureInjector, _statsLogger, perLogStatsLogger, DLUtils.normalizeClientId(_clientId), _regionId);
// initialize the write limiter
PermitLimiter writeLimiter;
if (_conf.getGlobalOutstandingWriteLimit() < 0) {
writeLimiter = PermitLimiter.NULL_PERMIT_LIMITER;
} else {
Feature disableWriteLimitFeature = featureProvider.getFeature(CoreFeatureKeys.DISABLE_WRITE_LIMIT.name().toLowerCase());
writeLimiter = new SimplePermitLimiter(_conf.getOutstandingWriteLimitDarkmode(), _conf.getGlobalOutstandingWriteLimit(), _statsLogger.scope("writeLimiter"), true, /* singleton */
disableWriteLimitFeature);
}
return new BKDistributedLogNamespace(_conf, normalizedUri, driver, scheduler, featureProvider, writeLimiter, failureInjector, _statsLogger, perLogStatsLogger, DLUtils.normalizeClientId(_clientId), _regionId);
}
use of org.apache.distributedlog.injector.AsyncFailureInjector in project bookkeeper by apache.
the class TestDistributedLogBase method createNewDLM.
public BKDistributedLogManager createNewDLM(DistributedLogConfiguration conf, String name, PermitLimiter writeLimiter) throws Exception {
URI uri = createDLMURI("/" + name);
ensureURICreated(uri);
final Namespace namespace = NamespaceBuilder.newBuilder().uri(uri).conf(conf).build();
final OrderedScheduler scheduler = OrderedScheduler.newSchedulerBuilder().numThreads(1).name("test-scheduler").build();
AsyncCloseable resourcesCloseable = new AsyncCloseable() {
@Override
public CompletableFuture<Void> asyncClose() {
LOG.info("Shutting down the scheduler");
SchedulerUtils.shutdownScheduler(scheduler, 1, TimeUnit.SECONDS);
LOG.info("Shut down the scheduler");
LOG.info("Closing the namespace");
namespace.close();
LOG.info("Closed the namespace");
return FutureUtils.Void();
}
};
AsyncFailureInjector failureInjector = AsyncRandomFailureInjector.newBuilder().injectDelays(conf.getEIInjectReadAheadDelay(), conf.getEIInjectReadAheadDelayPercent(), conf.getEIInjectMaxReadAheadDelayMs()).injectErrors(false, 10).injectStops(conf.getEIInjectReadAheadStall(), 10).injectCorruption(conf.getEIInjectReadAheadBrokenEntries()).build();
return new BKDistributedLogManager(name, conf, ConfUtils.getConstDynConf(conf), uri, namespace.getNamespaceDriver(), new LogSegmentMetadataCache(conf, Ticker.systemTicker()), scheduler, DistributedLogConstants.UNKNOWN_CLIENT_ID, DistributedLogConstants.LOCAL_REGION_ID, writeLimiter, new SettableFeatureProvider("", 0), failureInjector, NullStatsLogger.INSTANCE, NullStatsLogger.INSTANCE, Optional.of(resourcesCloseable));
}
Aggregations