You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2016/01/14 15:00:07 UTC

svn commit: r1724613 - in /qpid/java/branches/6.0.x: ./ bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/ bdbstore/src/test/java/org/apache/qpid/server/store/berk...

Author: orudyy
Date: Thu Jan 14 14:00:07 2016
New Revision: 1724613

URL: http://svn.apache.org/viewvc?rev=1724613&view=rev
Log:
QPID-6959: Restore environment mutating operations on BDB HA VHN when environment is restarting

           merged from trunk
           svn merge -c 1722246 https://svn.apache.org/repos/asf/qpid/java/trunk
           svn merge -c 1723194 https://svn.apache.org/repos/asf/qpid/java/trunk
           svn merge -c 1723563 https://svn.apache.org/repos/asf/qpid/java/trunk

Modified:
    qpid/java/branches/6.0.x/   (props changed)
    qpid/java/branches/6.0.x/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
    qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
    qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java
    qpid/java/branches/6.0.x/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/TwoNodeTest.java

Propchange: qpid/java/branches/6.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 14 14:00:07 2016
@@ -9,5 +9,5 @@
 /qpid/branches/java-broker-vhost-refactor/java:1493674-1494547
 /qpid/branches/java-network-refactor/qpid/java:805429-821809
 /qpid/branches/qpid-2935/qpid/java:1061302-1072333
-/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1719047,1719051,1720664,1721151,1721198,1722339,1723064,1724216,1724251,1724257,1724397,1724432,1724603
+/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1719047,1719051,1720664,1721151,1721198,1722246,1722339,1723064,1723194,1723563,1724216,1724251,1724257,1724397,1724432,1724603
 /qpid/trunk/qpid:796646-796653

Modified: qpid/java/branches/6.0.x/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java?rev=1724613&r1=1724612&r2=1724613&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java (original)
+++ qpid/java/branches/6.0.x/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java Thu Jan 14 14:00:07 2016
@@ -721,23 +721,34 @@ public class ReplicatedEnvironmentFacade
 
     void setCacheSizeInternal(long cacheSize)
     {
-        try
+        final ReplicatedEnvironment environment = _environment.get();
+        if (environment != null)
         {
-            final ReplicatedEnvironment environment = getEnvironment();
-            final EnvironmentMutableConfig oldConfig = environment.getMutableConfig();
-            final EnvironmentMutableConfig newConfig = oldConfig.setCacheSize(cacheSize);
-            environment.setMutableConfig(newConfig);
+            try
+            {
+                final EnvironmentMutableConfig oldConfig = environment.getMutableConfig();
+                final EnvironmentMutableConfig newConfig = oldConfig.setCacheSize(cacheSize);
+                environment.setMutableConfig(newConfig);
 
-            LOGGER.debug("Node {} cache size has been changed to {}", _prettyGroupNodeName, cacheSize);
-        }
-        catch (RuntimeException e)
-        {
-            RuntimeException handled = handleDatabaseException("Exception on setting cache size", e);
-            if (handled instanceof ConnectionScopedRuntimeException || handled instanceof ServerScopedRuntimeException)
+                LOGGER.debug("Node {} cache size has been changed to {}", _prettyGroupNodeName, cacheSize);
+            }
+            catch (RuntimeException e)
             {
-                throw handled;
+                RuntimeException handled = handleDatabaseException("Exception on setting cache size", e);
+                if (handled instanceof ConnectionScopedRuntimeException || handled instanceof ServerScopedRuntimeException)
+                {
+                    throw handled;
+                }
+                throw new ConnectionScopedRuntimeException("Cannot set cache size to " + cacheSize + " on node " + _prettyGroupNodeName, e);
             }
-            throw new ConnectionScopedRuntimeException("Cannot set cache size to " + cacheSize + " on node " + _prettyGroupNodeName, e);
+        }
+        else
+        {
+            throw new ConnectionScopedRuntimeException("Cannot set cache size to "
+                                                       + cacheSize
+                                                       + " on node "
+                                                       + _prettyGroupNodeName
+                                                       + " as environment does not exist");
         }
     }
 
