use of com.twitter.distributedlog.LogSegmentMetadata in project distributedlog by twitter.
the class TestLogSegmentCache method testGapDetectionOnLogSegmentsWithoutLogSegmentSequenceNumber.
@Test(timeout = 60000)
public void testGapDetectionOnLogSegmentsWithoutLogSegmentSequenceNumber() throws Exception {
LogSegmentCache cache = new LogSegmentCache("test-gap-detection");
LogSegmentMetadata segment1 = DLMTestUtil.completedLogSegment("/segment-1", 1L, 1L, 100L, 100, 1L, 99L, 0L).mutator().setVersion(LogSegmentMetadata.LogSegmentMetadataVersion.VERSION_V1_ORIGINAL).build();
cache.add(DLMTestUtil.completedLedgerZNodeNameWithLogSegmentSequenceNumber(1L), segment1);
LogSegmentMetadata segment3 = DLMTestUtil.completedLogSegment("/segment-3", 3L, 3L, 300L, 100, 3L, 99L, 0L).mutator().setVersion(LogSegmentMetadata.LogSegmentMetadataVersion.VERSION_V2_LEDGER_SEQNO).build();
cache.add(DLMTestUtil.completedLedgerZNodeNameWithLogSegmentSequenceNumber(3L), segment3);
List<LogSegmentMetadata> expectedList = Lists.asList(segment1, new LogSegmentMetadata[] { segment3 });
List<LogSegmentMetadata> resultList = cache.getLogSegments(LogSegmentMetadata.COMPARATOR);
assertEquals(expectedList, resultList);
}
use of com.twitter.distributedlog.LogSegmentMetadata in project distributedlog by twitter.
the class TestLogSegmentCache method testBasicOperations.
@Test(timeout = 60000)
public void testBasicOperations() {
LogSegmentMetadata metadata = DLMTestUtil.completedLogSegment("/segment1", 1L, 1L, 100L, 100, 1L, 99L, 0L);
String name = DLMTestUtil.completedLedgerZNodeNameWithLogSegmentSequenceNumber(1L);
LogSegmentCache cache = new LogSegmentCache("test-basic-operations");
assertNull("No log segment " + name + " should be cached", cache.get(name));
cache.add(name, metadata);
LogSegmentMetadata metadataRetrieved = cache.get(name);
assertNotNull("log segment " + name + " should be cached", metadataRetrieved);
assertEquals("Wrong log segment metadata returned for " + name, metadata, metadataRetrieved);
LogSegmentMetadata metadataRemoved = cache.remove(name);
assertNull("log segment " + name + " should be removed from cache", cache.get(name));
assertEquals("Wrong log segment metadata removed for " + name, metadata, metadataRemoved);
assertNull("No log segment " + name + " to be removed", cache.remove(name));
}
use of com.twitter.distributedlog.LogSegmentMetadata in project distributedlog by twitter.
the class TestLogSegmentMetadataStoreUpdater method testChangeSequenceNumber.
@Test(timeout = 60000)
public void testChangeSequenceNumber() throws Exception {
String ledgerPath = "/testChangeSequenceNumber";
zkc.get().create(ledgerPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Map<Long, LogSegmentMetadata> completedLogSegments = new HashMap<Long, LogSegmentMetadata>();
// Create 5 completed log segments
for (int i = 1; i <= 5; i++) {
LogSegmentMetadata segment = DLMTestUtil.completedLogSegment(ledgerPath, i, (i - 1) * 100, i * 100 - 1, 100, i, 100, 0);
completedLogSegments.put(((long) i), segment);
LOG.info("Create completed segment {} : {}", segment.getZkPath(), segment);
segment.write(zkc);
}
// Create a smaller inprogress log segment
long inprogressSeqNo = 3;
LogSegmentMetadata segment = DLMTestUtil.inprogressLogSegment(ledgerPath, inprogressSeqNo, 5 * 100, inprogressSeqNo);
LOG.info("Create inprogress segment {} : {}", segment.getZkPath(), segment);
segment.write(zkc);
Map<Long, LogSegmentMetadata> segmentList = readLogSegments(ledgerPath);
assertEquals(5, segmentList.size());
// Dryrun
MetadataUpdater dryrunUpdater = new DryrunLogSegmentMetadataStoreUpdater(conf, metadataStore);
FutureUtils.result(dryrunUpdater.changeSequenceNumber(segment, 6L));
segmentList = readLogSegments(ledgerPath);
assertEquals(5, segmentList.size());
// Fix the inprogress log segments
MetadataUpdater updater = LogSegmentMetadataStoreUpdater.createMetadataUpdater(conf, metadataStore);
FutureUtils.result(updater.changeSequenceNumber(segment, 6L));
segmentList = readLogSegments(ledgerPath);
assertEquals(6, segmentList.size());
// check first 5 log segments
for (int i = 1; i <= 5; i++) {
LogSegmentMetadata s = segmentList.get((long) i);
assertNotNull(s);
assertEquals(completedLogSegments.get((long) i), s);
}
// get log segment 6
LogSegmentMetadata segmentChanged = segmentList.get(6L);
assertNotNull(segmentChanged);
assertEquals(6L, segmentChanged.getLogSegmentSequenceNumber());
assertTrue(segmentChanged.isInProgress());
assertEquals(5 * 100, segmentChanged.getFirstTxId());
assertEquals(3L, segmentChanged.getLedgerId());
}
use of com.twitter.distributedlog.LogSegmentMetadata in project distributedlog by twitter.
the class TestLogSegmentMetadataStoreUpdater method testChangeTruncationStatus.
@Test
public void testChangeTruncationStatus() throws Exception {
String ledgerPath = "/ledgers2";
zkc.get().create(ledgerPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Map<Long, LogSegmentMetadata> completedLogSegments = new HashMap<Long, LogSegmentMetadata>();
// Create 5 completed log segments
for (int i = 1; i <= 5; i++) {
LogSegmentMetadata segment = DLMTestUtil.completedLogSegment(ledgerPath, i, (i - 1) * 100, i * 100 - 1, 100, i, 100, 0);
completedLogSegments.put(((long) i), segment);
LOG.info("Create completed segment {} : {}", segment.getZkPath(), segment);
segment.write(zkc);
}
Map<Long, LogSegmentMetadata> segmentList = readLogSegments(ledgerPath);
assertEquals(5, segmentList.size());
long segmentToModify = 1L;
// Dryrun
MetadataUpdater dryrunUpdater = new DryrunLogSegmentMetadataStoreUpdater(conf, metadataStore);
FutureUtils.result(dryrunUpdater.setLogSegmentTruncated(segmentList.get(segmentToModify)));
segmentList = readLogSegments(ledgerPath);
assertEquals(false, segmentList.get(segmentToModify).isTruncated());
// change truncation for the 1st log segment
MetadataUpdater updater = LogSegmentMetadataStoreUpdater.createMetadataUpdater(conf, metadataStore);
FutureUtils.result(updater.setLogSegmentTruncated(segmentList.get(segmentToModify)));
segmentList = readLogSegments(ledgerPath);
assertEquals(true, segmentList.get(segmentToModify).isTruncated());
assertEquals(false, segmentList.get(segmentToModify).isPartiallyTruncated());
updater = LogSegmentMetadataStoreUpdater.createMetadataUpdater(conf, metadataStore);
FutureUtils.result(updater.setLogSegmentActive(segmentList.get(segmentToModify)));
segmentList = readLogSegments(ledgerPath);
assertEquals(false, segmentList.get(segmentToModify).isTruncated());
assertEquals(false, segmentList.get(segmentToModify).isPartiallyTruncated());
updater = LogSegmentMetadataStoreUpdater.createMetadataUpdater(conf, metadataStore);
FutureUtils.result(updater.setLogSegmentPartiallyTruncated(segmentList.get(segmentToModify), segmentList.get(segmentToModify).getFirstDLSN()));
segmentList = readLogSegments(ledgerPath);
assertEquals(false, segmentList.get(segmentToModify).isTruncated());
assertEquals(true, segmentList.get(segmentToModify).isPartiallyTruncated());
updater = LogSegmentMetadataStoreUpdater.createMetadataUpdater(conf, metadataStore);
FutureUtils.result(updater.setLogSegmentActive(segmentList.get(segmentToModify)));
segmentList = readLogSegments(ledgerPath);
assertEquals(false, segmentList.get(segmentToModify).isTruncated());
assertEquals(false, segmentList.get(segmentToModify).isPartiallyTruncated());
}
use of com.twitter.distributedlog.LogSegmentMetadata in project distributedlog by twitter.
the class LogSegmentCache method remove.
/**
* Remove log segment <code>name</code> from the cache.
*
* @param name
* name of the log segment.
* @return log segment metadata.
*/
public LogSegmentMetadata remove(String name) {
synchronized (logSegments) {
LogSegmentMetadata metadata = logSegments.remove(name);
if (null != metadata) {
lid2LogSegments.remove(metadata.getLedgerId(), metadata);
LOG.debug("Removed log segment ({} : {}) from cache.", name, metadata);
}
return metadata;
}
}
Aggregations