use of org.apache.commons.configuration.BaseConfiguration in project pinot by linkedin.
the class RoutingTableTest method testKafkaHighLevelConsumerBasedRoutingTable.
@Test
public void testKafkaHighLevelConsumerBasedRoutingTable() throws Exception {
RoutingTableBuilder routingStrategy = new KafkaHighLevelConsumerBasedRoutingTableBuilder();
final String group0 = "testResource0_REALTIME_1433316466991_0";
final String group1 = "testResource1_REALTIME_1433316490099_1";
final String group2 = "testResource2_REALTIME_1436589344583_1";
final LLCSegmentName llcSegmentName = new LLCSegmentName("testResource0", 2, 65, System.currentTimeMillis());
HelixExternalViewBasedRouting routingTable = new HelixExternalViewBasedRouting(null, NO_LLC_ROUTING, null, new BaseConfiguration());
Field realtimeRTBField = HelixExternalViewBasedRouting.class.getDeclaredField("_realtimeHLCRoutingTableBuilder");
realtimeRTBField.setAccessible(true);
realtimeRTBField.set(routingTable, routingStrategy);
ExternalView externalView = new ExternalView("testResource0_REALTIME");
// Toss in an llc segment in the mix. Should not affect the results
externalView.setState(llcSegmentName.getSegmentName(), "dataServer_instance_0", "CONSUMING");
externalView.setState(new HLCSegmentName(group0, ALL_PARTITIONS, "0").getSegmentName(), "dataServer_instance_0", "ONLINE");
externalView.setState(new HLCSegmentName(group0, ALL_PARTITIONS, "1").getSegmentName(), "dataServer_instance_1", "ONLINE");
externalView.setState(new HLCSegmentName(group1, ALL_PARTITIONS, "2").getSegmentName(), "dataServer_instance_2", "ONLINE");
externalView.setState(new HLCSegmentName(group1, ALL_PARTITIONS, "3").getSegmentName(), "dataServer_instance_3", "ONLINE");
externalView.setState(new HLCSegmentName(group2, ALL_PARTITIONS, "4").getSegmentName(), "dataServer_instance_4", "ONLINE");
externalView.setState(new HLCSegmentName(group2, ALL_PARTITIONS, "5").getSegmentName(), "dataServer_instance_5", "ONLINE");
routingTable.markDataResourceOnline("testResource0_REALTIME", externalView, generateInstanceConfigs("dataServer_instance", 0, 5));
ExternalView externalView1 = new ExternalView("testResource1_REALTIME");
externalView1.setState(new HLCSegmentName(group0, ALL_PARTITIONS, "10").getSegmentName(), "dataServer_instance_10", "ONLINE");
externalView1.setState(new HLCSegmentName(group0, ALL_PARTITIONS, "11").getSegmentName(), "dataServer_instance_11", "ONLINE");
externalView1.setState(new HLCSegmentName(group0, ALL_PARTITIONS, "12").getSegmentName(), "dataServer_instance_12", "ONLINE");
routingTable.markDataResourceOnline("testResource1_REALTIME", externalView1, generateInstanceConfigs("dataServer_instance", 10, 12));
ExternalView externalView2 = new ExternalView("testResource2_REALTIME");
externalView2.setState(new HLCSegmentName(group0, ALL_PARTITIONS, "20").getSegmentName(), "dataServer_instance_20", "ONLINE");
externalView2.setState(new HLCSegmentName(group0, ALL_PARTITIONS, "21").getSegmentName(), "dataServer_instance_21", "ONLINE");
externalView2.setState(new HLCSegmentName(group0, ALL_PARTITIONS, "22").getSegmentName(), "dataServer_instance_22", "ONLINE");
externalView2.setState(new HLCSegmentName(group1, ALL_PARTITIONS, "23").getSegmentName(), "dataServer_instance_23", "ONLINE");
externalView2.setState(new HLCSegmentName(group1, ALL_PARTITIONS, "24").getSegmentName(), "dataServer_instance_24", "ONLINE");
externalView2.setState(new HLCSegmentName(group1, ALL_PARTITIONS, "25").getSegmentName(), "dataServer_instance_25", "ONLINE");
externalView2.setState(new HLCSegmentName(group2, ALL_PARTITIONS, "26").getSegmentName(), "dataServer_instance_26", "ONLINE");
externalView2.setState(new HLCSegmentName(group2, ALL_PARTITIONS, "27").getSegmentName(), "dataServer_instance_27", "ONLINE");
externalView2.setState(new HLCSegmentName(group2, ALL_PARTITIONS, "28").getSegmentName(), "dataServer_instance_28", "ONLINE");
routingTable.markDataResourceOnline("testResource2_REALTIME", externalView2, generateInstanceConfigs("dataServer_instance", 20, 28));
for (int numRun = 0; numRun < 100; ++numRun) {
assertResourceRequest(routingTable, "testResource0_REALTIME", new String[] { "[" + new HLCSegmentName(group0, ALL_PARTITIONS, "0").getSegmentName() + ", " + new HLCSegmentName(group0, ALL_PARTITIONS, "1").getSegmentName() + "]", "[" + new HLCSegmentName(group1, ALL_PARTITIONS, "2").getSegmentName() + ", " + new HLCSegmentName(group1, ALL_PARTITIONS, "3").getSegmentName() + "]", "[" + new HLCSegmentName(group2, ALL_PARTITIONS, "4").getSegmentName() + ", " + new HLCSegmentName(group2, ALL_PARTITIONS, "5").getSegmentName() + "]" }, 2);
}
for (int numRun = 0; numRun < 100; ++numRun) {
assertResourceRequest(routingTable, "testResource1_REALTIME", new String[] { "[" + new HLCSegmentName(group0, ALL_PARTITIONS, "10").getSegmentName() + ", " + new HLCSegmentName(group0, ALL_PARTITIONS, "11").getSegmentName() + ", " + new HLCSegmentName(group0, ALL_PARTITIONS, "12").getSegmentName() + "]" }, 3);
}
for (int numRun = 0; numRun < 100; ++numRun) {
assertResourceRequest(routingTable, "testResource2_REALTIME", new String[] { "[" + new HLCSegmentName(group0, ALL_PARTITIONS, "20").getSegmentName() + ", " + new HLCSegmentName(group0, ALL_PARTITIONS, "21").getSegmentName() + ", " + new HLCSegmentName(group0, ALL_PARTITIONS, "22").getSegmentName() + "]", "[" + new HLCSegmentName(group1, ALL_PARTITIONS, "23").getSegmentName() + ", " + new HLCSegmentName(group1, ALL_PARTITIONS, "24").getSegmentName() + ", " + new HLCSegmentName(group1, ALL_PARTITIONS, "25").getSegmentName() + "]", "[" + new HLCSegmentName(group2, ALL_PARTITIONS, "26").getSegmentName() + ", " + new HLCSegmentName(group2, ALL_PARTITIONS, "27").getSegmentName() + ", " + new HLCSegmentName(group2, ALL_PARTITIONS, "28").getSegmentName() + "]" }, 3);
}
}
use of org.apache.commons.configuration.BaseConfiguration in project pinot by linkedin.
the class RoutingTableTest method testCombinedKafkaRouting.
// Test that we can switch between llc and hlc routing depending on what the selector tells us.
@Test
public void testCombinedKafkaRouting() throws Exception {
HelixExternalViewBasedRouting routingTable = new HelixExternalViewBasedRouting(null, NO_LLC_ROUTING, null, new BaseConfiguration());
final long now = System.currentTimeMillis();
final String tableName = "table";
final String resourceName = tableName + "_REALTIME";
final String group1 = resourceName + "_" + Long.toString(now) + "_0";
final String group2 = resourceName + "_" + Long.toString(now) + "_1";
final String online = "ONLINE";
final String consuming = "CONSUMING";
final int partitionId = 1;
final String partitionRange = "JUNK";
final int segId1 = 1;
final int segId2 = 2;
final int port1 = 1;
final int port2 = 2;
final String host = "host";
final ServerInstance serverInstance1 = new ServerInstance(host, port1);
final ServerInstance serverInstance2 = new ServerInstance(host, port2);
final String helixInstance1 = CommonConstants.Helix.PREFIX_OF_SERVER_INSTANCE + serverInstance1;
final String helixInstance2 = CommonConstants.Helix.PREFIX_OF_SERVER_INSTANCE + serverInstance2;
final HLCSegmentName s1HlcSegment1 = new HLCSegmentName(group1, partitionRange, Integer.toString(segId1));
final HLCSegmentName s1HlcSegment2 = new HLCSegmentName(group1, partitionRange, Integer.toString(segId2));
final HLCSegmentName s2HlcSegment1 = new HLCSegmentName(group2, partitionRange, Integer.toString(segId1));
final HLCSegmentName s2HlcSegment2 = new HLCSegmentName(group2, partitionRange, Integer.toString(segId2));
final LLCSegmentName llcSegment1 = new LLCSegmentName(tableName, partitionId, segId1, now);
final LLCSegmentName llcSegment2 = new LLCSegmentName(tableName, partitionId, segId2, now);
final List<InstanceConfig> instanceConfigs = new ArrayList<>(2);
instanceConfigs.add(new InstanceConfig(helixInstance1));
instanceConfigs.add(new InstanceConfig(helixInstance2));
ExternalView ev = new ExternalView(resourceName);
ev.setState(s1HlcSegment1.getSegmentName(), helixInstance1, online);
ev.setState(s1HlcSegment2.getSegmentName(), helixInstance1, online);
ev.setState(llcSegment1.getSegmentName(), helixInstance2, online);
ev.setState(llcSegment2.getSegmentName(), helixInstance2, consuming);
routingTable.markDataResourceOnline(resourceName, ev, instanceConfigs);
RoutingTableLookupRequest request = new RoutingTableLookupRequest(resourceName, Collections.<String>emptyList());
for (int i = 0; i < 100; i++) {
Map<ServerInstance, SegmentIdSet> routingMap = routingTable.findServers(request);
Assert.assertEquals(routingMap.size(), 1);
List<String> segments = routingMap.get(serverInstance1).getSegmentsNameList();
Assert.assertEquals(segments.size(), 2);
Assert.assertTrue(segments.contains(s1HlcSegment1.getSegmentName()));
Assert.assertTrue(segments.contains(s1HlcSegment2.getSegmentName()));
}
// Now change the percent value in the routing table selector to be 100, and we should get only LLC segments.
Configuration configuration = new PropertiesConfiguration();
configuration.addProperty("class", PercentageBasedRoutingTableSelector.class.getName());
configuration.addProperty("table." + resourceName, new Integer(100));
RoutingTableSelector selector = RoutingTableSelectorFactory.getRoutingTableSelector(configuration, null);
selector.init(configuration, null);
Field selectorField = HelixExternalViewBasedRouting.class.getDeclaredField("_routingTableSelector");
selectorField.setAccessible(true);
selectorField.set(routingTable, selector);
// And we should find only LLC segments.
for (int i = 0; i < 100; i++) {
Map<ServerInstance, SegmentIdSet> routingMap = routingTable.findServers(request);
Assert.assertEquals(routingMap.size(), 1);
List<String> segments = routingMap.get(serverInstance2).getSegmentsNameList();
Assert.assertEquals(segments.size(), 2);
Assert.assertTrue(segments.contains(llcSegment1.getSegmentName()));
Assert.assertTrue(segments.contains(llcSegment2.getSegmentName()));
}
// Now change it to 50, and we should find both (at least 10 times each).
configuration = new PropertiesConfiguration();
configuration.addProperty("table." + resourceName, new Integer(50));
selector = new PercentageBasedRoutingTableSelector();
selector.init(configuration, null);
selectorField.set(routingTable, selector);
int hlc = 0;
int llc = 0;
for (int i = 0; i < 100; i++) {
Map<ServerInstance, SegmentIdSet> routingMap = routingTable.findServers(request);
Assert.assertEquals(routingMap.size(), 1);
if (routingMap.containsKey(serverInstance2)) {
List<String> segments = routingMap.get(serverInstance2).getSegmentsNameList();
Assert.assertEquals(segments.size(), 2);
Assert.assertTrue(segments.contains(llcSegment1.getSegmentName()));
Assert.assertTrue(segments.contains(llcSegment2.getSegmentName()));
llc++;
} else {
List<String> segments = routingMap.get(serverInstance1).getSegmentsNameList();
Assert.assertEquals(segments.size(), 2);
Assert.assertTrue(segments.contains(s1HlcSegment1.getSegmentName()));
Assert.assertTrue(segments.contains(s1HlcSegment2.getSegmentName()));
hlc++;
}
}
// If we do the above iteration 100 times, we should get at least 10 of each type of routing.
// If this test fails
Assert.assertTrue(hlc >= 10, "Got low values hlc=" + hlc + ",llc=" + llc);
Assert.assertTrue(llc >= 10, "Got low values hlc=" + hlc + ",llc=" + llc);
// Check that force HLC works
request = new RoutingTableLookupRequest(resourceName, Collections.singletonList("FORCE_HLC"));
hlc = 0;
llc = 0;
for (int i = 0; i < 100; i++) {
Map<ServerInstance, SegmentIdSet> routingMap = routingTable.findServers(request);
Assert.assertEquals(routingMap.size(), 1);
if (routingMap.containsKey(serverInstance2)) {
List<String> segments = routingMap.get(serverInstance2).getSegmentsNameList();
Assert.assertEquals(segments.size(), 2);
Assert.assertTrue(segments.contains(llcSegment1.getSegmentName()));
Assert.assertTrue(segments.contains(llcSegment2.getSegmentName()));
llc++;
} else {
List<String> segments = routingMap.get(serverInstance1).getSegmentsNameList();
Assert.assertEquals(segments.size(), 2);
Assert.assertTrue(segments.contains(s1HlcSegment1.getSegmentName()));
Assert.assertTrue(segments.contains(s1HlcSegment2.getSegmentName()));
hlc++;
}
}
Assert.assertEquals(hlc, 100);
Assert.assertEquals(llc, 0);
// Check that force LLC works
request = new RoutingTableLookupRequest(resourceName, Collections.singletonList("FORCE_LLC"));
hlc = 0;
llc = 0;
for (int i = 0; i < 100; i++) {
Map<ServerInstance, SegmentIdSet> routingMap = routingTable.findServers(request);
Assert.assertEquals(routingMap.size(), 1);
if (routingMap.containsKey(serverInstance2)) {
List<String> segments = routingMap.get(serverInstance2).getSegmentsNameList();
Assert.assertEquals(segments.size(), 2);
Assert.assertTrue(segments.contains(llcSegment1.getSegmentName()));
Assert.assertTrue(segments.contains(llcSegment2.getSegmentName()));
llc++;
} else {
List<String> segments = routingMap.get(serverInstance1).getSegmentsNameList();
Assert.assertEquals(segments.size(), 2);
Assert.assertTrue(segments.contains(s1HlcSegment1.getSegmentName()));
Assert.assertTrue(segments.contains(s1HlcSegment2.getSegmentName()));
hlc++;
}
}
Assert.assertEquals(hlc, 0);
Assert.assertEquals(llc, 100);
}
use of org.apache.commons.configuration.BaseConfiguration in project pinot by linkedin.
the class KafkaLowLevelConsumerRoutingTableBuilderTest method testMultipleConsumingSegments.
@Test
public void testMultipleConsumingSegments() {
final int SEGMENT_COUNT = 10;
final int ONLINE_SEGMENT_COUNT = 8;
final int CONSUMING_SEGMENT_COUNT = SEGMENT_COUNT - ONLINE_SEGMENT_COUNT;
KafkaLowLevelConsumerRoutingTableBuilder routingTableBuilder = new KafkaLowLevelConsumerRoutingTableBuilder();
routingTableBuilder.init(new BaseConfiguration());
List<SegmentName> segmentNames = new ArrayList<SegmentName>();
for (int i = 0; i < SEGMENT_COUNT; ++i) {
segmentNames.add(new LLCSegmentName("table", 0, i, System.currentTimeMillis()));
}
List<InstanceConfig> instanceConfigs = new ArrayList<InstanceConfig>();
InstanceConfig instanceConfig = new InstanceConfig("Server_localhost_1234");
instanceConfigs.add(instanceConfig);
instanceConfig.getRecord().setSimpleField(CommonConstants.Helix.IS_SHUTDOWN_IN_PROGRESS, "false");
// Generate an external view for a single server with some consuming segments
ExternalView externalView = new ExternalView("table_REALTIME");
for (int i = 0; i < ONLINE_SEGMENT_COUNT; i++) {
externalView.setState(segmentNames.get(i).getSegmentName(), "Server_localhost_1234", "ONLINE");
}
for (int i = ONLINE_SEGMENT_COUNT; i < SEGMENT_COUNT; ++i) {
externalView.setState(segmentNames.get(i).getSegmentName(), "Server_localhost_1234", "CONSUMING");
}
List<ServerToSegmentSetMap> routingTables = routingTableBuilder.computeRoutingTableFromExternalView("table", externalView, instanceConfigs);
for (ServerToSegmentSetMap routingTable : routingTables) {
for (String server : routingTable.getServerSet()) {
Set<String> segmentSet = routingTable.getSegmentSet(server);
assertEquals(segmentSet.size(), ONLINE_SEGMENT_COUNT + 1, "");
// Should only contain the first consuming segment, not the second
assertTrue(segmentSet.contains(segmentNames.get(ONLINE_SEGMENT_COUNT).getSegmentName()), "Segment set does not contain the first segment in consuming state");
for (int i = ONLINE_SEGMENT_COUNT + 1; i < SEGMENT_COUNT; i++) {
assertFalse(segmentSet.contains(segmentNames.get(i).getSegmentName()), "Segment set contains a segment in consuming state that should not be there");
}
}
}
}
use of org.apache.commons.configuration.BaseConfiguration in project pinot by linkedin.
the class RandomRoutingTableTest method testHelixExternalViewBasedRoutingTable.
@Test
public void testHelixExternalViewBasedRoutingTable() throws Exception {
URL resourceUrl = getClass().getClassLoader().getResource("SampleExternalView.json");
Assert.assertNotNull(resourceUrl);
String fileName = resourceUrl.getFile();
String tableName = "testTable_OFFLINE";
InputStream evInputStream = new FileInputStream(fileName);
ZNRecordSerializer znRecordSerializer = new ZNRecordSerializer();
ZNRecord externalViewRecord = (ZNRecord) znRecordSerializer.deserialize(IOUtils.toByteArray(evInputStream));
int totalRuns = 10000;
RoutingTableBuilder routingStrategy = new BalancedRandomRoutingTableBuilder(10);
HelixExternalViewBasedRouting routingTable = new HelixExternalViewBasedRouting(null, new PercentageBasedRoutingTableSelector(), null, new BaseConfiguration());
routingTable.setSmallClusterRoutingTableBuilder(routingStrategy);
ExternalView externalView = new ExternalView(externalViewRecord);
routingTable.markDataResourceOnline(tableName, externalView, getInstanceConfigs(externalView));
double[] globalArrays = new double[9];
for (int numRun = 0; numRun < totalRuns; ++numRun) {
RoutingTableLookupRequest request = new RoutingTableLookupRequest(tableName, Collections.<String>emptyList());
Map<ServerInstance, SegmentIdSet> serversMap = routingTable.findServers(request);
TreeSet<ServerInstance> serverInstances = new TreeSet<ServerInstance>(serversMap.keySet());
int i = 0;
double[] arrays = new double[9];
for (ServerInstance serverInstance : serverInstances) {
globalArrays[i] += serversMap.get(serverInstance).getSegments().size();
arrays[i++] = serversMap.get(serverInstance).getSegments().size();
}
for (int j = 0; i < arrays.length; ++j) {
Assert.assertTrue(arrays[j] / totalRuns <= 31);
Assert.assertTrue(arrays[j] / totalRuns >= 28);
}
// System.out.println(Arrays.toString(arrays) + " : " + new StandardDeviation().evaluate(arrays) + " : " + new Mean().evaluate(arrays));
}
for (int i = 0; i < globalArrays.length; ++i) {
Assert.assertTrue(globalArrays[i] / totalRuns <= 31);
Assert.assertTrue(globalArrays[i] / totalRuns >= 28);
}
// System.out.println(Arrays.toString(globalArrays) + " : " + new StandardDeviation().evaluate(globalArrays) + " : "
// + new Mean().evaluate(globalArrays));
}
use of org.apache.commons.configuration.BaseConfiguration in project titan by thinkaurelius.
the class TitanFactory method getLocalConfiguration.
//###################################
// HELPER METHODS
//###################################
private static ReadConfiguration getLocalConfiguration(String shortcutOrFile) {
File file = new File(shortcutOrFile);
if (file.exists())
return getLocalConfiguration(file);
else {
int pos = shortcutOrFile.indexOf(':');
if (pos < 0)
pos = shortcutOrFile.length();
String backend = shortcutOrFile.substring(0, pos);
Preconditions.checkArgument(StandardStoreManager.getAllManagerClasses().containsKey(backend.toLowerCase()), "Backend shorthand unknown: %s", backend);
String secondArg = null;
if (pos + 1 < shortcutOrFile.length())
secondArg = shortcutOrFile.substring(pos + 1).trim();
BaseConfiguration config = new BaseConfiguration();
ModifiableConfiguration writeConfig = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(config), BasicConfiguration.Restriction.NONE);
writeConfig.set(STORAGE_BACKEND, backend);
ConfigOption option = Backend.getOptionForShorthand(backend);
if (option == null) {
Preconditions.checkArgument(secondArg == null);
} else if (option == STORAGE_DIRECTORY || option == STORAGE_CONF_FILE) {
Preconditions.checkArgument(StringUtils.isNotBlank(secondArg), "Need to provide additional argument to initialize storage backend");
writeConfig.set(option, getAbsolutePath(secondArg));
} else if (option == STORAGE_HOSTS) {
Preconditions.checkArgument(StringUtils.isNotBlank(secondArg), "Need to provide additional argument to initialize storage backend");
writeConfig.set(option, new String[] { secondArg });
} else
throw new IllegalArgumentException("Invalid configuration option for backend " + option);
return new CommonsConfiguration(config);
}
}
Aggregations