@@ -858,26 +869,39 @@ public class ReplicatedEnvironmentFacade
 
     void setDesignatedPrimaryInternal(final boolean isPrimary)
     {
-        try
+        ReplicatedEnvironment environment = _environment.get();
+        if (environment != null)
         {
-            ReplicatedEnvironment environment = getEnvironment();
-            final ReplicationMutableConfig oldConfig = environment.getRepMutableConfig();
-            final ReplicationMutableConfig newConfig = oldConfig.setDesignatedPrimary(isPrimary);
-            environment.setRepMutableConfig(newConfig);
+            try
+            {
+                final ReplicationMutableConfig oldConfig = environment.getRepMutableConfig();
+                final ReplicationMutableConfig newConfig = oldConfig.setDesignatedPrimary(isPrimary);
+                environment.setRepMutableConfig(newConfig);
 
-            if (LOGGER.isInfoEnabled())
+                if (LOGGER.isInfoEnabled())
+                {
+                    LOGGER.info("Node " + _prettyGroupNodeName + " successfully set designated primary : " + isPrimary);
+                }
+            }
+            catch (RuntimeException e)
             {
-                LOGGER.info("Node " + _prettyGroupNodeName + " successfully set designated primary : " + isPrimary);
+                RuntimeException handled = handleDatabaseException("Exception on setting designated primary", e);
+                if (handled instanceof ConnectionScopedRuntimeException
+                    || handled instanceof ServerScopedRuntimeException)
+                {
+                    throw handled;
+                }
+                throw new ConnectionScopedRuntimeException("Cannot set designated primary to " +
+                                                           isPrimary + " on node " + _prettyGroupNodeName, handled);
             }
         }
-        catch (RuntimeException e)
+        else
         {
-            RuntimeException handled = handleDatabaseException("Exception on setting designated primary", e);
-            if (handled instanceof ConnectionScopedRuntimeException || handled instanceof ServerScopedRuntimeException)
-            {
-                throw handled;
-            }
-            throw new ConnectionScopedRuntimeException("Cannot set designated primary to " + isPrimary + " on node " + _prettyGroupNodeName, handled);
+            throw new ConnectionScopedRuntimeException("Cannot set designated primary to "
+                                                       + isPrimary
+                                                       + " on node "
+                                                       + _prettyGroupNodeName
+                                                       + " as environment does not exist");
         }
     }
 
@@ -907,26 +931,41 @@ public class ReplicatedEnvironmentFacade
 
     void setPriorityInternal(int priority)
     {
-        try
+        final ReplicatedEnvironment environment = _environment.get();
+        if (environment != null)
         {
-            final ReplicatedEnvironment environment = getEnvironment();
-            final ReplicationMutableConfig oldConfig = environment.getRepMutableConfig();
-            final ReplicationMutableConfig newConfig = oldConfig.setNodePriority(priority);
-            environment.setRepMutableConfig(newConfig);
-
-            if (LOGGER.isDebugEnabled())
+            try
             {
-                LOGGER.debug("Node " + _prettyGroupNodeName + " priority has been changed to " + priority);
+                final ReplicationMutableConfig oldConfig = environment.getRepMutableConfig();
+                final ReplicationMutableConfig newConfig = oldConfig.setNodePriority(priority);
+                environment.setRepMutableConfig(newConfig);
+
+                if (LOGGER.isDebugEnabled())
+                {
+                    LOGGER.debug("Node " + _prettyGroupNodeName + " priority has been changed to " + priority);
+                }
             }
-        }
-        catch (RuntimeException e)
-        {
-            RuntimeException handled = handleDatabaseException("Exception on setting priority", e);
-            if (handled instanceof ConnectionScopedRuntimeException || handled instanceof ServerScopedRuntimeException)
+            catch (RuntimeException e)
             {
-                throw handled;
+                RuntimeException handled = handleDatabaseException("Exception on setting priority", e);
+                if (handled instanceof ConnectionScopedRuntimeException
+                    || handled instanceof ServerScopedRuntimeException)
+                {
+                    throw handled;
+                }
+                throw new ConnectionScopedRuntimeException("Cannot set priority to "
+                                                           + priority
+                                                           + " on node "
+                                                           + _prettyGroupNodeName, e);
             }
-            throw new ConnectionScopedRuntimeException("Cannot set priority to " + priority + " on node " + _prettyGroupNodeName, e);
+        }
+        else
+        {
+            throw new ConnectionScopedRuntimeException("Cannot set priority to "
+                                                       + priority
+                                                       + " on node "
+                                                       + _prettyGroupNodeName
+                                                       + " as environment does not exists");
         }
     }
 
