Hi Renato,
just as a small addition, this patch is what I'm going to test tonight.
--Roland
Am 28.02.2013 17:45, schrieb Roland (JIRA):
And after looking more into this today, I think it may even be the usage of the
Hector Mutator inside CassandraClient. The Hector docs state, that the Mutator
isn't thread safe. [2]
Thanks,
Roland
[2]
http://hector-client.github.com/hector//source/content/API/core/1.0-1/me/prettyprint/hector/api/mutation/Mutator.html
Index: src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
===================================================================
--- src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
(revision 1449745)
+++ src/main/java/org/apache/gora/cassandra/store/CassandraClient.java
(working copy)
@@ -57,7 +57,8 @@
private Cluster cluster;
private Keyspace keyspace;
private Mutator<String> mutator;
-
+ private Object mutatorLock;
+
private CassandraMapping cassandraMapping = new CassandraMapping();
private StringSerializer stringSerializer = new StringSerializer();
@@ -135,8 +136,13 @@
String columnFamily = this.cassandraMapping.getFamily(fieldName);
String columnName = this.cassandraMapping.getColumn(fieldName);
-
- this.mutator.insert(key, columnFamily,
HFactory.createStringColumn(columnName, value.toString()));
+
+ // according to hector javadoc a Mutator is NOT thread-safe
+ // FIXME this is not really clean, maybe we should create a getMutator()
method and use it in CassandraStore for batch mode (Mutator.addInsertion() &&
Mutator.execute())
+ // this could save us all the buffer work in CassandraStore
+ synchronized(mutatorLock) {
+ this.mutator.insert(key, columnFamily,
HFactory.createStringColumn(columnName, value.toString()));
+ }
}
/**
@@ -157,7 +163,7 @@
* @param value the member value
*/
@SuppressWarnings("unchecked")
-public void addSubColumn(String key, String fieldName, String memberName,
Object value) {
+ public void addSubColumn(String key, String fieldName, String memberName,
Object value) {
if (value == null) {
return;
}
@@ -168,9 +174,14 @@
String columnFamily = this.cassandraMapping.getFamily(fieldName);
String superColumnName = this.cassandraMapping.getColumn(fieldName);
+
+ // according to hector javadoc a Mutator is NOT thread-safe
+ // FIXME this is not really clean, maybe we should create a getMutator()
method and use it in CassandraStore for batch mode (Mutator.addInsertion() &&
Mutator.execute())
+ // this could save us all the buffer work in CassandraStore
+ synchronized(mutatorLock) {
+ this.mutator.insert(key, columnFamily,
HFactory.createSuperColumn(superColumnName,
Arrays.asList(HFactory.createStringColumn(memberName, value.toString())),
this.stringSerializer, this.stringSerializer, this.stringSerializer));
+ }
- this.mutator.insert(key, columnFamily,
HFactory.createSuperColumn(superColumnName,
Arrays.asList(HFactory.createStringColumn(memberName, value.toString())),
this.stringSerializer, this.stringSerializer, this.stringSerializer));
-
}
/**