brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [12/18] git commit: fix race condition in CB startup
Date Tue, 07 Oct 2014 23:59:51 GMT
fix race condition in CB startup


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/57547287
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/57547287
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/57547287

Branch: refs/heads/master
Commit: 575472870bc26e7084252628b5e95848e591d9df
Parents: de70848
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Oct 7 00:08:52 2014 -0700
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Oct 7 00:09:56 2014 -0700

----------------------------------------------------------------------
 .../nosql/couchbase/CouchbaseClusterImpl.java   | 21 ++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/57547287/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
index 9b7595c..d674285 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
@@ -65,6 +65,7 @@ import brooklyn.util.task.Tasks;
 import brooklyn.util.text.ByteSizeStrings;
 import brooklyn.util.text.StringFunctions;
 import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
 import brooklyn.util.time.Time;
 
 import com.google.common.base.Function;
@@ -207,10 +208,9 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements
Couchbas
             setAttribute(COUCHBASE_PRIMARY_NODE, primaryNode);
 
             Set<Entity> serversToAdd = MutableSet.<Entity>copyOf(getUpNodes());
-            serversToAdd.remove(getPrimaryNode());
 
-            if (getUpNodes().size() >= getQuorumSize() && getUpNodes().size()
> 1) {
-                log.info("number of SERVICE_UP nodes:{} in cluster:{} reached Quorum:{},
adding the servers", new Object[]{getUpNodes().size(), getId(), getQuorumSize()});
+            if (serversToAdd.size() >= getQuorumSize() && serversToAdd.size()
> 1) {
+                log.info("number of SERVICE_UP nodes:{} in cluster:{} reached Quorum:{},
adding the servers", new Object[]{serversToAdd.size(), getId(), getQuorumSize()});
                 addServers(serversToAdd);
 
                 //wait for servers to be added to the couchbase server
@@ -414,15 +414,24 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements
Couchbas
     
     protected void addServers(Set<Entity> serversToAdd) {
         Preconditions.checkNotNull(serversToAdd);
-        for (Entity e : serversToAdd) {
-            if (!isMemberInCluster(e)) {
-                addServer(e);
+        for (Entity s : serversToAdd) {
+            try {
+                addServer(s);
+            } catch (Exception e) {
+                Exceptions.propagateIfFatal(e);
+                // retry once after sleep because we are getting some odd primary-change
events
+                Time.sleep(Duration.TEN_SECONDS);
+                addServer(s);
             }
         }
     }
 
     protected void addServer(Entity serverToAdd) {
         Preconditions.checkNotNull(serverToAdd);
+        if (serverToAdd.equals(getPrimaryNode())) {
+            // no need to add; but we pass it in anyway because it makes the calling logic
easier
+            return;
+        }
         if (!isMemberInCluster(serverToAdd)) {
             HostAndPort webAdmin = BrooklynAccessUtils.getBrooklynAccessibleAddress(serverToAdd,
serverToAdd.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT));
             String username = serverToAdd.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME);


Mime
View raw message