From d0964715d4d5f6d71c1139bd247962d278aa167c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 8 Mar 2012 17:39:51 -0600 Subject: [PATCH 1/5] Make BoundedStatsDeque threadsafe. Patch by brandonwilliams, reviewed by jbellis for CASSANDRA-4019 --- .../cassandra/utils/BoundedStatsDeque.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/java/org/apache/cassandra/utils/BoundedStatsDeque.java b/src/java/org/apache/cassandra/utils/BoundedStatsDeque.java index 32565642de..5d27608ebd 100644 --- a/src/java/org/apache/cassandra/utils/BoundedStatsDeque.java +++ b/src/java/org/apache/cassandra/utils/BoundedStatsDeque.java @@ -18,21 +18,20 @@ */ package org.apache.cassandra.utils; -import java.util.ArrayDeque; import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.concurrent.LinkedBlockingDeque; /** - * not threadsafe. caller is responsible for any locking necessary. + * bounded threadsafe deque */ public class BoundedStatsDeque extends AbstractStatsDeque { - private final int size; - protected final ArrayDeque deque; + protected final LinkedBlockingDeque deque; public BoundedStatsDeque(int size) { - this.size = size; - deque = new ArrayDeque(size); + deque = new LinkedBlockingDeque(size); } public Iterator iterator() @@ -50,12 +49,19 @@ public class BoundedStatsDeque extends AbstractStatsDeque deque.clear(); } - public void add(double o) + public void add(double i) { - if (size == deque.size()) + if (!deque.offer(i)) { - deque.remove(); + try + { + deque.remove(); + } + catch (NoSuchElementException e) + { + // oops, clear() beat us to it + } + deque.offer(i); } - deque.add(o); } } From 34060fc77a77846b60b146fc32af9dd58a21b545 Mon Sep 17 00:00:00 2001 From: Vijay Parthasarathy Date: Mon, 12 Mar 2012 12:00:06 -0700 Subject: [PATCH 2/5] EC2 snitch incorrectly reports regions patch by Vijay; reviewed by Brandon Williams for CASSANDRA-4026 --- .../org/apache/cassandra/locator/Ec2Snitch.java | 9 +++++++-- .../apache/cassandra/locator/EC2SnitchTest.java | 14 +++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/cassandra/locator/Ec2Snitch.java b/src/java/org/apache/cassandra/locator/Ec2Snitch.java index 3648143086..139c3053c4 100644 --- a/src/java/org/apache/cassandra/locator/Ec2Snitch.java +++ b/src/java/org/apache/cassandra/locator/Ec2Snitch.java @@ -51,10 +51,15 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch public Ec2Snitch() throws IOException, ConfigurationException { + String az = awsApiCall(ZONE_NAME_QUERY_URL); // Split "us-east-1a" or "asia-1a" into "us-east"/"1a" and "asia"/"1a". - String[] splits = awsApiCall(ZONE_NAME_QUERY_URL).split("-"); + String[] splits = az.split("-"); ec2zone = splits[splits.length - 1]; - ec2region = splits.length < 3 ? splits[0] : splits[0] + "-" + splits[1]; + + // hack for CASSANDRA-4026 + ec2region = az.substring(0, az.length() - 1); + if (ec2region.endsWith("1")) + ec2region = az.substring(0, az.length() - 3); logger.info("EC2Snitch using region: " + ec2region + ", zone: " + ec2zone + "."); } diff --git a/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java b/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java index fad5e9ea74..9df9543f65 100644 --- a/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java +++ b/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java @@ -36,6 +36,7 @@ import org.junit.Test; public class EC2SnitchTest { + private static String az; private class TestEC2Snitch extends Ec2Snitch { @@ -47,13 +48,14 @@ public class EC2SnitchTest @Override String awsApiCall(String url) throws IOException, ConfigurationException { - return "us-east-1d"; + return az; } } @Test public void testRac() throws IOException, ConfigurationException { + az = "us-east-1d"; Ec2Snitch snitch = new TestEC2Snitch(); InetAddress local = InetAddress.getByName("127.0.0.1"); InetAddress nonlocal = InetAddress.getByName("127.0.0.7"); @@ -69,4 +71,14 @@ public class EC2SnitchTest assertEquals("us-east", snitch.getDatacenter(local)); assertEquals("1d", snitch.getRack(local)); } + + @Test + public void testNewRegions() throws IOException, ConfigurationException + { + az = "us-east-2d"; + Ec2Snitch snitch = new TestEC2Snitch(); + InetAddress local = InetAddress.getByName("127.0.0.1"); + assertEquals("us-east-2", snitch.getDatacenter(local)); + assertEquals("2d", snitch.getRack(local)); + } } From e454ea60f18e3cf3fe53f665e8cfab5b262536a8 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Tue, 13 Mar 2012 12:10:37 -0500 Subject: [PATCH 3/5] add #3479 (SOURCE and CAPTURE cqlsh commands) to CHANGES --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index 693cf25293..65b1961c78 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -37,6 +37,7 @@ Merged from 1.0: 1.1-beta1 + * add SOURCE and CAPTURE cqlsh commands (CASSANDRA-3479) * add nodetool rebuild_index (CASSANDRA-3583) * add nodetool rangekeysample (CASSANDRA-2917) * Fix streaming too much data during move operations (CASSANDRA-3639) From e7e984a2f420470851f5ad51ea3702d786e7ed84 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Tue, 13 Mar 2012 12:21:31 -0500 Subject: [PATCH 4/5] emphasize that YOU SHOULD USE BulkOutputFormat --- NEWS.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.txt b/NEWS.txt index 592458df53..a588e91c7f 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -60,6 +60,10 @@ Features be pinned to specfic media. - Hadoop: a new BulkOutputFormat is included which will directly write SSTables locally and then stream them into the cluster. + YOU SHOULD USE BulkOutputFormat BY DEFAULT. ColumnFamilyOutputFormat + is still around in case for some strange reason you want results + trickling out over Thrift, but BulkOutputFormat is significantly + more efficient. - Hadoop: KeyRange.filter is now supported with ColumnFamilyInputFormat - The bulk loader is not longer a fat client; it can be run from an existing machine in a cluster. From f42ec6d599abac9aa9a4e8cc2d1ae4a13abfa4fa Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Tue, 13 Mar 2012 23:21:52 -0500 Subject: [PATCH 5/5] add environment variables to the simpleauth README --- examples/simple_authentication/README.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/simple_authentication/README.txt b/examples/simple_authentication/README.txt index 3de5092fd2..dcf95538d9 100644 --- a/examples/simple_authentication/README.txt +++ b/examples/simple_authentication/README.txt @@ -10,5 +10,16 @@ You can then set the authenticator and authority properties in cassandra.yaml to use those classes. See the two configuration files access.properties and passwd.properties to configure the authorized users and permissions. +When starting cassandra, you need to specify the location of the passwd.properties +and access.properties files by adding JVM args similar to the following either +in cassandra-env.sh or as commandline arguments: + + -Dpasswd.properties=conf/passwd.properties + -Daccess.properties=conf/access.properties + +For example, you might invoke cassandra as follows: + + bin/cassandra -f -Dpasswd.properties=conf/passwd.properties -Daccess.properties=conf/access.properties + Please note that the code in this directory is for demonstration purposes. In particular, it does not provide a high level of security.