use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.
the class TestAsyncReaderLock method testReaderLockSessionExpires.
@Test(timeout = 60000)
public void testReaderLockSessionExpires() throws Exception {
String name = runtime.getMethodName();
URI uri = createDLMURI("/" + name);
ensureURICreated(uri);
Namespace ns0 = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
DistributedLogManager dlm0 = ns0.openLog(name);
BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm0.startAsyncLogSegmentNonPartitioned());
writer.write(DLMTestUtil.getLogRecordInstance(1L));
writer.write(DLMTestUtil.getLogRecordInstance(2L));
writer.closeAndComplete();
Namespace ns1 = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
DistributedLogManager dlm1 = ns1.openLog(name);
CompletableFuture<AsyncLogReader> futureReader1 = dlm1.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
AsyncLogReader reader1 = Utils.ioResult(futureReader1);
ZooKeeperClientUtils.expireSession(((BKNamespaceDriver) ns1.getNamespaceDriver()).getWriterZKC(), zkServers, 1000);
// The result of expireSession is somewhat non-deterministic with this lock.
// It may fail with LockingException or it may succesfully reacquire, so for
// the moment rather than make it deterministic we accept either result.
boolean success = false;
try {
Utils.ioResult(reader1.readNext());
success = true;
} catch (LockingException ex) {
}
if (success) {
Utils.ioResult(reader1.readNext());
}
Utils.close(reader1);
dlm0.close();
ns0.close();
dlm1.close();
ns1.close();
}
use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.
the class TestBKDistributedLogManager method testCheckLogExists.
@Test(timeout = 60000)
public void testCheckLogExists() throws Exception {
String name = "distrlog-check-log-exists";
DistributedLogManager dlm = createNewDLM(conf, name);
long txid = 1;
LogWriter writer = dlm.startLogSegmentNonPartitioned();
for (long j = 1; j <= DEFAULT_SEGMENT_SIZE / 2; j++) {
writer.write(DLMTestUtil.getLogRecordInstance(txid++));
}
writer.flush();
writer.commit();
writer.close();
dlm.close();
URI uri = createDLMURI("/" + name);
Namespace namespace = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
assertTrue(namespace.logExists(name));
assertFalse(namespace.logExists("non-existent-log"));
URI nonExistentUri = createDLMURI("/" + "non-existent-ns");
Namespace nonExistentNS = NamespaceBuilder.newBuilder().conf(conf).uri(nonExistentUri).build();
assertFalse(nonExistentNS.logExists(name));
int logCount = 0;
Iterator<String> logIter = namespace.getLogs();
while (logIter.hasNext()) {
String log = logIter.next();
logCount++;
assertEquals(name, log);
}
assertEquals(1, logCount);
namespace.close();
}
use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.
the class TestBKDistributedLogManager method testInvalidStreamFromInvalidZkPath.
@Test(timeout = 60000)
public void testInvalidStreamFromInvalidZkPath() throws Exception {
String baseName = testNames.getMethodName();
String streamName = "\0blah";
URI uri = createDLMURI("/" + baseName);
Namespace namespace = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
DistributedLogManager dlm = null;
AsyncLogWriter writer = null;
try {
dlm = namespace.openLog(streamName);
writer = dlm.startAsyncLogSegmentNonPartitioned();
fail("should have thrown");
} catch (InvalidStreamNameException e) {
} finally {
if (null != writer) {
Utils.close(writer);
}
if (null != dlm) {
dlm.close();
}
namespace.close();
}
}
use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.
the class TestLogSegmentsZK method testCreateLogSegmentOnPrecreatedStream.
/**
* Create Log Segment for an pre-create stream. No max ledger sequence number recorded.
*/
@Test(timeout = 60000)
public void testCreateLogSegmentOnPrecreatedStream() throws Exception {
URI uri = createURI();
String streamName = testName.getMethodName();
DistributedLogConfiguration conf = new DistributedLogConfiguration().setLockTimeout(99999).setOutputBufferSize(0).setImmediateFlushEnabled(true).setEnableLedgerAllocatorPool(true).setLedgerAllocatorPoolName("test");
Namespace namespace = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
namespace.createLog(streamName);
MaxLogSegmentSequenceNo max1 = getMaxLogSegmentSequenceNo(getZooKeeperClient(namespace), uri, streamName, conf);
assertEquals(DistributedLogConstants.UNASSIGNED_LOGSEGMENT_SEQNO, max1.getSequenceNumber());
DistributedLogManager dlm = namespace.openLog(streamName);
final int numSegments = 3;
for (int i = 0; i < numSegments; i++) {
BKSyncLogWriter out = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned();
out.write(DLMTestUtil.getLogRecordInstance(i));
out.closeAndComplete();
}
MaxLogSegmentSequenceNo max2 = getMaxLogSegmentSequenceNo(getZooKeeperClient(namespace), uri, streamName, conf);
assertEquals(3, max2.getSequenceNumber());
dlm.close();
namespace.close();
}
use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.
the class TestLogSegmentsZK method testCreateLogSegmentMissingMaxSequenceNumber.
/**
* Create Log Segment when no max sequence number recorded in /ledgers. e.g. old version.
*/
@Test(timeout = 60000)
public void testCreateLogSegmentMissingMaxSequenceNumber() throws Exception {
URI uri = createURI();
String streamName = testName.getMethodName();
DistributedLogConfiguration conf = new DistributedLogConfiguration().setLockTimeout(99999).setOutputBufferSize(0).setImmediateFlushEnabled(true).setEnableLedgerAllocatorPool(true).setLedgerAllocatorPoolName("test");
Namespace namespace = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
namespace.createLog(streamName);
MaxLogSegmentSequenceNo max1 = getMaxLogSegmentSequenceNo(getZooKeeperClient(namespace), uri, streamName, conf);
assertEquals(DistributedLogConstants.UNASSIGNED_LOGSEGMENT_SEQNO, max1.getSequenceNumber());
DistributedLogManager dlm = namespace.openLog(streamName);
final int numSegments = 3;
for (int i = 0; i < numSegments; i++) {
BKSyncLogWriter out = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned();
out.write(DLMTestUtil.getLogRecordInstance(i));
out.closeAndComplete();
}
MaxLogSegmentSequenceNo max2 = getMaxLogSegmentSequenceNo(getZooKeeperClient(namespace), uri, streamName, conf);
assertEquals(3, max2.getSequenceNumber());
// nuke the max ledger sequence number
updateMaxLogSegmentSequenceNo(getZooKeeperClient(namespace), uri, streamName, conf, new byte[0]);
DistributedLogManager dlm1 = namespace.openLog(streamName);
try {
dlm1.startLogSegmentNonPartitioned();
fail("Should fail with unexpected exceptions");
} catch (UnexpectedException ue) {
// expected
} finally {
dlm1.close();
}
// invalid max ledger sequence number
updateMaxLogSegmentSequenceNo(getZooKeeperClient(namespace), uri, streamName, conf, "invalid-max".getBytes(UTF_8));
DistributedLogManager dlm2 = namespace.openLog(streamName);
try {
dlm2.startLogSegmentNonPartitioned();
fail("Should fail with unexpected exceptions");
} catch (UnexpectedException ue) {
// expected
} finally {
dlm2.close();
}
dlm.close();
namespace.close();
}
Aggregations