You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2013/06/28 23:06:16 UTC
git commit: Refactor IESCS in Snitches, (part 2 - rework YFNTS) patch
by jasobrown; reviewed by jbellis for CASSANDRA-5681
Updated Branches:
refs/heads/trunk 03ff26874 -> ff339c58c
Refactor IESCS in Snitches, (part 2 - rework YFNTS)
patch by jasobrown; reviewed by jbellis for CASSANDRA-5681
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ff339c58
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ff339c58
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ff339c58
Branch: refs/heads/trunk
Commit: ff339c58cc6726c676039e8a7ed4c2f6a0ea4f14
Parents: 03ff268
Author: Jason Brown <ja...@gmail.com>
Authored: Fri Jun 28 14:04:27 2013 -0700
Committer: Jason Brown <ja...@gmail.com>
Committed: Fri Jun 28 14:04:27 2013 -0700
----------------------------------------------------------------------
.../locator/YamlFileNetworkTopologySnitch.java | 207 +++----------------
.../YamlFileNetworkTopologySnitchTest.java | 17 --
2 files changed, 23 insertions(+), 201 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ff339c58/src/java/org/apache/cassandra/locator/YamlFileNetworkTopologySnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/YamlFileNetworkTopologySnitch.java b/src/java/org/apache/cassandra/locator/YamlFileNetworkTopologySnitch.java
index eb3fd3e..f299b61 100644
--- a/src/java/org/apache/cassandra/locator/YamlFileNetworkTopologySnitch.java
+++ b/src/java/org/apache/cassandra/locator/YamlFileNetworkTopologySnitch.java
@@ -28,10 +28,8 @@ import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.EndpointState;
import org.apache.cassandra.gms.Gossiper;
-import org.apache.cassandra.gms.IEndpointStateChangeSubscriber;
import org.apache.cassandra.gms.VersionedValue;
import org.apache.cassandra.io.util.FileUtils;
-import org.apache.cassandra.net.MessagingService;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.ResourceWatcher;
@@ -57,9 +55,7 @@ public class YamlFileNetworkTopologySnitch
extends AbstractNetworkTopologySnitch
{
- /** Logger. */
- private static final Logger logger = LoggerFactory
- .getLogger(YamlFileNetworkTopologySnitch.class);
+ private static final Logger logger = LoggerFactory.getLogger(YamlFileNetworkTopologySnitch.class);
/**
* How often to check the topology configuration file, in milliseconds; defaults to one minute.
@@ -163,89 +159,6 @@ public class YamlFileNetworkTopologySnitch
}
/**
- * Returns the preferred non-broadcast address for the endpoint, or null if none was specified.
- * <p>
- * Currently, the only preferred address that is considered is the data-center-local address.
- * </p>
- *
- * @param endpoint
- * the broadcast address for the endpoint
- * @return the preferred non-broadcast address for the endpoint, or null if none was specified
- */
- private InetAddress getPreferredAddress(final InetAddress endpoint)
- {
- return getDcLocalAddress(endpoint);
- }
-
- /**
- * Returns the data-center-local address for the endpoint, or null if none was specified.
- *
- * @param endpoint
- * the broadcast address for the endpoint
- * @return the data-center-local address for the endpoint, or null if none was specified
- */
- private InetAddress getDcLocalAddress(final InetAddress endpoint)
- {
- final NodeData nodeData = nodeDataMap.get(endpoint);
- return nodeData != null ? nodeData.dcLocalAddress : null;
- }
-
- /**
- * Reconnects to the endpoint through the preferred non-broadcast address if necessary.
- * <p>
- * A reconnect is performed if
- * <ul>
- * <li>the endpoint is not in the local data center and
- * <li>
- * <li>the endpoint has a configured preferred address as determined by {@link #getPreferredAddress(InetAddress)}.
- * </ul>
- * </p>
- *
- * @param endpoint
- * the endpoint's broadcast address
- */
- private void reconnectViaPreferredAddress(final InetAddress endpoint)
- {
- if (!localNodeData.datacenter.equals(getDatacenter(endpoint)))
- {
- return;
- }
-
- reconnectViaPreferredAddress(endpoint, getPreferredAddress(endpoint));
- }
-
- /**
- * Reconnects to the endpoint through the preferred non-broadcast address if necessary.
- * <p>
- * A reconnect is performed to {@code preferredAddress} if the {@code preferredAddress} argument is not null.
- * </p>
- * <p>
- * This method is only meant to be called by {@link #reconnectViaPreferredAddress(InetAddress)}, but is declared to
- * have package-private scope in order to facilitate unit testing.
- * </p>
- *
- * @param endpoint
- * the endpoint's broadcast address
- * @param preferredAddress
- * the endpoint's preferred address to reconnect to
- */
- void reconnectViaPreferredAddress(final InetAddress endpoint,
- final InetAddress preferredAddress)
- {
- if (preferredAddress == null)
- {
- return;
- }
-
- MessagingService.instance().getConnectionPool(endpoint)
- .reset(preferredAddress);
-
- logger.debug(
- "Initiated reconnect to node with broadcast address {} using preferred address {}",
- endpoint, preferredAddress);
- }
-
- /**
* Root object type for the YAML topology configuration.
*/
public static class TopologyConfig
@@ -427,6 +340,7 @@ public class YamlFileNetworkTopologySnitch
this.nodeDataMap = nodeDataMap;
this.localNodeData = localNodeData;
this.defaultNodeData = defaultNodeData;
+ maybeSetApplicationState();
if (logger.isDebugEnabled())
{
@@ -442,6 +356,26 @@ public class YamlFileNetworkTopologySnitch
}
/**
+ * be careful about just blindly updating ApplicationState.INTERNAL_IP everytime we read the yaml file,
+ * as that can cause connections to get unnecessarily reset (via IESCS.onChange()).
+ */
+ private void maybeSetApplicationState()
+ {
+ if (localNodeData.dcLocalAddress == null)
+ return;
+ final EndpointState es = Gossiper.instance.getEndpointStateForEndpoint(FBUtilities.getBroadcastAddress());
+ if (es == null)
+ return;
+ final VersionedValue vv = es.getApplicationState(ApplicationState.INTERNAL_IP);
+ if ((vv != null && !vv.value.equals(localNodeData.dcLocalAddress.toString()))
+ || vv == null)
+ {
+ Gossiper.instance.addLocalApplicationState(ApplicationState.INTERNAL_IP,
+ StorageService.instance.valueFactory.internalIP(localNodeData.dcLocalAddress.toString()));
+ }
+ }
+
+ /**
* Topology data for a node.
*/
private class NodeData
@@ -474,102 +408,7 @@ public class YamlFileNetworkTopologySnitch
{
gossiperInitialized = true;
StorageService.instance.gossipSnitchInfo();
-
- final IEndpointStateChangeSubscriber escs = new IEndpointStateChangeSubscriber()
- {
-
- /**
- * Called upon a "restart" gossip event; does nothing.
- *
- * @param endpoint
- * the endpoint's broadcast address
- * @param state
- * the endpoint's state
- */
- @Override
- public void onRestart(final InetAddress endpoint,
- final EndpointState state)
- {
- // No-op
- }
-
- /**
- * Called upon a "remove" gossip event; does nothing.
- *
- * @param endpoint
- * the endpoint's broadcast address
- */
- @Override
- public void onRemove(final InetAddress endpoint)
- {
- // No-op
- }
-
- /**
- * Called upon a "join" gossip event; attempts a reconnect to a preferred non-broadcast address if
- * necessary.
- *
- * @param endpoint
- * the endpoint's broadcast address
- * @param epState
- * the endpoint's state
- */
- @Override
- public void onJoin(final InetAddress endpoint,
- final EndpointState epState)
- {
- reconnectViaPreferredAddress(endpoint);
- }
-
- /**
- * Called upon a "dead" gossip event; does nothing.
- *
- * @param endpoint
- * the endpoint's broadcast address
- * @param state
- * the endpoint's state
- */
- @Override
- public void onDead(final InetAddress endpoint,
- final EndpointState state)
- {
- // No-op
- }
-
- /**
- * Called upon a "change" gossip event; does nothing.
- *
- * @param endpoint
- * the endpoint's broadcast address
- * @param state
- * the application state that has changed
- * @param value
- * the new value of the state
- */
- @Override
- public void onChange(final InetAddress endpoint,
- final ApplicationState state, final VersionedValue value)
- {
- reconnectViaPreferredAddress(endpoint);
- }
-
- /**
- * Called upon an "alive" gossip event; attempts a reconnect to a preferred non-broadcast address if
- * necessary.
- *
- * @param endpoint
- * the endpoint's broadcast address
- * @param state
- * the endpoint's state
- */
- @Override
- public void onAlive(final InetAddress endpoint,
- final EndpointState state)
- {
- reconnectViaPreferredAddress(endpoint);
- }
- };
- Gossiper.instance.register(escs);
+ Gossiper.instance.register(new ReconnectableSnitchHelper(this, localNodeData.datacenter, true));
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ff339c58/test/unit/org/apache/cassandra/locator/YamlFileNetworkTopologySnitchTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/locator/YamlFileNetworkTopologySnitchTest.java b/test/unit/org/apache/cassandra/locator/YamlFileNetworkTopologySnitchTest.java
index d5d0c9f..be1c24b 100644
--- a/test/unit/org/apache/cassandra/locator/YamlFileNetworkTopologySnitchTest.java
+++ b/test/unit/org/apache/cassandra/locator/YamlFileNetworkTopologySnitchTest.java
@@ -52,23 +52,6 @@ public class YamlFileNetworkTopologySnitchTest
{
super(topologyConfigFilename);
}
-
- /**
- * Overrides {@link YamlFileNetworkTopologySnitch#reconnectViaPreferredAddress(InetAddress, InetAddress)} to not
- * perform a reconnect.
- *
- * @param endpoint
- * the endpoint's broadcast address
- * @param preferredAddress
- * the endpoint's preferred address to reconnect to
- */
- @Override
- void reconnectViaPreferredAddress(final InetAddress endpoint,
- final InetAddress preferredAddress)
- {
- // No-op
- }
-
}
/**