- if (nodeConnections.putIfAbsent(node, newControllers) != null) {
- log.debug("PutIfAbsent failed {} to {}", controller.getHostAddress(), node.toString());
- /*
- * This check is needed again to take care of the case where some schemes
- * would not allow nodes to be connected to multiple controllers.
- * Hence, if putIfAbsent fails, that means, some other controller is competing
- * with this controller to take hold of a Node.
- */
- if (isConnectionAllowed(node)) {
- log.debug("Trying to replace old={} with new={} for {} to {}", oldControllers.toString(), newControllers.toString(),
- controller.getHostAddress(), node.toString());
- if (!nodeConnections.replace(node, oldControllers, newControllers)) {
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
+ try {
+ clusterServices.tbegin();
+ if (nodeConnections.putIfAbsent(node, newControllers) != null) {
+ log.debug("PutIfAbsent failed {} to {}", controller.getHostAddress(), node.toString());
+ /*
+ * This check is needed again to take care of the case where some schemes
+ * would not allow nodes to be connected to multiple controllers.
+ * Hence, if putIfAbsent fails, that means, some other controller is competing
+ * with this controller to take hold of a Node.
+ */
+ if (isConnectionAllowed(node)) {
+ if (oldControllers == null || !nodeConnections.replace(node, oldControllers, newControllers)) {
+ clusterServices.trollback();
+ try {
+ Thread.sleep(100);
+ } catch ( InterruptedException e) {}
+ log.debug("Retrying ... {} with {}", controller.getHostAddress(), node.toString());
+ return putNodeToController(node, controller);
+ } else {
+ log.debug("Replace successful old={} with new={} for {} to {}", oldControllers.toString(), newControllers.toString(),
+ controller.getHostAddress(), node.toString());