Author: gdusbabek
Date: Thu Nov 18 17:34:08 2010
New Revision: 1036550
URL: http://svn.apache.org/viewvc?rev=1036550&view=rev
Log:
SeedProvider interface and implementation replaces seeds in DD. patch by
gdusbabek, reviewed by jbellis. CASSANDRA-1669
Added:
cassandra/trunk/src/java/org/apache/cassandra/locator/SeedProvider.java
cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java
Modified:
cassandra/trunk/src/java/org/apache/cassandra/config/Config.java
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
Modified: cassandra/trunk/src/java/org/apache/cassandra/config/Config.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/Config.java?rev=1036550&r1=1036549&r2=1036550&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/Config.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/Config.java Thu Nov 18
17:34:08 2010
@@ -36,7 +36,6 @@ public class Config
public Boolean hinted_handoff_enabled = true;
public SeedProviderDef seed_provider;
- public String[] seeds;
public DiskAccessMode disk_access_mode = DiskAccessMode.auto;
/* Address where to run the job tracker */
Modified:
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=1036550&r1=1036549&r2=1036550&view=diff
==============================================================================
---
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
(original)
+++
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
Thu Nov 18 17:34:08 2010
@@ -61,7 +61,7 @@ public class DatabaseDescriptor
private static IEndpointSnitch snitch;
private static InetAddress listenAddress; // leave null so we can fall
through to getLocalHost
private static InetAddress rpcAddress;
- private static Set<InetAddress> seeds = new HashSet<InetAddress>();
+ private static SeedProvider seedProvider;
/* Current index into the above list of directories */
private static int currentIndex = 0;
private static int consistencyThreads = 4; // not configurable
@@ -364,14 +364,14 @@ public class DatabaseDescriptor
tables.put(Table.SYSTEM_TABLE, systemMeta);
/* Load the seeds for node contact points */
- if (conf.seeds == null || conf.seeds.length <= 0)
+ if (conf.seed_provider == null)
{
- throw new ConfigurationException("seeds missing; a minimum of
one seed is required.");
- }
- for (String seedString : conf.seeds)
- {
- seeds.add(InetAddress.getByName(seedString));
+ throw new ConfigurationException("seeds configuration is
missing; a minimum of one seed is required.");
}
+ Class seedProviderClass =
Class.forName(conf.seed_provider.class_name);
+ seedProvider =
(SeedProvider)seedProviderClass.getConstructor(Map.class).newInstance(conf.seed_provider.parameters);
+ if (seedProvider.getSeeds().size() == 0)
+ throw new ConfigurationException("The seed provider lists no
seeds.");
}
catch (UnknownHostException e)
{
@@ -885,7 +885,7 @@ public class DatabaseDescriptor
public static Set<InetAddress> getSeeds()
{
- return seeds;
+ return Collections.unmodifiableSet(new
HashSet(seedProvider.getSeeds()));
}
/*
Added: cassandra/trunk/src/java/org/apache/cassandra/locator/SeedProvider.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/SeedProvider.java?rev=1036550&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/locator/SeedProvider.java
(added)
+++ cassandra/trunk/src/java/org/apache/cassandra/locator/SeedProvider.java Thu
Nov 18 17:34:08 2010
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.locator;
+
+import java.net.InetAddress;
+import java.util.List;
+
+public interface SeedProvider
+{
+ List<InetAddress> getSeeds();
+}
Added:
cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java?rev=1036550&view=auto
==============================================================================
---
cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java
(added)
+++
cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSeedProvider.java
Thu Nov 18 17:34:08 2010
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.cassandra.locator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class SimpleSeedProvider implements SeedProvider
+{
+ private static final Logger logger =
LoggerFactory.getLogger(SimpleSeedProvider.class);
+
+ private List<InetAddress> seeds;
+
+ public SimpleSeedProvider(Map<String, String> args)
+ {
+ seeds = new ArrayList<InetAddress>();
+ String[] hosts = args.get("seeds").split(",", -1);
+ for (String host : hosts)
+ {
+ try
+ {
+ seeds.add(InetAddress.getByName(host));
+ }
+ catch (UnknownHostException ex)
+ {
+ // not fatal... DD will bark if there end up being zero seeds.
+ 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);
+ }
+}