+ "FROM LIVEINSTANCES "
+ "WHERE getMapFieldValue( getZNRecordFromMap(:IDEALSTATES , 'TestDB'), :partitionName, :_currObj.id)='MASTER'";
Map<String, Object> bindVariables = new HashMap<String, Object>();
bindVariables.put("partitionName", "TestDB_2");
ClusterJosqlQueryProcessor p = new ClusterJosqlQueryProcessor(manager);
List<Object> result = p.runJoSqlQuery(SQL, bindVariables, null);
Assert.assertEquals(result.size(), 1);
List<Object> firstList = (List<Object>) result.get(0);
Assert.assertTrue(((String) (firstList.get(0))).equalsIgnoreCase("localhost_12921"));
// Find the live instances names that hosts Partition TestDB_10 according to idealstate
SQL =
"SELECT id "
+ "FROM LIVEINSTANCES "
+ "WHERE hasMapFieldKey( getZNRecordFromMap(:IDEALSTATES, 'TestDB'), :partitionName, :_currObj.id)='true'";
p = new ClusterJosqlQueryProcessor(manager);
bindVariables.put("partitionName", "TestDB_10");
result = p.runJoSqlQuery(SQL, bindVariables, null);
Assert.assertEquals(result.size(), 3);
Set<String> hosts = new HashSet<String>();
for (Object o : result) {
String val = (String) ((List<Object>) o).get(0);
hosts.add(val);
}
Assert.assertTrue(hosts.contains("localhost_12918"));
Assert.assertTrue(hosts.contains("localhost_12920"));
Assert.assertTrue(hosts.contains("localhost_12921"));
// Find the partitions on host localhost_12919 and is on MASTER state
SQL =
"SELECT id "
+ "FROM PARTITIONS "
+ "WHERE getMapFieldValue( getZNRecordFromMap(:EXTERNALVIEW, 'TestDB'), id, :instanceName)='MASTER'";
p = new ClusterJosqlQueryProcessor(manager);
bindVariables.clear();
bindVariables.put("instanceName", "localhost_12919");
result = p.runJoSqlQuery(SQL, bindVariables, null);
Assert.assertEquals(result.size(), 4);
Set<String> partitions = new HashSet<String>();
for (Object o : result) {
String val = (String) ((List<Object>) o).get(0);
partitions.add(val);
}
Assert.assertTrue(partitions.contains("TestDB_6"));
Assert.assertTrue(partitions.contains("TestDB_7"));
Assert.assertTrue(partitions.contains("TestDB_9"));
Assert.assertTrue(partitions.contains("TestDB_14"));
// Find the partitions on host localhost_12919 and is on MASTER state
// Same as above but according to currentstates
SQL =
"SELECT id "
+ "FROM PARTITIONS "
+ "WHERE getMapFieldValue( getZNRecordFromMap(:CURRENTSTATES, :instanceName, 'TestDB'), :_currObj.id, :mapFieldKey)=:partitionState";
p = new ClusterJosqlQueryProcessor(manager);
bindVariables.clear();
bindVariables.put("instanceName", "localhost_12919");
bindVariables.put("mapFieldKey", "CURRENT_STATE");
bindVariables.put("partitionState", "MASTER");
result = p.runJoSqlQuery(SQL, bindVariables, null);
Assert.assertEquals(result.size(), 4);
partitions.clear();
partitions = new HashSet<String>();
for (Object o : result) {
String val = (String) ((List<Object>) o).get(0);
partitions.add(val);
}
Assert.assertTrue(partitions.contains("TestDB_6"));
Assert.assertTrue(partitions.contains("TestDB_7"));
Assert.assertTrue(partitions.contains("TestDB_9"));
Assert.assertTrue(partitions.contains("TestDB_14"));
// get node name that hosts a certain partition with certain state
SQL =
"SELECT id "
+ "FROM LIVEINSTANCES "
+ "WHERE getMapFieldValue( getZNRecordFromMap(:CURRENTSTATES, id, 'TestDB'), :partitionName, :mapFieldKey)=:partitionState";
p = new ClusterJosqlQueryProcessor(manager);
bindVariables.clear();
bindVariables.put("partitionName", "TestDB_8");
bindVariables.put("mapFieldKey", "CURRENT_STATE");
bindVariables.put("partitionState", "SLAVE");
result = p.runJoSqlQuery(SQL, bindVariables, null);
Assert.assertEquals(result.size(), 2);
partitions.clear();
partitions = new HashSet<String>();
for (Object o : result) {