@@ -956,26 +995,44 @@ public class ReplicatedEnvironmentFacade
 
     void setElectableGroupSizeOverrideInternal(int electableGroupOverride)
     {
-        try
+        final ReplicatedEnvironment environment = _environment.get();
+        if (environment != null)
         {
-            final ReplicatedEnvironment environment = getEnvironment();
-            final ReplicationMutableConfig oldConfig = environment.getRepMutableConfig();
-            final ReplicationMutableConfig newConfig = oldConfig.setElectableGroupSizeOverride(electableGroupOverride);
-            environment.setRepMutableConfig(newConfig);
-
-            if (LOGGER.isDebugEnabled())
+            try
             {
-                LOGGER.debug("Node " + _prettyGroupNodeName + " electable group size override has been changed to " + electableGroupOverride);
+                final ReplicationMutableConfig oldConfig = environment.getRepMutableConfig();
+                final ReplicationMutableConfig newConfig = oldConfig.setElectableGroupSizeOverride(electableGroupOverride);
+                environment.setRepMutableConfig(newConfig);
+
+                if (LOGGER.isDebugEnabled())
+                {
+                    LOGGER.debug("Node "
+                                 + _prettyGroupNodeName
+                                 + " electable group size override has been changed to "
+                                 + electableGroupOverride);
+                }
             }
-        }
-        catch (RuntimeException e)
-        {
-            RuntimeException handled = handleDatabaseException("Exception on setting electable group override", e);
-            if (handled instanceof ConnectionScopedRuntimeException || handled instanceof ServerScopedRuntimeException)
+            catch (RuntimeException e)
             {
-                throw handled;
+                RuntimeException handled = handleDatabaseException("Exception on setting electable group override", e);
+                if (handled instanceof ConnectionScopedRuntimeException
+                    || handled instanceof ServerScopedRuntimeException)
+                {
+                    throw handled;
+                }
+                throw new ConnectionScopedRuntimeException("Cannot set electable group size to "
+                                                           + electableGroupOverride
+                                                           + " on node "
+                                                           + _prettyGroupNodeName, e);
             }
-            throw new ConnectionScopedRuntimeException("Cannot set electable group size to " + electableGroupOverride + " on node " + _prettyGroupNodeName, e);
+        }
+        else
+        {
+            throw new ConnectionScopedRuntimeException("Cannot set electable group size to "
+                                                       + electableGroupOverride
+                                                       + " on node "
+                                                       + _prettyGroupNodeName
+                                                       + " as environment does not exists");
         }
     }
 

Modified: qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java?rev=1724613&r1=1724612&r2=1724613&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java (original)
+++ qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java Thu Jan 14 14:00:07 2016
@@ -179,6 +179,48 @@ public class BDBHAVirtualHostNodeTest ex
         assertNotNull("Last known replication transaction id should be set", node.getLastKnownReplicationTransactionId());
     }
 
+    public void testMutableAttributesAfterMajorityLost() throws Exception
+    {
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
+        int node3PortNumber = _portHelper.getNextAvailable();
+
+        String helperAddress = "localhost:" + node1PortNumber;
+        String groupName = "group";
+        String nodeName = "node1";
+
+        Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber, node3PortNumber);
+        BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
+
+        Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
+        BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes);
+
+        Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3", groupName, "localhost:" + node3PortNumber, helperAddress, nodeName);
+        BDBHAVirtualHostNode<?> node3 = _helper.createAndStartHaVHN(node3Attributes);
+
+        assertEquals("Unexpected node priority value before mutation", 1, node1.getPriority());
+        assertFalse("Unexpected designated primary value before mutation", node1.isDesignatedPrimary());
+        assertEquals("Unexpected electable group override value before mutation", 0, node1.getQuorumOverride());
+
+        node2.close();
+        node3.close();
+
+        _helper.assertNodeRole(node1, NodeRole.DETACHED);
+
+        Map<String, Object> attributes = new HashMap<>();
+        attributes.put(BDBHAVirtualHostNode.PRIORITY, 200);
+        attributes.put(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true);
+        attributes.put(BDBHAVirtualHostNode.QUORUM_OVERRIDE, 1);
+        node1.setAttributes(attributes);
+
+        _helper.awaitForVirtualhost(node1, 30000);
+
+        assertEquals("Unexpected node priority value after mutation", 200, node1.getPriority());
+        assertTrue("Unexpected designated primary value after mutation", node1.isDesignatedPrimary());
+        assertEquals("Unexpected electable group override value after mutation", 1, node1.getQuorumOverride());
+
+    }
+
     public void testTransferMasterToSelf() throws Exception
     {
         int node1PortNumber = _portHelper.getNextAvailable();

Modified: qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java?rev=1724613&r1=1724612&r2=1724613&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java (original)
+++ qpid/java/branches/6.0.x/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java Thu Jan 14 14:00:07 2016
@@ -926,6 +926,91 @@ public class ReplicatedEnvironmentFacade
         }
     }
 
