use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
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);
Utils.ioResult(dryrunUpdater.changeSequenceNumber(segment, 6L));
segmentList = readLogSegments(ledgerPath);
assertEquals(5, segmentList.size());
// Fix the inprogress log segments
MetadataUpdater updater = LogSegmentMetadataStoreUpdater.createMetadataUpdater(conf, metadataStore);
Utils.ioResult(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.getLogSegmentId());
}
use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
the class TestLogSegmentMetadataStoreUpdater method testChangeTruncationStatus.
@Test(timeout = 60000)
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);
Utils.ioResult(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);
Utils.ioResult(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);
Utils.ioResult(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);
Utils.ioResult(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);
Utils.ioResult(updater.setLogSegmentActive(segmentList.get(segmentToModify)));
segmentList = readLogSegments(ledgerPath);
assertEquals(false, segmentList.get(segmentToModify).isTruncated());
assertEquals(false, segmentList.get(segmentToModify).isPartiallyTruncated());
}
use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
the class TestZKLogSegmentMetadataStore method testCreateLogSegment.
@Test(timeout = 60000)
public void testCreateLogSegment() throws Exception {
LogSegmentMetadata segment = createLogSegment(1L);
Transaction<Object> createTxn = lsmStore.transaction();
lsmStore.createLogSegment(createTxn, segment, null);
Utils.ioResult(createTxn.execute());
// the log segment should be created
assertNotNull("LogSegment " + segment + " should be created", zkc.get().exists(segment.getZkPath(), false));
LogSegmentMetadata segment2 = createLogSegment(1L);
Transaction<Object> createTxn2 = lsmStore.transaction();
lsmStore.createLogSegment(createTxn2, segment2, null);
try {
Utils.ioResult(createTxn2.execute());
fail("Should fail if log segment exists");
} catch (Throwable t) {
// expected
assertTrue("Should throw NodeExistsException if log segment exists", t instanceof ZKException);
ZKException zke = (ZKException) t;
assertEquals("Should throw NodeExistsException if log segment exists", KeeperException.Code.NODEEXISTS, zke.getKeeperExceptionCode());
}
}
use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
the class TestZKLogSegmentMetadataStore method testRegisterListenerAfterLSMStoreClosed.
@Test(timeout = 60000)
public void testRegisterListenerAfterLSMStoreClosed() throws Exception {
lsmStore.close();
LogSegmentMetadata segment = createLogSegment(1L);
lsmStore.getLogSegmentNames(segment.getZkPath(), new LogSegmentNamesListener() {
@Override
public void onSegmentsUpdated(Versioned<List<String>> segments) {
// no-op;
}
@Override
public void onLogStreamDeleted() {
// no-op;
}
});
assertTrue("No listener is registered", lsmStore.listeners.isEmpty());
}
use of org.apache.distributedlog.LogSegmentMetadata in project bookkeeper by apache.
the class TestZKLogSegmentMetadataStore method testUpdateNonExistentLogSegment.
@Test(timeout = 60000)
public void testUpdateNonExistentLogSegment() throws Exception {
LogSegmentMetadata segment = createLogSegment(1L);
Transaction<Object> updateTxn = lsmStore.transaction();
lsmStore.updateLogSegment(updateTxn, segment);
try {
Utils.ioResult(updateTxn.execute());
fail("Should fail update if log segment doesn't exist");
} catch (Throwable t) {
assertTrue("Should throw NoNodeException if log segment doesn't exist", t instanceof ZKException);
ZKException zke = (ZKException) t;
assertEquals("Should throw NoNodeException if log segment doesn't exist", KeeperException.Code.NONODE, zke.getKeeperExceptionCode());
}
}
Aggregations