use of org.apache.distributedlog.util.SimplePermitLimiter 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.util.SimplePermitLimiter in project bookkeeper by apache.
the class TestAsyncReaderWriter method writeRecordsWithOutstandingWriteLimit.
public void writeRecordsWithOutstandingWriteLimit(int stream, int global, boolean shouldFail) throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(testConf);
confLocal.setOutputBufferSize(0);
confLocal.setImmediateFlushEnabled(true);
confLocal.setPerWriterOutstandingWriteLimit(stream);
confLocal.setOutstandingWriteLimitDarkmode(false);
DistributedLogManager dlm;
if (global > -1) {
dlm = createNewDLM(confLocal, runtime.getMethodName(), new SimplePermitLimiter(false, global, new NullStatsLogger(), true, new FixedValueFeature("", 0)));
} else {
dlm = createNewDLM(confLocal, runtime.getMethodName());
}
BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned());
ArrayList<CompletableFuture<DLSN>> results = new ArrayList<CompletableFuture<DLSN>>(1000);
for (int i = 0; i < 1000; i++) {
results.add(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
}
for (CompletableFuture<DLSN> result : results) {
try {
Utils.ioResult(result);
if (shouldFail) {
fail("should fail due to no outstanding writes permitted");
}
} catch (OverCapacityException ex) {
assertTrue(shouldFail);
}
}
writer.closeAndComplete();
dlm.close();
}
use of org.apache.distributedlog.util.SimplePermitLimiter in project bookkeeper by apache.
the class TestWriteLimiter method testDarkmodeWithDisabledFeature.
@Test(timeout = 60000)
public void testDarkmodeWithDisabledFeature() throws Exception {
SettableFeature feature = new SettableFeature("test", 10000);
SimplePermitLimiter streamLimiter = createPermitLimiter(true, 1, feature);
SimplePermitLimiter globalLimiter = createPermitLimiter(true, Integer.MAX_VALUE, feature);
WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
limiter.acquire();
limiter.acquire();
assertPermits(streamLimiter, 2, globalLimiter, 2);
limiter.release();
limiter.release();
assertPermits(streamLimiter, 0, globalLimiter, 0);
}
use of org.apache.distributedlog.util.SimplePermitLimiter in project bookkeeper by apache.
the class TestWriteLimiter method testSetDisableFeatureAfterAcquireAndBeforeRelease.
@Test(timeout = 60000)
public void testSetDisableFeatureAfterAcquireAndBeforeRelease() throws Exception {
SettableFeature feature = new SettableFeature("test", 0);
SimplePermitLimiter streamLimiter = createPermitLimiter(false, 2, feature);
SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE, feature);
WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
limiter.acquire();
limiter.acquire();
assertPermits(streamLimiter, 2, globalLimiter, 2);
feature.set(10000);
limiter.release();
limiter.release();
assertPermits(streamLimiter, 0, globalLimiter, 0);
}
use of org.apache.distributedlog.util.SimplePermitLimiter in project bookkeeper by apache.
the class TestWriteLimiter method testDarkmodeGlobalUnderStreamOver.
@Test(timeout = 60000)
public void testDarkmodeGlobalUnderStreamOver() throws Exception {
SimplePermitLimiter streamLimiter = createPermitLimiter(true, 1);
SimplePermitLimiter globalLimiter = createPermitLimiter(true, 2);
WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
limiter.acquire();
limiter.acquire();
assertPermits(streamLimiter, 2, globalLimiter, 2);
limiter.release();
limiter.release();
assertPermits(streamLimiter, 0, globalLimiter, 0);
}
Aggregations