private synchronized Map<String, BlurIndex> openMissingShards(final String table, Set<String> shardsToServe,
final Map<String, BlurIndex> tableIndexes) {
Map<String, Future<BlurIndex>> opening = new HashMap<String, Future<BlurIndex>>();
for (String s : shardsToServe) {
final String shard = s;
BlurIndex blurIndex = tableIndexes.get(shard);
if (blurIndex == null) {
_pauseWarmup.incrementAndGet();
LOG.info("Opening missing shard [{0}] from table [{1}]", shard, table);
Future<BlurIndex> submit = _openerService.submit(new Callable<BlurIndex>() {
@Override
public BlurIndex call() throws Exception {
_shardStateManager.opening(table, shard);
try {
BlurIndex openShard = openShard(table, shard);
_shardStateManager.open(table, shard);
return openShard;
} catch (Exception e) {
_shardStateManager.openingError(table, shard);
throw e;
} catch (Throwable t) {
_shardStateManager.openingError(table, shard);
throw new RuntimeException(t);
} finally {
_pauseWarmup.decrementAndGet();
}
}
});
opening.put(shard, submit);
}
}
for (Entry<String, Future<BlurIndex>> entry : opening.entrySet()) {
String shard = entry.getKey();
Future<BlurIndex> future = entry.getValue();
try {
BlurIndex blurIndex = future.get();
tableIndexes.put(shard, blurIndex);
} catch (Exception e) {
e.printStackTrace();
LOG.error("Unknown error while opening shard [{0}] for table [{1}].", e.getCause(), shard, table);
}
}
Map<String, BlurIndex> result = new HashMap<String, BlurIndex>();
for (String shard : shardsToServe) {
BlurIndex blurIndex = tableIndexes.get(shard);
if (blurIndex == null) {
LOG.error("Missing shard [{0}] for table [{1}].", shard, table);
} else {
result.put(shard, blurIndex);
}