Follow-up to CASSANDRA-10238

call invalidateCacheRings when topology is updated

patch by Stefania Alborghetti; reviewed by Branimir Lambov for
CASSANDRA-10238
This commit is contained in:
Stefania Alborghetti 2015-09-18 08:57:53 +08:00 committed by Aleksey Yeschenko
parent 6f8e07ab06
commit c4de752758
4 changed files with 19 additions and 10 deletions

View File

@ -59,7 +59,7 @@ public class PropertyFileSnitch extends AbstractNetworkTopologySnitch
public PropertyFileSnitch() throws ConfigurationException public PropertyFileSnitch() throws ConfigurationException
{ {
reloadConfiguration(); reloadConfiguration(false);
try try
{ {
@ -68,8 +68,7 @@ public class PropertyFileSnitch extends AbstractNetworkTopologySnitch
{ {
protected void runMayThrow() throws ConfigurationException protected void runMayThrow() throws ConfigurationException
{ {
reloadConfiguration(); reloadConfiguration(true);
StorageService.instance.updateTopology();
} }
}; };
ResourceWatcher.watch(SNITCH_PROPERTIES_FILENAME, runnable, 60 * 1000); ResourceWatcher.watch(SNITCH_PROPERTIES_FILENAME, runnable, 60 * 1000);
@ -131,7 +130,7 @@ public class PropertyFileSnitch extends AbstractNetworkTopologySnitch
return info[1]; return info[1];
} }
public void reloadConfiguration() throws ConfigurationException public void reloadConfiguration(boolean isUpdate) throws ConfigurationException
{ {
HashMap<InetAddress, String[]> reloadedMap = new HashMap<InetAddress, String[]>(); HashMap<InetAddress, String[]> reloadedMap = new HashMap<InetAddress, String[]>();
@ -198,7 +197,12 @@ public class PropertyFileSnitch extends AbstractNetworkTopologySnitch
endpointMap = reloadedMap; endpointMap = reloadedMap;
if (StorageService.instance != null) // null check tolerates circular dependency; see CASSANDRA-4145 if (StorageService.instance != null) // null check tolerates circular dependency; see CASSANDRA-4145
StorageService.instance.getTokenMetadata().invalidateCachedRings(); {
if (isUpdate)
StorageService.instance.updateTopology();
else
StorageService.instance.getTokenMetadata().invalidateCachedRings();
}
if (gossipStarted) if (gossipStarted)
StorageService.instance.gossipSnitchInfo(); StorageService.instance.gossipSnitchInfo();

View File

@ -413,6 +413,7 @@ public class TokenMetadata
{ {
logger.info("Updating topology for {}", endpoint); logger.info("Updating topology for {}", endpoint);
topology.updateEndpoint(endpoint); topology.updateEndpoint(endpoint);
invalidateCachedRings();
} }
finally finally
{ {
@ -431,6 +432,7 @@ public class TokenMetadata
{ {
logger.info("Updating topology for all endpoints that have changed"); logger.info("Updating topology for all endpoints that have changed");
topology.updateEndpoints(); topology.updateEndpoints();
invalidateCachedRings();
} }
finally finally
{ {

View File

@ -103,7 +103,7 @@ public class YamlFileNetworkTopologySnitch
throws ConfigurationException throws ConfigurationException
{ {
this.topologyConfigFilename = topologyConfigFilename; this.topologyConfigFilename = topologyConfigFilename;
loadTopologyConfiguration(); loadTopologyConfiguration(false);
try try
{ {
@ -119,8 +119,7 @@ public class YamlFileNetworkTopologySnitch
*/ */
protected void runMayThrow() throws ConfigurationException protected void runMayThrow() throws ConfigurationException
{ {
loadTopologyConfiguration(); loadTopologyConfiguration(true);
StorageService.instance.updateTopology();
} }
}; };
ResourceWatcher.watch(topologyConfigFilename, runnable, ResourceWatcher.watch(topologyConfigFilename, runnable,
@ -202,7 +201,7 @@ public class YamlFileNetworkTopologySnitch
* @throws ConfigurationException * @throws ConfigurationException
* on failure * on failure
*/ */
private synchronized void loadTopologyConfiguration() private synchronized void loadTopologyConfiguration(boolean isUpdate)
throws ConfigurationException throws ConfigurationException
{ {
logger.debug("Loading topology configuration from {}", logger.debug("Loading topology configuration from {}",
@ -354,6 +353,9 @@ public class YamlFileNetworkTopologySnitch
{ {
StorageService.instance.gossipSnitchInfo(); StorageService.instance.gossipSnitchInfo();
} }
if (isUpdate && StorageService.instance != null)
StorageService.instance.updateTopology();
} }
/** /**

View File

@ -1411,7 +1411,6 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
public void updateTopology() public void updateTopology()
{ {
getTokenMetadata().updateTopology(); getTokenMetadata().updateTopology();
} }
private void updatePeerInfo(InetAddress endpoint) private void updatePeerInfo(InetAddress endpoint)
@ -3670,6 +3669,8 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
if (oldSnitch instanceof DynamicEndpointSnitch) if (oldSnitch instanceof DynamicEndpointSnitch)
((DynamicEndpointSnitch)oldSnitch).unregisterMBean(); ((DynamicEndpointSnitch)oldSnitch).unregisterMBean();
updateTopology();
} }
/** /**