public void run() throws Exception {
// Go over every cluster and rollback one store at a time
for(String clusterUrl: clusterUrls) {
AdminClient adminClient = null;
ExecutorService service = null;
try {
service = Executors.newCachedThreadPool();
adminClient = new AdminClient(clusterUrl,
new AdminClientConfig(),
new ClientConfig());
Cluster cluster = adminClient.getAdminClientCluster();
AdminStoreSwapper swapper = new AdminStoreSwapper(cluster,
service,
adminClient,
1000 * props.getInt("timeout.seconds",
24 * 60 * 60),
true,
true);
// Get the current version for all stores on all nodes
Map<Integer, Map<String, Long>> previousVersions = Maps.newHashMap();
for(Node node: cluster.getNodes()) {
Map<String, Long> currentVersion = adminClient.readonlyOps.getROCurrentVersion(node.getId(),
storeNames);
log.info("Retrieving current version information on node " + node.getId());
Map<String, Long> previousVersion = Maps.newHashMap();
for(Entry<String, Long> entry: currentVersion.entrySet()) {
previousVersion.put(entry.getKey(), entry.getValue() - 1);
if(entry.getValue() == 0) {
throw new VoldemortException("Store '" + entry.getKey() + "' on node "
+ node.getId()
+ " does not have version to rollback to");
}
}
previousVersions.put(node.getId(), previousVersion);
}
// Swap one store at a time
for(String storeName: storeNames) {
for(Node node: cluster.getNodes()) {
log.info("Rolling back data on node " + node.getId() + " and for store "
+ storeName + " to version "
+ previousVersions.get(node.getId()).get(storeName));
swapper.invokeRollback(storeName,
previousVersions.get(node.getId()).get(storeName));
log.info("Successfully rolled back data on node " + node.getId()
+ " and for store " + storeName);
}
}
} finally {
if(service != null) {
service.shutdownNow();
service.awaitTermination(10, TimeUnit.SECONDS);
service = null;
}
if(adminClient != null) {
adminClient.close();
adminClient = null;
}
}
}
}