TreeMap<KeyExtent,String> tabletLocations = new TreeMap<KeyExtent,String>();
Connector conn = opts.getConnector();
final Instance inst = conn.getInstance();
String tableId = Tables.getNameToIdMap(inst).get(tableName);
Credentials credentials = new Credentials(opts.principal, opts.getToken());
MetadataServicer.forTableId(inst, credentials, tableId).getTabletLocations(tabletLocations);
final HashSet<KeyExtent> failures = new HashSet<KeyExtent>();
Map<String,List<KeyExtent>> extentsPerServer = new TreeMap<String,List<KeyExtent>>();
for (Entry<KeyExtent,String> entry : tabletLocations.entrySet()) {
KeyExtent keyExtent = entry.getKey();
String loc = entry.getValue();
if (loc == null)
System.out.println(" Tablet " + keyExtent + " has no location");
else if (opts.verbose)
System.out.println(" Tablet " + keyExtent + " is located at " + loc);
if (loc != null) {
List<KeyExtent> extentList = extentsPerServer.get(loc);
if (extentList == null) {
extentList = new ArrayList<KeyExtent>();
extentsPerServer.put(loc, extentList);
}
if (check == null || check.contains(keyExtent))
extentList.add(keyExtent);
}
}
ExecutorService tp = Executors.newFixedThreadPool(20);
final ServerConfiguration conf = new ServerConfiguration(inst);
for (final Entry<String,List<KeyExtent>> entry : extentsPerServer.entrySet()) {
Runnable r = new Runnable() {
@Override
public void run() {
try {
checkTabletServer(inst, conf.getConfiguration(), new Credentials(opts.principal, opts.getToken()), entry, failures);
} catch (Exception e) {
System.err.println("Failure on ts " + entry.getKey() + " " + e.getMessage());
e.printStackTrace();
failures.addAll(entry.getValue());
}