Skip to content

Commit

Permalink
added failoveronshutdown flag to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
andytaylor committed Dec 8, 2010
1 parent 86f08d9 commit cf3f55e
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 30 deletions.
Expand Up @@ -19,6 +19,9 @@

<shared-store>true</shared-store>

<!--we kill the server process so don't need this set to true-->
<failover-on-shutdown>false</failover-on-shutdown>

<allow-failback>true</allow-failback>
<!-- Connectors -->

Expand Down
Expand Up @@ -19,6 +19,9 @@

<backup>true</backup>

<!--we kill the server process so don't need this set to true-->
<failover-on-shutdown>false</failover-on-shutdown>

<shared-store>true</shared-store>

<allow-failback>true</allow-failback>
Expand Down
Expand Up @@ -20,6 +20,9 @@

<backup>true</backup>

<!--we kill the server process so don't need this set to true-->
<failover-on-shutdown>false</failover-on-shutdown>

<shared-store>true</shared-store>

<allow-failback>true</allow-failback>
Expand Down
Expand Up @@ -4,6 +4,9 @@

<clustered>true</clustered>

<!--we kill the server process so don't need this set to true-->
<failover-on-shutdown>false</failover-on-shutdown>

<shared-store>true</shared-store>
<!-- Connectors -->

Expand Down
Expand Up @@ -4,6 +4,9 @@

<clustered>true</clustered>

<!--we kill the server process so don't need this set to true-->
<failover-on-shutdown>false</failover-on-shutdown>

<backup>true</backup>

<shared-store>true</shared-store>
Expand Down
Expand Up @@ -20,6 +20,9 @@

<backup>true</backup>

<!--we kill the server process so don't need this set to true-->
<failover-on-shutdown>false</failover-on-shutdown>

<shared-store>true</shared-store>

<connectors>
Expand Down
2 changes: 2 additions & 0 deletions src/config/common/schema/hornetq-configuration.xsd
Expand Up @@ -69,6 +69,8 @@
</xsd:element>
<xsd:element maxOccurs="1" minOccurs="0" name="allow-failback" type="xsd:boolean">
</xsd:element>
<xsd:element maxOccurs="1" minOccurs="0" name="failover-on-shutdown" type="xsd:boolean">
</xsd:element>
<xsd:element maxOccurs="1" minOccurs="0" name="shared-store" type="xsd:boolean">
</xsd:element>
<xsd:element maxOccurs="1" minOccurs="0" name="persist-delivery-count-before-delivery" type="xsd:boolean">
Expand Down
2 changes: 2 additions & 0 deletions src/config/trunk/clustered/hornetq-configuration.xml
Expand Up @@ -4,6 +4,8 @@

<clustered>true</clustered>

<failover-on-shutdown>false</failover-on-shutdown>

<shared-store>true</shared-store>

<journal-min-files>10</journal-min-files>
Expand Down
Expand Up @@ -589,4 +589,7 @@ void createBridge(@Parameter(name="name", desc="Name of the bridge") String name

@Operation(desc= "Destroy a bridge", impact = MBeanOperationInfo.ACTION)
void destroyBridge(@Parameter(name="name", desc="Name of the bridge") String name) throws Exception;

@Operation(desc = "force the server to stop and notify clients to failover", impact = MBeanOperationInfo.UNKNOWN)
void forceFailover() throws Exception;
}
11 changes: 11 additions & 0 deletions src/main/org/hornetq/core/config/Configuration.java
Expand Up @@ -399,6 +399,17 @@ public interface Configuration extends Serializable
*/
String getClusterPassword();

/**
* should we notify any clients on close that they should failover
* @return true if clients should failover
*/
boolean isFailoverOnServerShutdown();

/*
* set to allow clients to failover on server shutdown
* */
void setFailoverOnServerShutdown(boolean failoverOnServerShutdown);

/**
* Sets the cluster password for this server.
*/
Expand Down
18 changes: 18 additions & 0 deletions src/main/org/hornetq/core/config/impl/ConfigurationImpl.java
Expand Up @@ -174,6 +174,8 @@ public class ConfigurationImpl implements Configuration

public static final long DEFAULT_SERVER_DUMP_INTERVAL = -1;

private static final boolean DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN = false;

public static final int DEFAULT_MEMORY_WARNING_THRESHOLD = 25;

public static final long DEFAULT_MEMORY_MEASURE_INTERVAL = -1; // in milliseconds
Expand Down Expand Up @@ -316,6 +318,8 @@ public class ConfigurationImpl implements Configuration

protected long serverDumpInterval = ConfigurationImpl.DEFAULT_SERVER_DUMP_INTERVAL;

protected boolean failoverOnServerShutdown = ConfigurationImpl.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN;

// percentage of free memory which triggers warning from the memory manager
protected int memoryWarningThreshold = ConfigurationImpl.DEFAULT_MEMORY_WARNING_THRESHOLD;

Expand Down Expand Up @@ -879,6 +883,16 @@ public String getClusterPassword()
return clusterPassword;
}

public boolean isFailoverOnServerShutdown()
{
return failoverOnServerShutdown;
}

public void setFailoverOnServerShutdown(boolean failoverOnServerShutdown)
{
this.failoverOnServerShutdown = failoverOnServerShutdown;
}

