use of com.twitter.distributedlog.DistributedLogManager in project distributedlog by twitter.
the class TestDistributedLogTool method setupDefaults.
@BeforeClass
public static void setupDefaults() throws Exception {
defaultUri = DLMTestUtil.createDLMURI(zkPort, defaultPath);
DistributedLogManager dlm = DLMTestUtil.createNewDLM("DefaultStream", conf, defaultUri);
bindStream(defaultUri, defaultLedgerPath, defaultHost);
DLMTestUtil.generateCompletedLogSegments(dlm, conf, 3, 8192);
dlm.close();
}
use of com.twitter.distributedlog.DistributedLogManager in project distributedlog by twitter.
the class TestDistributedLogTool method testToolTruncateStream.
@Test(timeout = 60000)
public void testToolTruncateStream() throws Exception {
DistributedLogManager dlm = DLMTestUtil.createNewDLM("testToolTruncateStream", conf, defaultUri);
DLMTestUtil.generateCompletedLogSegments(dlm, conf, 3, 1000);
DLSN dlsn = new DLSN(2, 1, 0);
TruncateStreamCommand cmd = new TruncateStreamCommand();
cmd.setDlsn(dlsn);
cmd.setUri(defaultUri);
cmd.setStreamName("testToolTruncateStream");
cmd.setForce(true);
assertEquals(0, cmd.runCmd());
LogReader reader = dlm.getInputStream(0);
LogRecordWithDLSN record = reader.readNext(false);
assertEquals(dlsn, record.getDlsn());
reader.close();
dlm.close();
}
use of com.twitter.distributedlog.DistributedLogManager in project distributedlog by twitter.
the class TestDLCK method testCheckAndRepairDLNamespace.
@Test(timeout = 60000)
@SuppressWarnings("deprecation")
public void testCheckAndRepairDLNamespace() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.loadConf(conf);
confLocal.setImmediateFlushEnabled(true);
confLocal.setOutputBufferSize(0);
confLocal.setLogSegmentSequenceNumberValidationEnabled(false);
URI uri = createDLMURI("/check-and-repair-dl-namespace");
zkc.get().create(uri.getPath(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
com.twitter.distributedlog.DistributedLogManagerFactory factory = new com.twitter.distributedlog.DistributedLogManagerFactory(confLocal, uri);
ExecutorService executorService = Executors.newCachedThreadPool();
String streamName = "check-and-repair-dl-namespace";
// Create completed log segments
DistributedLogManager dlm = factory.createDistributedLogManagerWithSharedClients(streamName);
DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 1L, 1L, 10, false);
DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 2L, 11L, 10, true);
DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 3L, 21L, 10, false);
DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 4L, 31L, 10, true);
// dryrun
BookKeeperClient bkc = getBookKeeperClient(factory);
DistributedLogAdmin.checkAndRepairDLNamespace(uri, factory, new DryrunLogSegmentMetadataStoreUpdater(confLocal, getLogSegmentMetadataStore(factory)), executorService, bkc, confLocal.getBKDigestPW(), false, false);
Map<Long, LogSegmentMetadata> segments = getLogSegments(dlm);
LOG.info("segments after drynrun {}", segments);
verifyLogSegment(segments, new DLSN(1L, 18L, 0L), 1L, 10, 10L);
verifyLogSegment(segments, new DLSN(2L, 16L, 0L), 2L, 9, 19L);
verifyLogSegment(segments, new DLSN(3L, 18L, 0L), 3L, 10, 30L);
verifyLogSegment(segments, new DLSN(4L, 16L, 0L), 4L, 9, 39L);
// check and repair
bkc = getBookKeeperClient(factory);
DistributedLogAdmin.checkAndRepairDLNamespace(uri, factory, LogSegmentMetadataStoreUpdater.createMetadataUpdater(confLocal, getLogSegmentMetadataStore(factory)), executorService, bkc, confLocal.getBKDigestPW(), false, false);
segments = getLogSegments(dlm);
LOG.info("segments after repair {}", segments);
verifyLogSegment(segments, new DLSN(1L, 18L, 0L), 1L, 10, 10L);
verifyLogSegment(segments, new DLSN(2L, 18L, 0L), 2L, 10, 20L);
verifyLogSegment(segments, new DLSN(3L, 18L, 0L), 3L, 10, 30L);
verifyLogSegment(segments, new DLSN(4L, 18L, 0L), 4L, 10, 40L);
dlm.close();
SchedulerUtils.shutdownScheduler(executorService, 5, TimeUnit.MINUTES);
factory.close();
}
use of com.twitter.distributedlog.DistributedLogManager in project distributedlog by twitter.
the class TestDistributedLogAdmin method testChangeSequenceNumber.
/**
* {@link https://issues.apache.org/jira/browse/DL-44}
*/
@DistributedLogAnnotations.FlakyTest
@Ignore
@Test(timeout = 60000)
@SuppressWarnings("deprecation")
public void testChangeSequenceNumber() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setLogSegmentSequenceNumberValidationEnabled(false);
URI uri = createDLMURI("/change-sequence-number");
zooKeeperClient.get().create(uri.getPath(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
com.twitter.distributedlog.DistributedLogManagerFactory factory = new com.twitter.distributedlog.DistributedLogManagerFactory(confLocal, uri);
String streamName = "change-sequence-number";
// create completed log segments
DistributedLogManager dlm = factory.createDistributedLogManagerWithSharedClients(streamName);
DLMTestUtil.generateCompletedLogSegments(dlm, confLocal, 4, 10);
DLMTestUtil.injectLogSegmentWithGivenLogSegmentSeqNo(dlm, confLocal, 5, 41, false, 10, true);
dlm.close();
// create a reader
DistributedLogManager readDLM = factory.createDistributedLogManagerWithSharedClients(streamName);
AsyncLogReader reader = readDLM.getAsyncLogReader(DLSN.InitialDLSN);
// read the records
long expectedTxId = 1L;
for (int i = 0; i < 4 * 10; i++) {
LogRecord record = Await.result(reader.readNext());
assertNotNull(record);
DLMTestUtil.verifyLogRecord(record);
assertEquals(expectedTxId, record.getTransactionId());
expectedTxId++;
}
dlm = factory.createDistributedLogManagerWithSharedClients(streamName);
DLMTestUtil.injectLogSegmentWithGivenLogSegmentSeqNo(dlm, confLocal, 3L, 5 * 10 + 1, true, 10, false);
// Wait for reader to be aware of new log segments
TimeUnit.SECONDS.sleep(2);
DLSN dlsn = readDLM.getLastDLSN();
assertTrue(dlsn.compareTo(new DLSN(5, Long.MIN_VALUE, Long.MIN_VALUE)) < 0);
assertTrue(dlsn.compareTo(new DLSN(4, -1, Long.MIN_VALUE)) > 0);
// there isn't records should be read
Future<LogRecordWithDLSN> readFuture = reader.readNext();
try {
Await.result(readFuture, Duration.fromMilliseconds(1000));
fail("Should fail reading next when there is a corrupted log segment");
} catch (TimeoutException te) {
// expected
}
// Dryrun
DistributedLogAdmin.fixInprogressSegmentWithLowerSequenceNumber(factory, new DryrunLogSegmentMetadataStoreUpdater(confLocal, getLogSegmentMetadataStore(factory)), streamName, false, false);
// Wait for reader to be aware of new log segments
TimeUnit.SECONDS.sleep(2);
dlsn = readDLM.getLastDLSN();
assertTrue(dlsn.compareTo(new DLSN(5, Long.MIN_VALUE, Long.MIN_VALUE)) < 0);
assertTrue(dlsn.compareTo(new DLSN(4, -1, Long.MIN_VALUE)) > 0);
// there isn't records should be read
try {
Await.result(readFuture, Duration.fromMilliseconds(1000));
fail("Should fail reading next when there is a corrupted log segment");
} catch (TimeoutException te) {
// expected
}
// Actual run
DistributedLogAdmin.fixInprogressSegmentWithLowerSequenceNumber(factory, LogSegmentMetadataStoreUpdater.createMetadataUpdater(confLocal, getLogSegmentMetadataStore(factory)), streamName, false, false);
// Wait for reader to be aware of new log segments
TimeUnit.SECONDS.sleep(2);
expectedTxId = 51L;
LogRecord record = Await.result(readFuture);
assertNotNull(record);
DLMTestUtil.verifyLogRecord(record);
assertEquals(expectedTxId, record.getTransactionId());
expectedTxId++;
for (int i = 1; i < 10; i++) {
record = Await.result(reader.readNext());
assertNotNull(record);
DLMTestUtil.verifyLogRecord(record);
assertEquals(expectedTxId, record.getTransactionId());
expectedTxId++;
}
dlsn = readDLM.getLastDLSN();
LOG.info("LastDLSN after fix inprogress segment : {}", dlsn);
assertTrue(dlsn.compareTo(new DLSN(7, Long.MIN_VALUE, Long.MIN_VALUE)) < 0);
assertTrue(dlsn.compareTo(new DLSN(6, -1, Long.MIN_VALUE)) > 0);
Utils.close(reader);
readDLM.close();
dlm.close();
factory.close();
}
use of com.twitter.distributedlog.DistributedLogManager in project distributedlog by twitter.
the class TestZKLogMetadataForWriter method testCreateLogMetadataWithCustomMetadata.
@Test(timeout = 60000)
public void testCreateLogMetadataWithCustomMetadata() throws Exception {
URI uri = DLMTestUtil.createDLMURI(zkPort, "");
String logName = testName.getMethodName();
String logIdentifier = "<default>";
List<String> pathsToDelete = Lists.newArrayList();
DLMetadata.create(new BKDLConfig(zkServers, "/ledgers")).update(uri);
DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.newBuilder().conf(new DistributedLogConfiguration()).uri(uri).build();
DistributedLogManager dlm = namespace.openLog(logName);
dlm.createOrUpdateMetadata(logName.getBytes("UTF-8"));
dlm.close();
testCreateLogMetadataWithMissingPaths(uri, logName, logIdentifier, pathsToDelete, true, false);
}
Aggregations