Skip to content
This repository
Browse code

Merge pull request #77 from apigee/GH-ISSUE-69-consistency

added configurable consistency level to cassandraService with default fo...
  • Loading branch information...
commit 5b341d10466aa4724022effb930aaa2d4d2a2a5a 2 parents e8c798f + 4211878
Ed Anuff edanuff authored
29 core/src/main/java/org/usergrid/persistence/cassandra/CassandraService.java
@@ -17,7 +17,6 @@
17 17
18 18 import static me.prettyprint.cassandra.service.FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE;
19 19 import static me.prettyprint.hector.api.factory.HFactory.createColumn;
20   -import static me.prettyprint.hector.api.factory.HFactory.createDefaultConsistencyLevelPolicy;
21 20 import static me.prettyprint.hector.api.factory.HFactory.createMultigetSliceQuery;
22 21 import static me.prettyprint.hector.api.factory.HFactory.createMutator;
23 22 import static me.prettyprint.hector.api.factory.HFactory.createRangeSlicesQuery;
@@ -56,6 +55,7 @@
56 55 import java.util.concurrent.TimeUnit;
57 56
58 57 import me.prettyprint.cassandra.connection.HConnectionManager;
  58 +import me.prettyprint.cassandra.model.ConfigurableConsistencyLevel;
59 59 import me.prettyprint.cassandra.serializers.ByteBufferSerializer;
60 60 import me.prettyprint.cassandra.serializers.BytesArraySerializer;
61 61 import me.prettyprint.cassandra.serializers.DynamicCompositeSerializer;
@@ -64,9 +64,7 @@
64 64 import me.prettyprint.cassandra.serializers.UUIDSerializer;
65 65 import me.prettyprint.cassandra.service.CassandraHostConfigurator;
66 66 import me.prettyprint.cassandra.service.ThriftKsDef;
67   -import me.prettyprint.hector.api.Cluster;
68   -import me.prettyprint.hector.api.Keyspace;
69   -import me.prettyprint.hector.api.Serializer;
  67 +import me.prettyprint.hector.api.*;
70 68 import me.prettyprint.hector.api.beans.ColumnSlice;
71 69 import me.prettyprint.hector.api.beans.DynamicComposite;
72 70 import me.prettyprint.hector.api.beans.HColumn;
@@ -125,6 +123,8 @@
125 123 Properties properties;
126 124 LockManager lockManager;
127 125
  126 + ConsistencyLevelPolicy consistencyLevelPolicy;
  127 +
128 128 private Keyspace systemKeyspace;
129 129
130 130 public static final StringSerializer se = new StringSerializer();
@@ -148,12 +148,15 @@ public CassandraService(Properties properties, Cluster cluster,
148 148
149 149 public void init() throws Exception {
150 150 HFactory.getOrCreateCluster(cluster.getName(), chc);
151   -
  151 + if ( consistencyLevelPolicy == null ) {
  152 + consistencyLevelPolicy = new ConfigurableConsistencyLevel();
  153 + ((ConfigurableConsistencyLevel)consistencyLevelPolicy).setDefaultReadConsistencyLevel(HConsistencyLevel.ONE);
  154 + }
152 155 Map<String, String> accessMap = new HashMap<String, String>();
153 156 accessMap.put("username", properties.getProperty("cassandra.username"));
154 157 accessMap.put("password", properties.getProperty("cassandra.password"));
155 158 systemKeyspace = HFactory.createKeyspace(SYSTEM_KEYSPACE, cluster,
156   - createDefaultConsistencyLevelPolicy(),
  159 + consistencyLevelPolicy,
157 160 ON_FAIL_TRY_ALL_AVAILABLE, accessMap);
158 161 }
159 162
@@ -196,7 +199,15 @@ public void setLockManager(LockManager lockManager) {
196 199 this.lockManager = lockManager;
197 200 }
198 201
199   - /**
  202 + public ConsistencyLevelPolicy getConsistencyLevelPolicy() {
  203 + return consistencyLevelPolicy;
  204 + }
  205 +
  206 + public void setConsistencyLevelPolicy(ConsistencyLevelPolicy consistencyLevelPolicy) {
  207 + this.consistencyLevelPolicy = consistencyLevelPolicy;
  208 + }
  209 +
  210 + /**
200 211 * @param applicationId
201 212 * @return keyspace for application UUID
202 213 */
@@ -223,11 +234,11 @@ public Keyspace getKeyspace(String keyspace, UUID prefix) {
223 234 Keyspace ko = null;
224 235 if (USE_VIRTUAL_KEYSPACES && (prefix != null)) {
225 236 ko = createVirtualKeyspace(keyspace, prefix, ue, cluster,
226   - createDefaultConsistencyLevelPolicy(),
  237 + consistencyLevelPolicy,
227 238 ON_FAIL_TRY_ALL_AVAILABLE, accessMap);
228 239 } else {
229 240 ko = HFactory.createKeyspace(keyspace, cluster,
230   - createDefaultConsistencyLevelPolicy(),
  241 + consistencyLevelPolicy,
231 242 ON_FAIL_TRY_ALL_AVAILABLE, accessMap);
232 243 }
233 244 return ko;

0 comments on commit 5b341d1

Please sign in to comment.
Something went wrong with that request. Please try again.