SSP doesn't cache seeds forever Patch by brandonwilliams, reviewed by jbellis for CASSANDRA-7663
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/eb92a9fc Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/eb92a9fc Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/eb92a9fc Branch: refs/heads/trunk Commit: eb92a9fca76f51c91c9eebaddfd439897a14a6e0 Parents: 249bbfc Author: Brandon Williams <brandonwilli...@apache.org> Authored: Fri Aug 1 10:40:53 2014 -0500 Committer: Brandon Williams <brandonwilli...@apache.org> Committed: Fri Aug 1 10:40:53 2014 -0500 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/config/DatabaseDescriptor.java | 2 +- .../cassandra/locator/SimpleSeedProvider.java | 43 +++++++++++++------- 3 files changed, 30 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb92a9fc/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 676c4e5..0ad02c1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb92a9fc/src/java/org/apache/cassandra/config/DatabaseDescriptor.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index 1e534f9..3079283 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -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) http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb92a9fc/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java b/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java index a3031fa..9f491f3 100644 --- a/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java +++ b/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java @@ -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); - } }