public void setClusterPassword(final String theclusterPassword)
{
clusterPassword = theclusterPassword;
Expand Down Expand Up @@ -1189,6 +1203,10 @@ else if (!managementAddress.equals(other.managementAddress))
{
return false;
}
if (failoverOnServerShutdown != other.isFailoverOnServerShutdown())
{
return false;
}
if (clusterPassword == null)
{
if (other.clusterPassword != null)
Expand Down
Expand Up @@ -164,6 +164,8 @@ public void parseMainConfig(final Element e, final Configuration config) throws
config.setClustered(XMLConfigurationUtil.getBoolean(e, "clustered", config.isClustered()));

config.setAllowAutoFailBack(XMLConfigurationUtil.getBoolean(e, "allow-failback", config.isClustered()));

config.setFailoverOnServerShutdown(XMLConfigurationUtil.getBoolean(e, "failover-on-shutdown", config.isFailoverOnServerShutdown()));

config.setBackup(XMLConfigurationUtil.getBoolean(e, "backup", config.isBackup()));

Expand Down
Expand Up @@ -1715,6 +1715,21 @@ public void destroyBridge(final String name) throws Exception
}
}

public void forceFailover() throws Exception
{
checkStarted();

clearIO();

try
{
server.stop(true);
}
finally
{
blockOnIO();
}
}
// NotificationEmitter implementation ----------------------------

public void removeNotificationListener(final NotificationListener listener,
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/hornetq/core/server/HornetQServer.java
Expand Up @@ -162,5 +162,5 @@ Queue deployQueue(SimpleString address,

ServerSession getSessionByID(String sessionID);

void kill() throws Exception;
void stop(boolean failoverOnServerShutdown) throws Exception;
}
7 changes: 1 addition & 6 deletions src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
Expand Up @@ -581,14 +581,9 @@ protected void finalize() throws Throwable
super.finalize();
}

public void kill() throws Exception
{
stop(true);
}

public void stop() throws Exception
{
stop(false);
stop(configuration.isFailoverOnServerShutdown());
}

public void stop(boolean failoverOnServerShutdown) throws Exception
Expand Down
Expand Up @@ -155,10 +155,7 @@ public void testFailoverAndReconnectImmediately() throws Exception

BridgeReconnectTest.log.info("** failing connection");
// Now we will simulate a failure of the bridge connection between server0 and server1
/*Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);
RemotingConnection forwardingConnection = getForwardingConnection(bridge);
forwardingConnection.fail(new HornetQException(HornetQException.NOT_CONNECTED));*/
server0.kill();
server0.stop(true);

waitForServerStart(service2);

Expand Down Expand Up @@ -300,7 +297,7 @@ public void testFailoverAndReconnectAfterAFewTries() throws Exception
server1.start();
server0.start();
// Now we will simulate a failure of the bridge connection between server0 and server1
server0.kill();
server0.stop(true);


locator = HornetQClient.createServerLocatorWithHA(server2tc);
Expand Down
Expand Up @@ -348,9 +348,8 @@ protected void failNode(final int node) throws Exception

ClusterManagerImpl clusterManager = (ClusterManagerImpl) server.getClusterManager();
clusterManager.clear();
//FailoverManagerImpl.failAllConnectionsForConnector(serverTC);

server.kill();
server.stop(true);
}

public void testFailAllNodes() throws Exception
Expand Down
Expand Up @@ -87,7 +87,7 @@ public void testGroupingLocalHandlerFails() throws Exception

closeSessionFactory(0);

servers[0].kill();
servers[0].stop(true);

waitForServerRestart(2);

Expand Down Expand Up @@ -176,7 +176,7 @@ public void testGroupingLocalHandlerFailsMultipleGroups() throws Exception

closeSessionFactory(0);

servers[0].kill();
servers[0].stop(true);

waitForServerRestart(2);

Expand Down
Expand Up @@ -97,16 +97,10 @@ public void beforeReconnect(HornetQException exception)
{
session.addFailureListener(new MyListener());
}
/*Set<RemotingConnection> connections = server.getRemotingService().getConnections();
for (RemotingConnection remotingConnection : connections)
{
remotingConnection.destroy();
server.getRemotingService().removeConnection(remotingConnection.getID());
}*/

ClusterManagerImpl clusterManager = (ClusterManagerImpl) server.getClusterManager();
clusterManager.clear();
server.kill();
server.stop(true);


// Wait to be informed of failure
Expand Down
Expand Up @@ -235,16 +235,10 @@ public void beforeReconnect(HornetQException exception)
{
session.addFailureListener(new MyListener());
}
/*Set<RemotingConnection> connections = server.getRemotingService().getConnections();
for (RemotingConnection remotingConnection : connections)
{
remotingConnection.destroy();
server.getRemotingService().removeConnection(remotingConnection.getID());
}*/

ClusterManagerImpl clusterManager = (ClusterManagerImpl)server.getClusterManager();
clusterManager.clear();
server.kill();
server.stop(true);

// Wait to be informed of failure
boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
Expand Down
Expand Up @@ -562,6 +562,11 @@ public void destroyBridge(String name) throws Exception

}

public void forceFailover() throws Exception
{
proxy.invokeOperation("forceFailover");
}

public String getLiveConnectorName() throws Exception
{
return (String)proxy.retrieveAttributeValue("liveConnectorName");
Expand Down

0 comments on commit cf3f55e

Please sign in to comment.