use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.
the class DLMetadata method create.
public void create(URI uri) throws IOException {
DistributedLogConfiguration conf = new DistributedLogConfiguration();
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
byte[] data = serialize();
try {
Utils.zkCreateFullPathOptimistic(zkc, uri.getPath(), data, zkc.getDefaultACL(), CreateMode.PERSISTENT);
} catch (KeeperException ke) {
throw new ZKException("Encountered zookeeper exception on creating dl metadata", ke);
} finally {
zkc.close();
}
}
use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.
the class DLMetadata method update.
public void update(URI uri) throws IOException {
DistributedLogConfiguration conf = new DistributedLogConfiguration();
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
byte[] data = serialize();
try {
zkc.get().setData(uri.getPath(), data, -1);
} catch (KeeperException e) {
throw new IOException("Fail to update dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted when updating dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
} finally {
zkc.close();
}
}
use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.
the class DLMetadata method unbind.
public static void unbind(URI uri) throws IOException {
DistributedLogConfiguration conf = new DistributedLogConfiguration();
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
byte[] data = new byte[0];
try {
zkc.get().setData(uri.getPath(), data, -1);
} catch (KeeperException ke) {
throw new IOException("Fail to unbound dl metadata on uri " + uri, ke);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted when unbinding dl metadata on uri " + uri, ie);
} finally {
zkc.close();
}
}
use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.
the class AbstractFeatureProvider method getFeatureProvider.
public static FeatureProvider getFeatureProvider(String rootScope, DistributedLogConfiguration conf, StatsLogger statsLogger) throws IOException {
Class<? extends FeatureProvider> featureProviderClass;
try {
featureProviderClass = conf.getFeatureProviderClass();
} catch (ConfigurationException e) {
throw new IOException("Can't initialize the feature provider : ", e);
}
// create feature provider
Constructor<? extends FeatureProvider> constructor;
try {
constructor = featureProviderClass.getDeclaredConstructor(String.class, DistributedLogConfiguration.class, StatsLogger.class);
} catch (NoSuchMethodException e) {
throw new IOException("No constructor found for feature provider class " + featureProviderClass + " : ", e);
}
try {
return constructor.newInstance(rootScope, conf, statsLogger);
} catch (InstantiationException e) {
throw new IOException("Failed to instantiate feature provider : ", e);
} catch (IllegalAccessException e) {
throw new IOException("Encountered illegal access when instantiating feature provider : ", e);
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
if (targetException instanceof IOException) {
throw (IOException) targetException;
} else {
throw new IOException("Encountered invocation target" + " exception while instantiating feature provider : ", e);
}
}
}
use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.
the class TestBKLogSegmentEntryReader method testMaxPrefetchEntriesSmallBatch.
@Test(timeout = 60000)
public void testMaxPrefetchEntriesSmallBatch() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setOutputBufferSize(0);
confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
confLocal.setImmediateFlushEnabled(false);
confLocal.setNumPrefetchEntriesPerLogSegment(2);
confLocal.setMaxPrefetchEntriesPerLogSegment(10);
DistributedLogManager dlm = createNewDLM(confLocal, runtime.getMethodName());
generateCompletedLogSegments(dlm, confLocal, 1, 20);
List<LogSegmentMetadata> segments = dlm.getLogSegments();
assertEquals(segments.size() + " log segments found, expected to be only one", 1, segments.size());
BKLogSegmentEntryReader reader = createEntryReader(segments.get(0), 0, confLocal);
reader.start();
// wait for the read ahead entries to become available
while (reader.readAheadEntries.size() < 10) {
TimeUnit.MILLISECONDS.sleep(10);
}
long txId = 1L;
long entryId = 0L;
assertEquals(10, reader.readAheadEntries.size());
assertEquals(10, reader.getNextEntryId());
assertFalse(reader.hasCaughtUpOnInprogress());
// read first entry
Entry.Reader entryReader = Utils.ioResult(reader.readNext(1)).get(0);
LogRecordWithDLSN record = entryReader.nextRecord();
while (null != record) {
if (!record.isControl()) {
DLMTestUtil.verifyLogRecord(record);
assertEquals(txId, record.getTransactionId());
++txId;
}
DLSN dlsn = record.getDlsn();
assertEquals(1L, dlsn.getLogSegmentSequenceNo());
assertEquals(entryId, dlsn.getEntryId());
record = entryReader.nextRecord();
}
++entryId;
assertEquals(2L, txId);
// wait for the read ahead entries to become 10 again
while (reader.readAheadEntries.size() < 10) {
TimeUnit.MILLISECONDS.sleep(10);
}
assertEquals(10, reader.readAheadEntries.size());
assertEquals(11, reader.getNextEntryId());
assertFalse(reader.hasCaughtUpOnInprogress());
Utils.close(reader);
}
Aggregations