Builder kb = accessor.keyBuilder();
accessor.setProperty(kb.healthReport(instance, "scnTable"), new HealthStat(scnRecord));
}
ZNRecordQueryProcessor processor = new ZNRecordQueryProcessor();
DataAccessorBasedTupleReader tupleReader = new DataAccessorBasedTupleReader(accessor, manager.getClusterName());
String scnTableQuery = "SELECT T1.instance as instance, T1.mapField as partition, T1.gen as gen, T1.seq as seq " +
"FROM explodeMap(`INSTANCES/*/HEALTHREPORT/scnTable`) AS T1" +
" JOIN LIVEINSTANCES as T2 using (T1.instance, T2.id)";
List<ZNRecord> scnTable = processor.execute(scnTableQuery, tupleReader);
tupleReader.setTempTable("scnTable", scnTable);
String rankQuery = "SELECT instance, partition, gen, seq, T1.listIndex AS instanceRank " +
" FROM scnTable JOIN explodeList(`IDEALSTATES/" + TEST_DB + "`) AS T1 " +
"USING (scnTable.instance, T1.listVal) WHERE scnTable.partition=T1.listField";
List<ZNRecord> rankTable = processor.execute(rankQuery, tupleReader);
System.out.println(rankTable.size());
tupleReader.setTempTable("rankTable", rankTable);
String masterSelectionQuery = "SELECT instance, partition, instanceRank, gen, (T.maxSeq-seq) AS seqDiff, seq FROM rankTable JOIN " +
" (SELECT partition, max(to_number(seq)) AS maxSeq FROM rankTable GROUP BY partition) AS T USING(rankTable.partition, T.partition) " +
" WHERE to_number(seqDiff) < 10 " +
" ORDER BY partition, to_number(gen) desc, to_number(instanceRank), to_number(seqDiff)";