SSP doesn't cache seeds forever

Patch by brandonwilliams, reviewed by jbellis for CASSANDRA-7663
This commit is contained in:
Brandon Williams 2014-08-01 10:40:53 -05:00
parent 249bbfc3b2
commit eb92a9fca7
3 changed files with 30 additions and 16 deletions

View File

@ -1,4 +1,5 @@
1.2.19
* SimpleSeedProvider no longer caches seeds forever (CASSANDRA-7663)
* Set correct stream ID on responses when non-Exception Throwables
are thrown while handling native protocol messages (CASSANDRA-7470)
* Fix row size miscalculation in LazilyCompactedRow (CASSANDRA-7543)

View File

@ -103,7 +103,7 @@ public class DatabaseDescriptor
/**
* Inspect the classpath to find storage configuration file
*/
static URL getStorageConfigURL() throws ConfigurationException
public static URL getStorageConfigURL() throws ConfigurationException
{
String configUrl = System.getProperty("cassandra.config");
if (configUrl == null)

View File

@ -17,26 +17,50 @@
*/
package org.apache.cassandra.locator;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.cassandra.config.Config;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.SeedProviderDef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Loader;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
public class SimpleSeedProvider implements SeedProvider
{
private static final Logger logger = LoggerFactory.getLogger(SimpleSeedProvider.class);
private final List<InetAddress> seeds;
public SimpleSeedProvider(Map<String, String> args) {}
public SimpleSeedProvider(Map<String, String> args)
public List<InetAddress> getSeeds()
{
String[] hosts = args.get("seeds").split(",", -1);
seeds = new ArrayList<InetAddress>(hosts.length);
InputStream input;
try
{
URL url = DatabaseDescriptor.getStorageConfigURL();
input = url.openStream();
}
catch (Exception e)
{
throw new AssertionError(e);
}
org.yaml.snakeyaml.constructor.Constructor constructor = new org.yaml.snakeyaml.constructor.Constructor(Config.class);
TypeDescription seedDesc = new TypeDescription(SeedProviderDef.class);
seedDesc.putMapPropertyType("parameters", String.class, String.class);
constructor.addTypeDescription(seedDesc);
Yaml yaml = new Yaml(new Loader(constructor));
Config conf = (Config)yaml.load(input);
String[] hosts = conf.seed_provider.parameters.get("seeds").split(",", -1);
List<InetAddress> seeds = new ArrayList<InetAddress>(hosts.length);
for (String host : hosts)
{
try
@ -49,17 +73,6 @@ public class SimpleSeedProvider implements SeedProvider
logger.warn("Seed provider couldn't lookup host " + host);
}
}
}
public List<InetAddress> getSeeds()
{
return Collections.unmodifiableList(seeds);
}
// future planning?
public void addSeed(InetAddress addr)
{
if (!seeds.contains(addr))
seeds.add(addr);
}
}