+    public void testSetElectableGroupSizeOverrideAfterMajorityLost()  throws Exception
+    {
+        final CountDownLatch recoveredLatch = new CountDownLatch(1);
+        final CountDownLatch majorityLost = new CountDownLatch(1);
+        ReplicationGroupListener listener = new NoopReplicationGroupListener()
+        {
+            @Override
+            public void onNoMajority()
+            {
+                majorityLost.countDown();
+            }
+
+            @Override
+            public void onReplicationNodeRecovered(ReplicationNode node)
+            {
+                if (node.getName().equals(TEST_NODE_NAME))
+                {
+                    recoveredLatch.countDown();
+                }
+            }
+        };
+        ReplicatedEnvironmentFacade master = createMaster(listener);
+
+
+        int replica1Port = _portHelper.getNextAvailable();
+        String node1NodeHostPort = "localhost:" + replica1Port;
+        int replica2Port = _portHelper.getNextAvailable();
+        String node2NodeHostPort = "localhost:" + replica2Port;
+
+        master.setPermittedNodes(Arrays.asList(master.getHostPort(), node1NodeHostPort, node2NodeHostPort));
+
+        ReplicatedEnvironmentFacade replica1 = createReplica(TEST_NODE_NAME + "_1", node1NodeHostPort, new NoopReplicationGroupListener());
+        ReplicatedEnvironmentFacade replica2 = createReplica(TEST_NODE_NAME + "_2", node2NodeHostPort, new NoopReplicationGroupListener());
+
+        replica1.close();
+        replica2.close();
+
+        assertTrue("Majority lost is undetected", majorityLost.await(2, TimeUnit.SECONDS));
+        assertEquals("Unexpected facade state", ReplicatedEnvironmentFacade.State.RESTARTING, master.getFacadeState());
+        assertEquals("Master node should not be recovered", 1, recoveredLatch.getCount());
+        master.setElectableGroupSizeOverride(1);
+        assertTrue("Master was not recovered after electable group override change", majorityLost.await(2, TimeUnit.SECONDS));
+    }
+
+    public void testSetDesignatedPrimaryAfterMajorityLost()  throws Exception
+    {
+        final CountDownLatch recoveredLatch = new CountDownLatch(1);
+        final CountDownLatch majorityLost = new CountDownLatch(1);
+        ReplicationGroupListener listener = new NoopReplicationGroupListener()
+        {
+            @Override
+            public void onNoMajority()
+            {
+                majorityLost.countDown();
+            }
+
+            @Override
+            public void onReplicationNodeRecovered(ReplicationNode node)
+            {
+                if (node.getName().equals(TEST_NODE_NAME))
+                {
+                    recoveredLatch.countDown();
+                }
+            }
+        };
+        ReplicatedEnvironmentFacade master = createMaster(listener);
+
+
+        int replica1Port = _portHelper.getNextAvailable();
+        String node1NodeHostPort = "localhost:" + replica1Port;
+        int replica2Port = _portHelper.getNextAvailable();
+        String node2NodeHostPort = "localhost:" + replica2Port;
+
+        master.setPermittedNodes(Arrays.asList(master.getHostPort(), node1NodeHostPort, node2NodeHostPort));
+
+        ReplicatedEnvironmentFacade replica1 = createReplica(TEST_NODE_NAME + "_1", node1NodeHostPort, new NoopReplicationGroupListener());
+        replica1.close();
+
+        assertTrue("Majority lost is undetected", majorityLost.await(2, TimeUnit.SECONDS));
+        assertEquals("Unexpected facade state", ReplicatedEnvironmentFacade.State.RESTARTING, master.getFacadeState());
+        assertEquals("Master node should not be recovered", 1, recoveredLatch.getCount());
+        master.setDesignatedPrimary(true);
+        assertTrue("Master was not recovered after being assigned as designated primary", majorityLost.await(2, TimeUnit.SECONDS));
+    }
+
     private void putRecord(final ReplicatedEnvironmentFacade master, final Database db, final int keyValue,
                            final String dataValue)
     {

Modified: qpid/java/branches/6.0.x/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/TwoNodeTest.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/TwoNodeTest.java?rev=1724613&r1=1724612&r2=1724613&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/TwoNodeTest.java (original)
+++ qpid/java/branches/6.0.x/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/TwoNodeTest.java Thu Jan 14 14:00:07 2016
@@ -181,4 +181,21 @@ public class TwoNodeTest extends QpidBro
         assertProducingConsuming(connection);
     }
 
+    public void testSetDesignatedAfterReplicaBeingStopped() throws Exception
+    {
+        startCluster(false);
+
+        _groupCreator.stopNode(_groupCreator.getBrokerPortNumberOfSecondaryNode());
+
+        Map<String, Object> secondaryNodeAttributes = _groupCreator.getNodeAttributes(_groupCreator.getBrokerPortNumberOfPrimary());
+        assertFalse("Expected node to NOT be set as designated primary", (Boolean) secondaryNodeAttributes.get(BDBHAVirtualHostNode.DESIGNATED_PRIMARY));
+
+        _groupCreator.setNodeAttributes(_groupCreator.getBrokerPortNumberOfPrimary(), Collections.<String, Object>singletonMap(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true));
+        _groupCreator.awaitNodeToAttainRole(_groupCreator.getBrokerPortNumberOfPrimary(), "MASTER" );
+
+        final Connection connection = getConnection(_positiveFailoverUrl);
+        assertNotNull("Expected to get a valid connection to primary", connection);
+        assertProducingConsuming(connection);
+    }
+
 }



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