use of com.linkedin.pinot.common.utils.LLCSegmentName in project pinot by linkedin.
the class PinotLLCRealtimeSegmentManagerTest method testPreExistingSegments.
@Test
public void testPreExistingSegments() throws Exception {
LLCSegmentName existingSegmentName = new LLCSegmentName("someTable", 1, 31, 12355L);
String[] existingSegs = { existingSegmentName.getSegmentName() };
FakePinotLLCRealtimeSegmentManager segmentManager = new FakePinotLLCRealtimeSegmentManager(true, Arrays.asList(existingSegs));
final String topic = "someTopic";
final String rtTableName = "table_REALTIME";
List<String> instances = getInstanceList(3);
final String startOffset = KAFKA_OFFSET;
IdealState idealState = PinotTableIdealStateBuilder.buildEmptyKafkaConsumerRealtimeIdealStateFor(rtTableName, 10);
try {
segmentManager.setupHelixEntries(topic, rtTableName, 8, instances, 3, startOffset, DUMMY_HOST, idealState, false, 10000);
Assert.fail("Did not get expected exception when setting up helix with existing segments in propertystore");
} catch (RuntimeException e) {
// Expected
}
try {
segmentManager.setupHelixEntries(topic, rtTableName, 8, instances, 3, startOffset, DUMMY_HOST, idealState, true, 10000);
Assert.fail("Did not get expected exception when setting up helix with existing segments in propertystore");
} catch (RuntimeException e) {
// Expected
}
}
use of com.linkedin.pinot.common.utils.LLCSegmentName in project pinot by linkedin.
the class SegmentCompletionTest method testCaseSetup.
public void testCaseSetup(boolean isLeader) throws Exception {
segmentManager = new MockPinotLLCRealtimeSegmentManager();
final int partitionId = 23;
final int seqId = 12;
final long now = System.currentTimeMillis();
final String tableName = "someTable";
final LLCSegmentName segmentName = new LLCSegmentName(tableName, partitionId, seqId, now);
segmentNameStr = segmentName.getSegmentName();
final LLCRealtimeSegmentZKMetadata metadata = new LLCRealtimeSegmentZKMetadata();
metadata.setStatus(CommonConstants.Segment.Realtime.Status.IN_PROGRESS);
metadata.setNumReplicas(3);
segmentManager._segmentMetadata = metadata;
segmentCompletionMgr = new MockSegmentCompletionManager(segmentManager, isLeader);
segmentManager._segmentCompletionMgr = segmentCompletionMgr;
Field fsmMapField = SegmentCompletionManager.class.getDeclaredField("_fsmMap");
fsmMapField.setAccessible(true);
fsmMap = (Map<String, Object>) fsmMapField.get(segmentCompletionMgr);
Field ctMapField = SegmentCompletionManager.class.getDeclaredField("_commitTimeMap");
ctMapField.setAccessible(true);
commitTimeMap = (Map<String, Long>) ctMapField.get(segmentCompletionMgr);
}
use of com.linkedin.pinot.common.utils.LLCSegmentName in project pinot by linkedin.
the class RetentionManagerTest method setupRealtimeTable.
// The most recent will be in
private Set<String> setupRealtimeTable(final int nSegments, final long now) throws Exception {
final int replicaCount = 1;
createRealtimeTableConfig(_realtimeTableName, replicaCount);
Set<String> remainingSegments = new HashSet<>();
IdealState idealState = PinotTableIdealStateBuilder.buildEmptyKafkaConsumerRealtimeIdealStateFor(_realtimeTableName, replicaCount);
final int kafkaPartition = 5;
final long millisInDays = TimeUnit.DAYS.toMillis(1);
final String serverName = "Server_localhost_0";
// If we set the segment creation time to a certain value and compare it as being X ms old,
// then we could get unpredictable results depending on whether it takes more or less than
// one millisecond to get to RetentionManager time comparison code. To be safe, set the
// milliseconds off by 1/2 day.
long segmentCreationTime = now - (nSegments + 1) * millisInDays + millisInDays / 2;
List<LLCRealtimeSegmentZKMetadata> segmentZKMetadatas = new ArrayList<>();
for (int seq = 1; seq <= nSegments; seq++) {
segmentCreationTime += millisInDays;
LLCRealtimeSegmentZKMetadata segmentMetadata = createSegmentMetadata(replicaCount, segmentCreationTime);
LLCSegmentName llcSegmentName = new LLCSegmentName(_testTableName, kafkaPartition, seq, segmentCreationTime);
final String segName = llcSegmentName.getSegmentName();
segmentMetadata.setSegmentName(segName);
if (seq == nSegments) {
// create consuming segment
segmentMetadata.setStatus(CommonConstants.Segment.Realtime.Status.IN_PROGRESS);
idealState.setPartitionState(segName, serverName, "CONSUMING");
remainingSegments.add(segName);
} else if (seq % 2 == 0) {
// create ONLINE segment
segmentMetadata.setStatus(CommonConstants.Segment.Realtime.Status.DONE);
idealState.setPartitionState(segName, serverName, "ONLINE");
remainingSegments.add(segName);
} else {
segmentMetadata.setStatus(CommonConstants.Segment.Realtime.Status.IN_PROGRESS);
idealState.setPartitionState(segName, serverName, "OFFLINE");
if (now - segmentCreationTime < TimeUnit.DAYS.toMillis(RetentionManager.getRetentionTimeForOldLLCSegmentsDays())) {
remainingSegments.add(segName);
}
}
final String znodePath = ZKMetadataProvider.constructPropertyStorePathForSegment(_realtimeTableName, segName);
_propertyStore.set(znodePath, segmentMetadata.toZNRecord(), AccessOption.PERSISTENT);
}
_helixAdmin.addResource(HELIX_CLUSTER_NAME, _realtimeTableName, idealState);
return remainingSegments;
}
use of com.linkedin.pinot.common.utils.LLCSegmentName in project pinot by linkedin.
the class ValidationManagerTest method testLLCValidation.
@Test
public void testLLCValidation() throws Exception {
final String topicName = "topic";
final int kafkaPartitionCount = 2;
final String realtimeTableName = "table_REALTIME";
final String tableName = TableNameBuilder.extractRawTableName(realtimeTableName);
// Server 1
final String S1 = "S1";
// Server 2
final String S2 = "S2";
// Server 3
final String S3 = "S3";
final List<String> hosts = Arrays.asList(new String[] { S1, S2, S3 });
final HelixAdmin helixAdmin = _pinotHelixResourceManager.getHelixAdmin();
ZNRecord znRecord = new ZNRecord(topicName);
for (int i = 0; i < kafkaPartitionCount; i++) {
znRecord.setListField(Integer.toString(i), hosts);
}
makeMockPinotLLCRealtimeSegmentManager(znRecord);
long msSinceEpoch = 1540;
LLCSegmentName p0s0 = new LLCSegmentName(tableName, 0, 0, msSinceEpoch);
LLCSegmentName p0s1 = new LLCSegmentName(tableName, 0, 1, msSinceEpoch);
LLCSegmentName p1s0 = new LLCSegmentName(tableName, 1, 0, msSinceEpoch);
LLCSegmentName p1s1 = new LLCSegmentName(tableName, 1, 1, msSinceEpoch);
IdealState idealstate = PinotTableIdealStateBuilder.buildEmptyIdealStateFor(realtimeTableName, 3);
idealstate.setPartitionState(p0s0.getSegmentName(), S1, PinotHelixSegmentOnlineOfflineStateModelGenerator.ONLINE_STATE);
idealstate.setPartitionState(p0s0.getSegmentName(), S2, PinotHelixSegmentOnlineOfflineStateModelGenerator.ONLINE_STATE);
idealstate.setPartitionState(p0s0.getSegmentName(), S3, PinotHelixSegmentOnlineOfflineStateModelGenerator.ONLINE_STATE);
// idealstate.setPartitionState(p0s1.getSegmentName(), S1, PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE);
// idealstate.setPartitionState(p0s1.getSegmentName(), S2, PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE);
// idealstate.setPartitionState(p0s1.getSegmentName(), S3, PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE);
idealstate.setPartitionState(p1s0.getSegmentName(), S1, PinotHelixSegmentOnlineOfflineStateModelGenerator.ONLINE_STATE);
idealstate.setPartitionState(p1s0.getSegmentName(), S2, PinotHelixSegmentOnlineOfflineStateModelGenerator.ONLINE_STATE);
idealstate.setPartitionState(p1s0.getSegmentName(), S3, PinotHelixSegmentOnlineOfflineStateModelGenerator.ONLINE_STATE);
idealstate.setPartitionState(p1s1.getSegmentName(), S1, PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE);
idealstate.setPartitionState(p1s1.getSegmentName(), S2, PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE);
idealstate.setPartitionState(p1s1.getSegmentName(), S3, PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE);
helixAdmin.addResource(HELIX_CLUSTER_NAME, realtimeTableName, idealstate);
FakeValidationMetrics validationMetrics = new FakeValidationMetrics();
ValidationManager validationManager = new ValidationManager(validationMetrics, _pinotHelixResourceManager, new ControllerConf(), _segmentManager);
Map<String, String> streamConfigs = new HashMap<String, String>(4);
streamConfigs.put(StringUtil.join(".", CommonConstants.Helix.DataSource.STREAM_PREFIX, CommonConstants.Helix.DataSource.Realtime.Kafka.CONSUMER_TYPE), "highLevel,simple");
Field autoCreateOnError = ValidationManager.class.getDeclaredField("_autoCreateOnError");
autoCreateOnError.setAccessible(true);
autoCreateOnError.setBoolean(validationManager, false);
AbstractTableConfig tableConfig = mock(AbstractTableConfig.class);
IndexingConfig indexingConfig = mock(IndexingConfig.class);
when(tableConfig.getIndexingConfig()).thenReturn(indexingConfig);
when(indexingConfig.getStreamConfigs()).thenReturn(streamConfigs);
validationManager.validateLLCSegments(realtimeTableName, tableConfig);
Assert.assertEquals(validationMetrics.partitionCount, 1);
// Set partition 0 to have one instance in CONSUMING state, and others in OFFLINE.
// we should not flag any partitions to correct.
helixAdmin.dropResource(HELIX_CLUSTER_NAME, realtimeTableName);
idealstate.setPartitionState(p0s1.getSegmentName(), S1, PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE);
idealstate.setPartitionState(p0s1.getSegmentName(), S2, PinotHelixSegmentOnlineOfflineStateModelGenerator.OFFLINE_STATE);
idealstate.setPartitionState(p0s1.getSegmentName(), S3, PinotHelixSegmentOnlineOfflineStateModelGenerator.OFFLINE_STATE);
helixAdmin.addResource(HELIX_CLUSTER_NAME, realtimeTableName, idealstate);
validationManager.validateLLCSegments(realtimeTableName, tableConfig);
Assert.assertEquals(validationMetrics.partitionCount, 0);
helixAdmin.dropResource(HELIX_CLUSTER_NAME, realtimeTableName);
}
use of com.linkedin.pinot.common.utils.LLCSegmentName in project pinot by linkedin.
the class SegmentCompletionIntegrationTests method testStopConsumingToOfflineAndAutofix.
// Test that if we send stoppedConsuming to the controller, the segment goes offline.
@Test
public void testStopConsumingToOfflineAndAutofix() throws Exception {
final String realtimeTableName = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(_tableName);
long endTime = now() + MAX_RUN_TIME_SECONDS * 1000L;
while (now() < endTime) {
ExternalView ev = HelixHelper.getExternalViewForResource(_helixAdmin, _clusterName, realtimeTableName);
if (ev != null) {
Map<String, String> stateMap = ev.getStateMap(_segmentName);
if (stateMap != null && stateMap.containsKey(_serverInstance)) {
if (stateMap.get(_serverInstance).equals(PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE)) {
break;
}
}
}
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
Assert.assertTrue(now() < endTime, "Failed trying to reach consuming state");
// Now report to the controller that we had to stop consumption
ServerSegmentCompletionProtocolHandler protocolHandler = new ServerSegmentCompletionProtocolHandler(_serverInstance);
SegmentCompletionProtocol.Request.Params params = new SegmentCompletionProtocol.Request.Params();
params.withOffset(45688L).withSegmentName(_segmentName).withReason("RandomReason");
SegmentCompletionProtocol.Response response = protocolHandler.segmentStoppedConsuming(params);
Assert.assertTrue(response.getStatus() == SegmentCompletionProtocol.ControllerResponseStatus.PROCESSED);
while (now() < endTime) {
ExternalView ev = HelixHelper.getExternalViewForResource(_helixAdmin, _clusterName, realtimeTableName);
Map<String, String> stateMap = ev.getStateMap(_segmentName);
if (stateMap.containsKey(_serverInstance)) {
if (stateMap.get(_serverInstance).equals(PinotHelixSegmentOnlineOfflineStateModelGenerator.OFFLINE_STATE)) {
break;
}
}
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
Assert.assertTrue(now() < endTime, "Failed trying to reach offline state");
// Now call the validation manager, and the segment should fix itself
getControllerValidationManager().runValidation();
// Now there should be a new segment in CONSUMING state in the IDEALSTATE.
IdealState idealState = HelixHelper.getTableIdealState(_helixManager, realtimeTableName);
Assert.assertEquals(idealState.getPartitionSet().size(), 2);
for (String segmentId : idealState.getPartitionSet()) {
if (!segmentId.equals(_segmentName)) {
// This is a new segment. Verify that it is in CONSUMING state, and has a sequence number 1 more than prev one
LLCSegmentName oldSegmentName = new LLCSegmentName(_segmentName);
LLCSegmentName newSegmentName = new LLCSegmentName(segmentId);
Assert.assertEquals(newSegmentName.getSequenceNumber(), oldSegmentName.getSequenceNumber() + 1);
Map<String, String> instanceStateMap = idealState.getInstanceStateMap(segmentId);
for (String state : instanceStateMap.values()) {
Assert.assertTrue(state.equals(PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE));
}
}
}
// We will assume that it eventually makes it to externalview
}
Aggregations