You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2014/09/04 16:29:16 UTC

svn commit: r1622488 - /qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java

Author: kwall
Date: Thu Sep  4 14:29:16 2014
New Revision: 1622488

URL: http://svn.apache.org/r1622488
Log:
QPID-6063: [Java Broker]  BDB HA - report node role correctly after node restart in group without quorum or node error

* if a node is restarted but there are too few nodes attached to achieve quorum, the role is now reported as WAITING (previously it was erroneously reported as DETACHED)
* if a node goes into error state (for example in response to an intruder), the role is now reported as DETACHED (previously it continued to report its previous role)

Modified:
    qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java

Modified: qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java?rev=1622488&r1=1622487&r2=1622488&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java (original)
+++ qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java Thu Sep  4 14:29:16 2014
@@ -95,7 +95,7 @@ public class BDBHAVirtualHostNodeImpl ex
 
     private final AtomicReference<ReplicatedEnvironmentFacade> _environmentFacade = new AtomicReference<>();
 
-    private final AtomicReference<NodeRole> _lastReplicatedEnvironmentState = new AtomicReference<>(NodeRole.WAITING);
+    private final AtomicReference<NodeRole> _lastRole = new AtomicReference<>(NodeRole.DETACHED);
     private BDBHAVirtualHostNodeLogSubject _virtualHostNodeLogSubject;
     private GroupLogSubject _groupLogSubject;
     private String _virtualHostNodePrincipalName;
@@ -206,7 +206,7 @@ public class BDBHAVirtualHostNodeImpl ex
     @Override
     public NodeRole getRole()
     {
-        return _lastReplicatedEnvironmentState.get();
+        return _lastRole.get();
     }
 
     @Override
@@ -316,6 +316,12 @@ public class BDBHAVirtualHostNodeImpl ex
             LOGGER.debug("Activating virtualhost node " + this);
         }
 
+        // activating the environment does not cause a state change.  Adjust the role
+        // so that our observers will see WAITING rather than our previous role in the group.
+        // the role will change again after the election at which point it will become master or replica.
+        _lastRole.set(NodeRole.WAITING);
+        attributeSet(ROLE, _role, NodeRole.WAITING);
+
         getConfigurationStore().openConfigurationStore(this, false);
 
         getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.CREATED());
@@ -348,7 +354,7 @@ public class BDBHAVirtualHostNodeImpl ex
 
             // closing the environment does not cause a state change.  Adjust the role
             // so that our observers will see DETACHED rather than our previous role in the group.
-            _lastReplicatedEnvironmentState.set(NodeRole.DETACHED);
+            _lastRole.set(NodeRole.DETACHED);
             attributeSet(ROLE, _role, NodeRole.DETACHED);
         }
     }
@@ -596,8 +602,8 @@ public class BDBHAVirtualHostNodeImpl ex
             finally
             {
                 NodeRole newRole = NodeRole.fromJeState(state);
-                _lastReplicatedEnvironmentState.set(newRole);
-                attributeSet(ROLE, _role, state.name());
+                _lastRole.set(newRole);
+                attributeSet(ROLE, _role, newRole);
                 getEventLogger().message(getGroupLogSubject(),
                         HighAvailabilityMessages.ROLE_CHANGED(getName(), getAddress(), previousRole.name(), newRole.name()));
             }
@@ -951,8 +957,13 @@ public class BDBHAVirtualHostNodeImpl ex
             }
             else
             {
-                LOGGER.error(String.format("Intruder node '%s' from '%s' detected. Shutting down virtual host node '%s' based on permitted nodes '%s'",
-                        node.getName(), hostAndPort, BDBHAVirtualHostNodeImpl.this.getName(), String.valueOf(BDBHAVirtualHostNodeImpl.this.getPermittedNodes()) ));
+                LOGGER.error(String.format("Intruder node '%s' from '%s' detected. Shutting down virtual host node " +
+                                           "'%s' (last role %s) owing to the presence of a node not in permitted nodes '%s'",
+                                           node.getName(),
+                                           hostAndPort,
+                                           BDBHAVirtualHostNodeImpl.this.getName(),
+                                           _lastRole.get(),
+                                           String.valueOf(BDBHAVirtualHostNodeImpl.this.getPermittedNodes()) ));
 
                 getTaskExecutor().submit(new Task<Void>()
                 {
@@ -973,6 +984,9 @@ public class BDBHAVirtualHostNodeImpl ex
                             finally
                             {
                                 closeEnvironment();
+
+                                _lastRole.set(NodeRole.DETACHED);
+                                attributeSet(ROLE, _role, NodeRole.DETACHED);
                             }
                             notifyStateChanged(state, State.ERRORED);
                         }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org