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 2015/08/31 19:21:24 UTC
svn commit: r1700280 - in /qpid/java/trunk/bdbstore/src:
main/java/org/apache/qpid/server/store/berkeleydb/
main/java/org/apache/qpid/server/store/berkeleydb/replication/
main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/
test/java/org/apache...
Author: orudyy
Date: Mon Aug 31 17:21:23 2015
New Revision: 1700280
URL: http://svn.apache.org/r1700280
Log:
QPID-6710: [Java Broker] Rely on JE exceptions thrown for invalid environment and handle them in order to restart environment as early as possible
( work by Lorenz Quack <qu...@gmail.com> and Alex Rudyy <or...@gmail.com>)
Modified:
qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacade.java
qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeImpl.java
qpid/java/trunk/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeTest.java
Modified: qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacade.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacade.java?rev=1700280&r1=1700279&r2=1700280&view=diff
==============================================================================
--- qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacade.java (original)
+++ qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacade.java Mon Aug 31 17:21:23 2015
@@ -281,10 +281,6 @@ public class StandardEnvironmentFacade i
{
throw new IllegalStateException("Environment is null.");
}
- else if (!environment.isValid())
- {
- throw new IllegalStateException("Environment is invalid.");
- }
return environment;
}
Modified: qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java?rev=1700280&r1=1700279&r2=1700280&view=diff
==============================================================================
--- qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java (original)
+++ qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java Mon Aug 31 17:21:23 2015
@@ -711,8 +711,16 @@ public class ReplicatedEnvironmentFacade
{
return ReplicatedEnvironment.State.UNKNOWN.name();
}
- ReplicatedEnvironment.State state = getEnvironment().getState();
- return state.toString();
+
+ try
+ {
+ ReplicatedEnvironment.State state = getEnvironment().getState();
+ return state.toString();
+ }
+ catch (RuntimeException e)
+ {
+ throw handleDatabaseException("Cannot get environment state", e);
+ }
}
public boolean isDesignatedPrimary()
@@ -756,9 +764,14 @@ public class ReplicatedEnvironmentFacade
LOGGER.info("Node " + _prettyGroupNodeName + " successfully set designated primary : " + isPrimary);
}
}
- catch (Exception e)
+ catch (RuntimeException e)
{
- throw new ConnectionScopedRuntimeException("Cannot set designated primary to " + isPrimary + " on node " + _prettyGroupNodeName, e);
+ 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);
}
}
@@ -804,8 +817,13 @@ public class ReplicatedEnvironmentFacade
LOGGER.debug("Node " + _prettyGroupNodeName + " priority has been changed to " + priority);
}
}
- catch (Exception e)
+ catch (RuntimeException e)
{
+ 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);
}
}
@@ -852,8 +870,13 @@ public class ReplicatedEnvironmentFacade
LOGGER.debug("Node " + _prettyGroupNodeName + " electable group size override has been changed to " + electableGroupOverride);
}
}
- catch (Exception e)
+ catch (RuntimeException e)
{
+ 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);
}
}
@@ -882,20 +905,33 @@ public class ReplicatedEnvironmentFacade
LOGGER.debug("The mastership has been transferred to " + newMaster);
}
}
- catch (DatabaseException e)
+ catch (RuntimeException e)
{
- LOGGER.warn("Exception on transferring the mastership to " + _prettyGroupNodeName
- + " Master transfer timeout : " + _masterTransferTimeout, e);
- throw e;
+ String message = "Exception on transferring the mastership to " + _prettyGroupNodeName
+ + " Master transfer timeout : " + _masterTransferTimeout;
+ LOGGER.warn(message, e);
+ throw handleDatabaseException(message, e);
}
return null;
}
});
}
- public void removeNodeFromGroup(final String nodeName)
+ public boolean removeNodeFromGroup(final String nodeName)
{
- createReplicationGroupAdmin().removeMember(nodeName);
+ try
+ {
+ createReplicationGroupAdmin().removeMember(nodeName);
+ return true;
+ }
+ catch(MasterStateException e)
+ {
+ return false;
+ }
+ catch(RuntimeException e)
+ {
+ throw handleDatabaseException("Exception on node removal from group", e);
+ }
}
public long getJoinTime()
@@ -907,9 +943,16 @@ public class ReplicatedEnvironmentFacade
{
if (_state.get() == State.OPEN)
{
- VLSNRange range = RepInternal.getRepImpl(getEnvironment()).getVLSNIndex().getRange();
- VLSN lastTxnEnd = range.getLastTxnEnd();
- return lastTxnEnd.getSequence();
+ try
+ {
+ VLSNRange range = RepInternal.getRepImpl(getEnvironment()).getVLSNIndex().getRange();
+ VLSN lastTxnEnd = range.getLastTxnEnd();
+ return lastTxnEnd.getSequence();
+ }
+ catch (RuntimeException e)
+ {
+ throw handleDatabaseException("Exception on getting last known replication transaction id", e);
+ }
}
else
{
@@ -930,17 +973,18 @@ public class ReplicatedEnvironmentFacade
private ReplicatedEnvironment getEnvironment()
{
+ if (getFacadeState() == State.RESTARTING)
+ {
+ throw new ConnectionScopedRuntimeException("Environment is restarting");
+ }
+
final ReplicatedEnvironment environment = _environment.get();
if (environment == null)
{
throw new IllegalStateException("Environment is null.");
}
- else if (!environment.isValid())
- {
- throw new IllegalStateException("Environment is invalid.");
- }
- return environment;
+ return environment;
}
@Override
@@ -1306,7 +1350,15 @@ public class ReplicatedEnvironmentFacade
{
throw new IllegalStateException("Environment facade is not opened");
}
- return getEnvironment().getGroup().getElectableNodes().size();
+
+ try
+ {
+ return getEnvironment().getGroup().getElectableNodes().size();
+ }
+ catch(RuntimeException e)
+ {
+ throw handleDatabaseException("Exception on getting number of electable group members", e);
+ }
}
public boolean isMaster()
@@ -1469,7 +1521,14 @@ public class ReplicatedEnvironmentFacade
if (!permittedNodes.isEmpty())
{
byte[] data = permittedNodeListToBytes(permittedNodes);
- getEnvironment().registerAppStateMonitor(new EnvironmentStateHolder(data));
+ try
+ {
+ getEnvironment().registerAppStateMonitor(new EnvironmentStateHolder(data));
+ }
+ catch (RuntimeException e)
+ {
+ throw handleDatabaseException("Exception on registering app state monitor", e);
+ }
}
}
@@ -1605,19 +1664,16 @@ public class ReplicatedEnvironmentFacade
{
handleDatabaseException("Exception on replication group check", e);
}
-
if (continueMonitoring)
{
- // TODO: this code block does not seem to handle exceptions correctly.
- boolean currentDesignatedPrimary = isDesignatedPrimary();
- int currentElectableGroupSizeOverride = getElectableGroupSizeOverride();
Map<ReplicationNode, NodeState> nodeStates = discoverNodeStates(_remoteReplicationNodes.values());
- executeDatabasePingerOnNodeChangesIfMaster(nodeStates, currentDesignatedPrimary, currentElectableGroupSizeOverride);
+ executeDatabasePingerOnNodeChangesIfMaster(nodeStates);
notifyGroupListenerAboutNodeStates(nodeStates);
}
+
}
}
finally
@@ -1801,37 +1857,42 @@ public class ReplicatedEnvironmentFacade
* still available. This allows us to discover if quorum is lost in a timely manner, rather than
* having to await the next user transaction.
*/
- private void executeDatabasePingerOnNodeChangesIfMaster(final Map<ReplicationNode, NodeState> nodeStates,
- final boolean currentDesignatedPrimary,
- final int currentElectableGroupSizeOverride)
+ private void executeDatabasePingerOnNodeChangesIfMaster(final Map<ReplicationNode, NodeState> nodeStates)
{
- if (ReplicatedEnvironment.State.MASTER == getEnvironment().getState())
+ try
{
- Map<String, ReplicatedEnvironment.State> currentGroupState = new HashMap<>();
- for (Map.Entry<ReplicationNode, NodeState> entry : nodeStates.entrySet())
+ if (ReplicatedEnvironment.State.MASTER == getEnvironment().getState())
{
- ReplicationNode node = entry.getKey();
- NodeState nodeState = entry.getValue();
- ReplicatedEnvironment.State state = nodeState == null? ReplicatedEnvironment.State.UNKNOWN : nodeState.getNodeState();
- currentGroupState.put(node.getName(), state);
- }
-
- ReplicatedEnvironmentFacade.this.isDesignatedPrimary();
- ReplicatedEnvironmentFacade.this.getElectableGroupSizeOverride();
+ Map<String, ReplicatedEnvironment.State> currentGroupState = new HashMap<>();
+ for (Map.Entry<ReplicationNode, NodeState> entry : nodeStates.entrySet())
+ {
+ ReplicationNode node = entry.getKey();
+ NodeState nodeState = entry.getValue();
+ ReplicatedEnvironment.State state = nodeState == null ? ReplicatedEnvironment.State.UNKNOWN : nodeState.getNodeState();
+ currentGroupState.put(node.getName(), state);
+ }
- boolean stateChanged = !_previousGroupState.equals(currentGroupState)
- || currentDesignatedPrimary != _previousDesignatedPrimary
- || currentElectableGroupSizeOverride != _previousElectableGroupOverride;
+ boolean currentDesignatedPrimary = ReplicatedEnvironmentFacade.this.isDesignatedPrimary();
+ int currentElectableGroupSizeOverride = ReplicatedEnvironmentFacade.this.getElectableGroupSizeOverride();
- _previousGroupState = currentGroupState;
- _previousDesignatedPrimary = currentDesignatedPrimary;
- _previousElectableGroupOverride = currentElectableGroupSizeOverride;
+ boolean stateChanged = !_previousGroupState.equals(currentGroupState)
+ || currentDesignatedPrimary != _previousDesignatedPrimary
+ || currentElectableGroupSizeOverride != _previousElectableGroupOverride;
+
+ _previousGroupState = currentGroupState;
+ _previousDesignatedPrimary = currentDesignatedPrimary;
+ _previousElectableGroupOverride = currentElectableGroupSizeOverride;
- if (stateChanged && State.OPEN == _state.get())
- {
- new DatabasePinger().pingDb(ReplicatedEnvironmentFacade.this);
+ if (stateChanged && State.OPEN == _state.get())
+ {
+ new DatabasePinger().pingDb(ReplicatedEnvironmentFacade.this);
+ }
}
}
+ catch(RuntimeException e)
+ {
+ throw handleDatabaseException("Exception on master check", e);
+ }
}
private void notifyGroupListenerAboutNodeStates(final Map<ReplicationNode, NodeState> nodeStates)
Modified: qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeImpl.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeImpl.java?rev=1700280&r1=1700279&r2=1700280&view=diff
==============================================================================
--- qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeImpl.java (original)
+++ qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeImpl.java Mon Aug 31 17:21:23 2015
@@ -43,6 +43,7 @@ import org.apache.qpid.server.model.Stat
import org.apache.qpid.server.model.SystemConfig;
import org.apache.qpid.server.model.VirtualHostNode;
import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade;
+import org.apache.qpid.server.util.ServerScopedRuntimeException;
public class BDBHARemoteReplicationNodeImpl extends AbstractConfiguredObject<BDBHARemoteReplicationNodeImpl> implements BDBHARemoteReplicationNode<BDBHARemoteReplicationNodeImpl>
{
@@ -128,21 +129,30 @@ public class BDBHARemoteReplicationNodeI
getEventLogger().message(_virtualHostNodeLogSubject, HighAvailabilityMessages.DELETED());
+ boolean deletionAllowed;
try
{
- _replicatedEnvironmentFacade.removeNodeFromGroup(nodeName);
- setState(State.DELETED);
- deleted();
+ deletionAllowed = _replicatedEnvironmentFacade.removeNodeFromGroup(nodeName);
}
- catch(MasterStateException e)
+ catch (ServerScopedRuntimeException e)
{
- throw new IllegalStateTransitionException("Node '" + nodeName + "' cannot be deleted when role is a master");
+ throw e;
}
- catch (Exception e)
+ catch (RuntimeException e)
{
throw new IllegalStateTransitionException("Unexpected exception on node '" + nodeName + "' deletion", e);
}
+ if (deletionAllowed)
+ {
+ setState(State.DELETED);
+ deleted();
+ }
+ else
+ {
+ throw new IllegalStateTransitionException("Node '" + nodeName + "' cannot be deleted when role is a master");
+ }
+
return Futures.immediateFuture(null);
}
Modified: qpid/java/trunk/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeTest.java?rev=1700280&r1=1700279&r2=1700280&view=diff
==============================================================================
--- qpid/java/trunk/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeTest.java (original)
+++ qpid/java/trunk/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeTest.java Mon Aug 31 17:21:23 2015
@@ -94,6 +94,7 @@ public class BDBHARemoteReplicationNodeT
String remoteReplicationName = getName();
BDBHARemoteReplicationNode remoteReplicationNode = createRemoteReplicationNode(remoteReplicationName);
+ when(_facade.removeNodeFromGroup(remoteReplicationName)).thenReturn(true);
remoteReplicationNode.delete();
verify(_facade).removeNodeFromGroup(remoteReplicationName);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org