usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [04/12] usergrid git commit: First commit of new implementation of Astyanax locks and having it wired with guide instead of Spring.
Date Sat, 16 Jan 2016 00:44:44 GMT
First commit of new implementation of Astyanax locks and having it wired with guide instead of Spring.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/71f32747
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/71f32747
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/71f32747

Branch: refs/heads/master
Commit: 71f327473434874f78fb53bebf46b8cf909a9735
Parents: 8849d8e
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Thu Jan 14 09:42:42 2016 -0800
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Thu Jan 14 12:17:35 2016 -0800

----------------------------------------------------------------------
 stack/core/pom.xml                              |   5 +
 .../apache/usergrid/batch/job/OnlyOnceJob.java  |   3 +-
 .../usergrid/corepersistence/CoreModule.java    |   2 +
 .../locking/cassandra/AstyanaxLockImpl.java     |  79 +++++
 .../cassandra/AstyanaxLockManagerImpl.java      | 173 +++++++++
 .../usergrid/locking/guice/LockModule.java      |  40 +++
 .../mq/cassandra/QueueManagerFactoryImpl.java   |   5 +-
 .../persistence/cassandra/CassandraService.java |   5 +-
 .../main/resources/usergrid-core-context.xml    |   5 +-
 stack/corepersistence/common/pom.xml            | 351 ++++++++++---------
 .../core/astyanax/AstyanaxKeyspaceProvider.java |  46 +--
 .../core/astyanax/CassandraCluster.java         |  20 ++
 .../core/astyanax/CassandraClusterImpl.java     | 198 +++++++++++
 .../persistence/core/astyanax/CassandraFig.java |  72 +++-
 .../persistence/core/guice/CommonModule.java    |  11 +-
 .../data/MigrationInfoSerializationImpl.java    |  10 +-
 .../core/astyanax/ColumnNameIteratorTest.java   |   5 +-
 .../MultiKeyColumnNameIteratorTest.java         |   5 +-
 .../astyanax/MultiRowColumnIteratorTest.java    |   5 +-
 .../persistence/core/astyanax/TestUtils.java    |   8 +-
 stack/pom.xml                                   |   7 +
 .../services/ServiceManagerFactory.java         |   6 +-
 .../resources/usergrid-services-context.xml     |   6 +-
 .../test/resources/testApplicationContext.xml   |  10 +-
 24 files changed, 830 insertions(+), 247 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/core/pom.xml
----------------------------------------------------------------------
diff --git a/stack/core/pom.xml b/stack/core/pom.xml
index ae9f915..49082b6 100644
--- a/stack/core/pom.xml
+++ b/stack/core/pom.xml
@@ -214,6 +214,11 @@
       <artifactId>curator-recipes</artifactId>
     </dependency>
 
+      <dependency>
+          <groupId>com.netflix.astyanax</groupId>
+          <artifactId>astyanax-recipes</artifactId>
+      </dependency>
+
     <dependency>
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/core/src/main/java/org/apache/usergrid/batch/job/OnlyOnceJob.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/batch/job/OnlyOnceJob.java b/stack/core/src/main/java/org/apache/usergrid/batch/job/OnlyOnceJob.java
index 726464e..f857d05 100644
--- a/stack/core/src/main/java/org/apache/usergrid/batch/job/OnlyOnceJob.java
+++ b/stack/core/src/main/java/org/apache/usergrid/batch/job/OnlyOnceJob.java
@@ -19,6 +19,7 @@ package org.apache.usergrid.batch.job;
 
 import java.util.concurrent.TimeUnit;
 
+import org.elasticsearch.common.inject.Inject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.apache.usergrid.batch.Job;
@@ -37,7 +38,7 @@ import org.apache.usergrid.persistence.EntityManagerFactory;
 @Component("OnlyOnceJob")
 public abstract class OnlyOnceJob implements Job {
 
-    @Autowired
+    @Inject
     private LockManager lockManager;
 
     @Autowired

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index 628459b..e2d845f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@ -16,6 +16,7 @@
 package org.apache.usergrid.corepersistence;
 
 
+import org.apache.usergrid.locking.guice.LockModule;
 import org.apache.usergrid.persistence.cache.guice.CacheModule;
 import java.util.concurrent.ThreadPoolExecutor;
 
@@ -94,6 +95,7 @@ public class CoreModule extends AbstractModule {
     protected void configure() {
 
         install( new CommonModule());
+        install( new LockModule());
         install( new CacheModule());
         install( new CollectionModule() {
             /**

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockImpl.java b/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockImpl.java
new file mode 100644
index 0000000..3c12d8a
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockImpl.java
@@ -0,0 +1,79 @@
+/*
+ * 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.usergrid.locking.cassandra;
+
+
+import com.netflix.astyanax.recipes.locks.ColumnPrefixDistributedRowLock;
+
+import org.apache.usergrid.locking.Lock;
+import org.apache.usergrid.locking.exception.UGLockException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.TimeUnit;
+
+
+public class AstyanaxLockImpl implements Lock {
+
+    private static final Logger logger = LoggerFactory.getLogger( AstyanaxLockImpl.class );
+
+
+
+    ColumnPrefixDistributedRowLock lock;
+
+    public AstyanaxLockImpl(//AstyanaxLockManagerImpl lockManager,
+                            ColumnPrefixDistributedRowLock lock) {
+
+        this.lock = lock;
+
+    }
+
+
+    @Override
+    public boolean tryLock( long timeout, TimeUnit time ) throws UGLockException {
+        lock.withTtl( (int) timeout, time);
+
+        try {
+            lock.acquire();
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    @Override
+    public void lock() throws UGLockException {
+
+        try {
+            lock.acquire();
+        } catch (Exception e) {
+            throw new UGLockException("Unable to acquire lock with id: " + lock.getLockId());
+        }
+    }
+
+    @Override
+    public void unlock() throws UGLockException {
+
+        try {
+            lock.release();
+        } catch (Exception e) {
+            throw new UGLockException("Unable to release lock with id: " + lock.getLockId());
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockManagerImpl.java
new file mode 100644
index 0000000..ece942f
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/locking/cassandra/AstyanaxLockManagerImpl.java
@@ -0,0 +1,173 @@
+/*
+ * 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.usergrid.locking.cassandra;
+
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Inject;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import com.netflix.astyanax.ddl.ColumnFamilyDefinition;
+import com.netflix.astyanax.ddl.KeyspaceDefinition;
+import com.netflix.astyanax.model.ColumnFamily;
+import com.netflix.astyanax.recipes.locks.ColumnPrefixDistributedRowLock;
+import com.netflix.astyanax.serializers.StringSerializer;
+import org.apache.cassandra.db.marshal.BytesType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.usergrid.locking.Lock;
+import org.apache.usergrid.locking.LockManager;
+import org.apache.usergrid.locking.LockPathBuilder;
+import org.apache.usergrid.persistence.core.astyanax.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+public class AstyanaxLockManagerImpl implements LockManager {
+
+    private static final Logger logger = LoggerFactory.getLogger( AstyanaxLockManagerImpl.class );
+    private static final String CF_NAME = "AstyanaxLocks";
+
+
+    private final CassandraFig cassandraFig;
+    private final Keyspace keyspace;
+    private final ColumnFamily columnFamily;
+
+    @Inject
+    public AstyanaxLockManagerImpl(CassandraFig cassandraFig,
+                                   CassandraCluster cassandraCluster ) throws ConnectionException {
+
+        this.cassandraFig = cassandraFig;
+        this.keyspace = cassandraCluster.getLocksKeyspace();
+
+        createLocksKeyspace();
+
+        this.columnFamily = createLocksColumnFamily();
+
+
+
+
+    }
+
+
+    @Override
+    public Lock createLock(final UUID applicationId, final String... path ){
+
+        String lockPath = LockPathBuilder.buildPath( applicationId, path );
+
+        ColumnPrefixDistributedRowLock<String> lock =
+            new ColumnPrefixDistributedRowLock<>(keyspace, columnFamily, lockPath);
+
+
+        return new AstyanaxLockImpl( lock );
+
+    }
+
+
+
+    private ColumnFamily createLocksColumnFamily() throws ConnectionException {
+
+        ColumnFamily<String, String> CF_LOCKS = ColumnFamily.newColumnFamily(
+            CF_NAME, StringSerializer.get(), StringSerializer.get() );
+
+        final KeyspaceDefinition keyspaceDefinition = keyspace.describeKeyspace();
+        final ColumnFamilyDefinition existing =
+            keyspaceDefinition.getColumnFamily( CF_LOCKS.getName() );
+
+
+        if ( existing != null ) {
+
+            Map<String, Object> existingOptions = new HashMap<>(1);
+            existingOptions.put("gc_grace_seconds", existing.getGcGraceSeconds());
+            existingOptions.put("caching", existing.getCaching());
+            existingOptions.put("compaction_strategy", existing.getCompactionStrategy());
+            existingOptions.put("compaction_strategy_options", existing.getCompactionStrategyOptions());
+
+            logger.info( "Locks column family {} exists with options: {}", existing.getName(),
+                existingOptions.toString() );
+
+            return CF_LOCKS;
+        }
+
+        MultiTenantColumnFamilyDefinition columnFamilyDefinition = new MultiTenantColumnFamilyDefinition(
+            CF_LOCKS,
+            BytesType.class.getSimpleName(),
+            UTF8Type.class.getSimpleName(),
+            BytesType.class.getSimpleName(),
+            MultiTenantColumnFamilyDefinition.CacheOption.ALL
+        );
+
+        Map<String, Object> cfOptions = columnFamilyDefinition.getOptions();
+
+        // Additionally set the gc grace low
+        cfOptions.put("gc_grace_seconds", 60);
+
+
+        keyspace.createColumnFamily( columnFamilyDefinition.getColumnFamily() , cfOptions );
+
+        logger.info( "Created column family {}", columnFamilyDefinition.getOptions() );
+
+        return columnFamilyDefinition.getColumnFamily();
+    }
+
+
+    private void createLocksKeyspace() throws ConnectionException {
+
+
+
+        ImmutableMap.Builder<String, Object> strategyOptions = getKeySpaceProps();
+
+        ImmutableMap<String, Object> options =
+            ImmutableMap.<String, Object>builder().put( "strategy_class", cassandraFig.getLocksKeyspaceStrategy() )
+                .put( "strategy_options", strategyOptions.build() ).build();
+
+
+        keyspace.createKeyspaceIfNotExists( options );
+
+        strategyOptions.toString();
+
+        logger.info( "Keyspace {} created or already exists with options {}",
+            keyspace.getKeyspaceName(),
+            options.toString() );
+    }
+
+    /**
+     * Get keyspace properties
+     */
+    private ImmutableMap.Builder<String, Object> getKeySpaceProps() {
+        ImmutableMap.Builder<String, Object> keyspaceProps = ImmutableMap.<String, Object>builder();
+
+        String optionString = cassandraFig.getLocksKeyspaceReplication();
+
+        if(optionString == null){
+            return keyspaceProps;
+        }
+
+
+        for ( String key : optionString.split( "," ) ) {
+
+            final String[] options = key.split( ":" );
+            if (options.length > 0) {
+                keyspaceProps.put(options[0], options[1]);
+            }
+        }
+
+        return keyspaceProps;
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/core/src/main/java/org/apache/usergrid/locking/guice/LockModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/locking/guice/LockModule.java b/stack/core/src/main/java/org/apache/usergrid/locking/guice/LockModule.java
new file mode 100644
index 0000000..49c58fe
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/locking/guice/LockModule.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.locking.guice;
+
+
+import com.google.inject.AbstractModule;
+import org.apache.usergrid.locking.LockManager;
+import org.apache.usergrid.locking.cassandra.AstyanaxLockManagerImpl;
+
+
+/**
+ * Wire up LockManager implementation.
+ */
+public class LockModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+
+        bind( LockManager.class ).to( AstyanaxLockManagerImpl.class );
+
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/QueueManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/QueueManagerFactoryImpl.java b/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/QueueManagerFactoryImpl.java
index a54295c..47b58e8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/QueueManagerFactoryImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/QueueManagerFactoryImpl.java
@@ -19,6 +19,7 @@ package org.apache.usergrid.mq.cassandra;
 
 import java.util.UUID;
 
+import com.google.inject.Injector;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.usergrid.locking.LockManager;
@@ -47,10 +48,10 @@ public class QueueManagerFactoryImpl implements QueueManagerFactory {
      * @param cass the cassandra client pool
      * @param counterUtils the CounterUtils
      */
-    public QueueManagerFactoryImpl( CassandraService cass, CounterUtils counterUtils, LockManager lockManager, int lockTimeout ) {
+    public QueueManagerFactoryImpl(CassandraService cass, CounterUtils counterUtils, final Injector injector, int lockTimeout ) {
         this.cass = cass;
         this.counterUtils = counterUtils;
-        this.lockManager = lockManager;
+        lockManager = injector.getInstance(LockManager.class);
         this.lockTimeout = lockTimeout;
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
index e973764..b0226b7 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.persistence.cassandra;
 
 
+import com.google.inject.Inject;
 import com.google.inject.Injector;
 import me.prettyprint.cassandra.connection.HConnectionManager;
 import me.prettyprint.cassandra.model.ConfigurableConsistencyLevel;
@@ -110,12 +111,12 @@ public class CassandraService {
 
 //Wire guice injector via spring here, just pass the injector in the spring
     public CassandraService( Properties properties, Cluster cluster,
-                             CassandraHostConfigurator cassandraHostConfigurator, LockManager lockManager,
+                             CassandraHostConfigurator cassandraHostConfigurator,
                            final Injector injector) {
         this.properties = properties;
         this.cluster = cluster;
         chc = cassandraHostConfigurator;
-        this.lockManager = lockManager;
+        lockManager = injector.getInstance( LockManager.class );
         db_logger.info( "" + cluster.getKnownPoolHosts( false ) );
         //getInjector
         applicationKeyspace  = injector.getInstance( CassandraFig.class ).getApplicationKeyspace();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/core/src/main/resources/usergrid-core-context.xml
----------------------------------------------------------------------
diff --git a/stack/core/src/main/resources/usergrid-core-context.xml b/stack/core/src/main/resources/usergrid-core-context.xml
index dc52b70..d413816 100644
--- a/stack/core/src/main/resources/usergrid-core-context.xml
+++ b/stack/core/src/main/resources/usergrid-core-context.xml
@@ -77,6 +77,7 @@
 	     be updated to use an odd number for it's replication Factor. Even numbers can potentially
 	     case the locks to fail, via "split brain" when read at QUORUM on lock verification-->
 
+    <!-- not using hector anymore
 	<bean name="lockManager" class="org.apache.usergrid.locking.cassandra.HectorLockManagerImpl">
 		<property name="cluster" ref="cassandraCluster"/>
 		<property name="keyspaceName" value="${cassandra.lock.keyspace}"/>
@@ -87,6 +88,7 @@
         <property name="defaultReadConsistencyLevel" value="${cassandra.lock.readcl}"/>
         <property name="defaultWriteConsistencyLevel" value="${cassandra.lock.writecl}"/>
     </bean>
+    -->
 
     <bean id="injector"
    		class="org.apache.usergrid.corepersistence.GuiceFactory">
@@ -103,7 +105,6 @@
 		<constructor-arg ref="properties" />
 		<constructor-arg ref="cassandraCluster" />
 		<constructor-arg ref="cassandraHostConfigurator" />
-		<constructor-arg ref="lockManager" />
         <constructor-arg ref="injector"/>
 		<property name="consistencyLevelPolicy" ref="consistencyLevelPolicy"/>
 	</bean>
@@ -124,7 +125,7 @@
           class="org.apache.usergrid.mq.cassandra.QueueManagerFactoryImpl">
         <constructor-arg ref="cassandraService" />
         <constructor-arg ref="counterUtils"/>
-        <constructor-arg ref="lockManager"/>
+        <constructor-arg ref="injector"/>
         <constructor-arg value="${usergrid.queue.lock.timeout}"/>
     </bean>
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/pom.xml b/stack/corepersistence/common/pom.xml
index 0f54896..ff2ab28 100644
--- a/stack/corepersistence/common/pom.xml
+++ b/stack/corepersistence/common/pom.xml
@@ -2,175 +2,181 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <parent>
-    <artifactId>persistence</artifactId>
-    <groupId>org.apache.usergrid</groupId>
-    <version>2.1.1-SNAPSHOT</version>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-
-  <artifactId>common</artifactId>
-  <name>Usergrid Common</name>
-
-  <dependencies>
-
-    <dependency>
-        <groupId>${project.parent.groupId}</groupId>
-        <artifactId>model</artifactId>
-        <version>${project.version}</version>
-      </dependency>
-
-
-    <dependency>
-      <groupId>com.netflix.astyanax</groupId>
-      <artifactId>astyanax-core</artifactId>
-      <version>${astyanax.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>com.netflix.astyanax</groupId>
-      <artifactId>astyanax-thrift</artifactId>
-      <version>${astyanax.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>com.netflix.astyanax</groupId>
-      <artifactId>astyanax-cassandra</artifactId>
-      <version>${astyanax.version}</version>
-      <exclusions>
-        <exclusion>
-          <artifactId>servlet-api</artifactId>
-          <groupId>org.mortbay.jetty</groupId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-
-    <dependency>
-      <groupId>org.apache.cassandra</groupId>
-      <artifactId>cassandra-all</artifactId>
-      <version>${cassandra.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.antlr</groupId>
-      <artifactId>antlr</artifactId>
-      <version>${antlr.version}</version>
-      <type>jar</type>
-    </dependency>
-
-    <dependency>
-      <groupId>org.antlr</groupId>
-      <artifactId>antlr-runtime</artifactId>
-      <version>${antlr.version}</version>
-      <type>jar</type>
-    </dependency>
-
-    <dependency>
-      <groupId>org.safehaus.guicyfig</groupId>
-      <artifactId>guicyfig</artifactId>
-      <version>${guicyfig.version}</version>
-    </dependency>
-
-
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-collections4</artifactId>
-      <version>4.0</version>
-    </dependency>
-
-
-    <!-- Google Guice -->
-
-    <dependency>
-      <groupId>com.google.inject</groupId>
-      <artifactId>guice</artifactId>
-      <version>${guice.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>com.google.inject.extensions</groupId>
-      <artifactId>guice-multibindings</artifactId>
-      <version>${guice.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>com.google.inject.extensions</groupId>
-      <artifactId>guice-assistedinject</artifactId>
-      <version>${guice.version}</version>
-    </dependency>
-
-    <!-- RX java -->
-
-      <dependency>
-          <groupId>io.reactivex</groupId>
-          <artifactId>rxjava</artifactId>
-          <version>${rx.version}</version>
-      </dependency>
-
-    <dependency>
-      <groupId>io.reactivex</groupId>
-      <artifactId>rxjava-math</artifactId>
-      <version>1.0.0</version>
-    </dependency>
-
-      <dependency>
-          <groupId>io.reactivex</groupId>
-          <artifactId>rxjava-async-util</artifactId>
-          <version>0.21.0</version>
-      </dependency>
-
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-      <version>${slf4j.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-log4j12</artifactId>
-      <version>${slf4j.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <version>${log4j.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>com.netflix.hystrix</groupId>
-      <artifactId>hystrix-core</artifactId>
-      <version>${hystrix.version}</version>
-    </dependency>
-
-
-    <!-- aws sdks -->
-    <dependency>
-      <groupId>com.amazonaws</groupId>
-      <artifactId>aws-java-sdk</artifactId>
-      <version>${aws.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-core</artifactId>
-      <version>${mockito.version}</version>
-      <scope>test</scope>
-    </dependency>
-
-
-    <dependency>
-      <groupId>com.codahale.metrics</groupId>
-      <artifactId>metrics-core</artifactId>
-      <version>${metrics.version}</version>
-    </dependency>
-
-    <dependency>
-      <groupId>com.codahale.metrics</groupId>
-      <artifactId>metrics-graphite</artifactId>
-      <version>${metrics.version}</version>
-    </dependency>
-  </dependencies>
+    <parent>
+        <artifactId>persistence</artifactId>
+        <groupId>org.apache.usergrid</groupId>
+        <version>2.1.1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>common</artifactId>
+    <name>Usergrid Common</name>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>${project.parent.groupId}</groupId>
+            <artifactId>model</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>com.netflix.astyanax</groupId>
+            <artifactId>astyanax-core</artifactId>
+            <version>${astyanax.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.netflix.astyanax</groupId>
+            <artifactId>astyanax-thrift</artifactId>
+            <version>${astyanax.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.netflix.astyanax</groupId>
+            <artifactId>astyanax-cassandra</artifactId>
+            <version>${astyanax.version}</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>servlet-api</artifactId>
+                    <groupId>org.mortbay.jetty</groupId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>com.netflix.astyanax</groupId>
+            <artifactId>astyanax-recipes</artifactId>
+            <version>${astyanax.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.cassandra</groupId>
+            <artifactId>cassandra-all</artifactId>
+            <version>${cassandra.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.antlr</groupId>
+            <artifactId>antlr</artifactId>
+            <version>${antlr.version}</version>
+            <type>jar</type>
+        </dependency>
+
+        <dependency>
+            <groupId>org.antlr</groupId>
+            <artifactId>antlr-runtime</artifactId>
+            <version>${antlr.version}</version>
+            <type>jar</type>
+        </dependency>
+
+        <dependency>
+            <groupId>org.safehaus.guicyfig</groupId>
+            <artifactId>guicyfig</artifactId>
+            <version>${guicyfig.version}</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.0</version>
+        </dependency>
+
+
+        <!-- Google Guice -->
+
+        <dependency>
+            <groupId>com.google.inject</groupId>
+            <artifactId>guice</artifactId>
+            <version>${guice.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.google.inject.extensions</groupId>
+            <artifactId>guice-multibindings</artifactId>
+            <version>${guice.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.google.inject.extensions</groupId>
+            <artifactId>guice-assistedinject</artifactId>
+            <version>${guice.version}</version>
+        </dependency>
+
+        <!-- RX java -->
+
+        <dependency>
+            <groupId>io.reactivex</groupId>
+            <artifactId>rxjava</artifactId>
+            <version>${rx.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>io.reactivex</groupId>
+            <artifactId>rxjava-math</artifactId>
+            <version>1.0.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>io.reactivex</groupId>
+            <artifactId>rxjava-async-util</artifactId>
+            <version>0.21.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>${log4j.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.netflix.hystrix</groupId>
+            <artifactId>hystrix-core</artifactId>
+            <version>${hystrix.version}</version>
+        </dependency>
+
+
+        <!-- aws sdks -->
+        <dependency>
+            <groupId>com.amazonaws</groupId>
+            <artifactId>aws-java-sdk</artifactId>
+            <version>${aws.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>${mockito.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+
+        <dependency>
+            <groupId>com.codahale.metrics</groupId>
+            <artifactId>metrics-core</artifactId>
+            <version>${metrics.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.codahale.metrics</groupId>
+            <artifactId>metrics-graphite</artifactId>
+            <version>${metrics.version}</version>
+        </dependency>
+    </dependencies>
 
     <profiles>
         <profile>
@@ -182,8 +188,11 @@
                         <artifactId>maven-surefire-plugin</artifactId>
                         <version>${surefire.plugin.version}</version>
                         <configuration>
-                            <argLine>-javaagent:${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco.version}/org.jacoco.agent-${jacoco.version}-runtime.jar=destfile=${project.build.directory}/jacoco.exec</argLine>
-                            <excludedGroups>org.apache.usergrid.StressTest,org.apache.usergrid.ExperimentalTest</excludedGroups>
+                            <argLine>
+                                -javaagent:${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco.version}/org.jacoco.agent-${jacoco.version}-runtime.jar=destfile=${project.build.directory}/jacoco.exec
+                            </argLine>
+                            <excludedGroups>org.apache.usergrid.StressTest,org.apache.usergrid.ExperimentalTest
+                            </excludedGroups>
                         </configuration>
                     </plugin>
                 </plugins>

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java
index 9377236..f02cf27 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java
@@ -44,55 +44,21 @@ import com.netflix.astyanax.thrift.ThriftFamilyFactory;
  */
 @Singleton
 public class AstyanaxKeyspaceProvider implements Provider<Keyspace> {
-    private final CassandraFig cassandraFig;
-    private final CassandraConfig cassandraConfig;
+
+    private final CassandraCluster cassandraCluster;
 
 
     @Inject
-    public AstyanaxKeyspaceProvider( final CassandraFig cassandraFig, final CassandraConfig cassandraConfig) {
-        this.cassandraFig = cassandraFig;
-        this.cassandraConfig = cassandraConfig;
+    public AstyanaxKeyspaceProvider( final CassandraCluster cassandraCluster) {
+
+        this.cassandraCluster = cassandraCluster;
     }
 
 
     @Override
     public Keyspace get() {
 
-        AstyanaxConfiguration config = new AstyanaxConfigurationImpl()
-                .setDiscoveryType( NodeDiscoveryType.valueOf( cassandraFig.getDiscoveryType() ) )
-                .setTargetCassandraVersion( cassandraFig.getVersion() )
-                .setDefaultReadConsistencyLevel( cassandraConfig.getReadCL() )
-                .setDefaultWriteConsistencyLevel( cassandraConfig.getWriteCL() );
-
-        ConnectionPoolConfiguration connectionPoolConfiguration =
-                new ConnectionPoolConfigurationImpl( "UsergridConnectionPool" )
-                        .setPort( cassandraFig.getThriftPort() )
-                        .setLocalDatacenter( cassandraFig.getLocalDataCenter() )
-                        .setMaxConnsPerHost( cassandraFig.getConnections() )
-                        .setSeeds( cassandraFig.getHosts() )
-                        .setSocketTimeout( cassandraFig.getTimeout() );
-
-        AstyanaxContext<Keyspace> context =
-                new AstyanaxContext.Builder().forCluster( cassandraFig.getClusterName() )
-                        .forKeyspace( cassandraFig.getApplicationKeyspace())
-
-                        /*
-                         * TODO tnine Filter this by adding a host supplier.  We will get token discovery from cassandra
-                         * but only connect
-                         * to nodes that have been specified.  Good for real time updates of the cass system without
-                         * adding
-                         * load to them during runtime
-                         */
-
-                        .withAstyanaxConfiguration( config )
-                        .withConnectionPoolConfiguration( connectionPoolConfiguration )
-                        .withConnectionPoolMonitor( new Slf4jConnectionPoolMonitorImpl() )
-                        .buildKeyspace( ThriftFamilyFactory.getInstance() );
-
-        context.start();
-
-
-        return context.getClient();
+        return cassandraCluster.getApplicationKeyspace();
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraCluster.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraCluster.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraCluster.java
new file mode 100644
index 0000000..0adac8e
--- /dev/null
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraCluster.java
@@ -0,0 +1,20 @@
+package org.apache.usergrid.persistence.core.astyanax;
+
+
+
+import com.netflix.astyanax.Keyspace;
+
+import java.util.Map;
+
+
+public interface CassandraCluster {
+
+
+    Map<String, Keyspace> getKeyspaces();
+
+    Keyspace getApplicationKeyspace();
+
+    Keyspace getLocksKeyspace();
+
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraClusterImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraClusterImpl.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraClusterImpl.java
new file mode 100644
index 0000000..674e076
--- /dev/null
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraClusterImpl.java
@@ -0,0 +1,198 @@
+/*
+ * 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.usergrid.persistence.core.astyanax;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.netflix.astyanax.AstyanaxConfiguration;
+import com.netflix.astyanax.AstyanaxContext;
+import com.netflix.astyanax.Cluster;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.connectionpool.ConnectionPoolConfiguration;
+import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
+import com.netflix.astyanax.connectionpool.impl.Slf4jConnectionPoolMonitorImpl;
+import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
+import com.netflix.astyanax.thrift.ThriftFamilyFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * TODO.  Provide the ability to do a service hook for realtime tuning without the need of a JVM restart This could be
+ * done with governator and service discovery
+ *
+ * @author tnine
+ */
+@Singleton
+public class CassandraClusterImpl implements CassandraCluster {
+
+    private static final Logger logger = LoggerFactory.getLogger( CassandraClusterImpl.class );
+
+
+    private final CassandraFig cassandraFig;
+    private final CassandraConfig cassandraConfig;
+    private final Map<String, Keyspace> keyspaces = new HashMap<>(2);
+
+
+    @Inject
+    public CassandraClusterImpl(final CassandraFig cassandraFig, final CassandraConfig cassandraConfig) {
+        this.cassandraFig = cassandraFig;
+        this.cassandraConfig = cassandraConfig;
+
+
+
+        AstyanaxConfiguration config = new AstyanaxConfigurationImpl()
+            .setDiscoveryType( NodeDiscoveryType.valueOf( cassandraFig.getDiscoveryType() ) )
+            .setTargetCassandraVersion( cassandraFig.getVersion() )
+            .setDefaultReadConsistencyLevel( cassandraConfig.getReadCL() )
+            .setDefaultWriteConsistencyLevel( cassandraConfig.getWriteCL() );
+
+
+        if(cassandraFig.useSharedPoolForLocks()){
+
+            ConnectionPoolConfiguration sharedPoolConfig =
+                getConnectionPoolConfig( "ConnectionPool-Shared", cassandraFig.getConnections());
+
+            AstyanaxContext<Cluster> sharedClusterContext =
+                getCluster( cassandraFig.getClusterName(), config, sharedPoolConfig );
+
+            sharedClusterContext.start();
+            Cluster sharedCluster = sharedClusterContext.getClient();
+
+
+            try {
+                addKeyspace( sharedCluster, cassandraFig.getApplicationKeyspace());
+                addKeyspace( sharedCluster, cassandraFig.getLocksKeyspace());
+            } catch (Exception e) {
+                throw new RuntimeException( "Unable to create keyspace clients");
+            }
+
+
+
+        }else{
+
+            ConnectionPoolConfiguration applicationPoolConfig =
+                getConnectionPoolConfig( "ConnectionPool-Application", cassandraFig.getConnections());
+
+            ConnectionPoolConfiguration locksPoolConfig =
+                getConnectionPoolConfig( "ConnectionPool-Locks", cassandraFig.getConnectionsLocks());
+
+            AstyanaxContext<Cluster> applicationClusterContext =
+                getCluster( cassandraFig.getClusterName(), config, applicationPoolConfig );
+
+            AstyanaxContext<Cluster> locksClusterContext =
+                getCluster( cassandraFig.getClusterName() + "-Locks", config, locksPoolConfig );
+
+
+            applicationClusterContext.start();
+            locksClusterContext.start();
+
+            Cluster applicationCluster = applicationClusterContext.getClient();
+            Cluster locksCluster = locksClusterContext.getClient();
+
+
+            try {
+                addKeyspace( applicationCluster, cassandraFig.getApplicationKeyspace());
+                addKeyspace( locksCluster, cassandraFig.getLocksKeyspace());
+            } catch (Exception e) {
+                throw new RuntimeException( "Unable to create keyspace clients");
+            }
+
+
+        }
+
+
+
+    }
+
+
+    @Override
+    public Map<String, Keyspace> getKeyspaces() {
+
+        return keyspaces;
+
+    }
+
+
+    @Override
+    public Keyspace getApplicationKeyspace() {
+
+        return keyspaces.get( cassandraFig.getApplicationKeyspace() );
+
+    }
+
+    @Override
+    public Keyspace getLocksKeyspace() {
+
+        return keyspaces.get( cassandraFig.getLocksKeyspace() );
+
+    }
+
+
+
+
+
+
+    private ConnectionPoolConfiguration getConnectionPoolConfig ( final String poolName, final int poolSize ){
+
+        return new ConnectionPoolConfigurationImpl( poolName )
+            .setPort( cassandraFig.getThriftPort() )
+            .setLocalDatacenter( cassandraFig.getLocalDataCenter() )
+            .setMaxConnsPerHost( poolSize )
+            .setSeeds( cassandraFig.getHosts() )
+            .setSocketTimeout( cassandraFig.getTimeout() );
+
+    }
+
+    private AstyanaxContext<Cluster> getCluster ( final String clusterName,
+                                                  final AstyanaxConfiguration astyanaxConfiguration,
+                                                  final ConnectionPoolConfiguration poolConfig ) {
+
+        return new AstyanaxContext.Builder().forCluster( clusterName )
+            .withAstyanaxConfiguration( astyanaxConfiguration )
+            .withConnectionPoolConfiguration( poolConfig )
+            .withConnectionPoolMonitor( new Slf4jConnectionPoolMonitorImpl())
+            .buildCluster( ThriftFamilyFactory.getInstance() );
+
+    }
+
+    private void addKeyspace (Cluster cluster, String keyspaceName) throws Exception {
+
+        try {
+            keyspaces.put( keyspaceName, cluster.getKeyspace( keyspaceName ) );
+        } catch (ConnectionException e) {
+
+            logger.error("Unable to get keyspace client for keyspace: {}, detail: {}",
+                keyspaceName,
+                e.getMessage());
+
+            throw e;
+        }
+
+
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java
index 2dc4876..d7cd57a 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java
@@ -32,16 +32,26 @@ import org.safehaus.guicyfig.Key;
 @FigSingleton
 public interface CassandraFig extends GuicyFig {
 
+    // main application cassandra properties
+    String READ_CONSISTENT_CL = "usergrid.consistent.read.cl";
+    String READ_CL = "usergrid.read.cl";
+    String WRITE_CL = "usergrid.write.cl";
+    String SHARD_VALUES = "cassandra.shardvalues";
+    String THRIFT_TRANSPORT_SIZE = "cassandra.thrift.transport.frame";
 
-    public static final String READ_CONSISTENT_CL = "usergrid.consistent.read.cl";
+    // locks cassandra properties
+    String LOCKS_KEYSPACE_NAME = "cassandra.lock.keyspace";
+    String LOCKS_KEYSPACE_REPLICATION = "cassandra.lock.keyspace.replication";
+    String LOCKS_KEYSPACE_STRATEGY = "cassandra.lock.keyspace.strategy";
+    String LOCKS_READ_CL = "cassandra.lock.readcl";
+    String LOCKS_WRITE_CL = "cassandra.lock.writecl";
+    String LOCKS_SHARED_POOL_FLAG = "cassandra.lock.use_shared_pool";
+    String LOCKS_CONNECTIONS = "cassandra.lock.connections";
 
-    public static final String READ_CL = "usergrid.read.cl";
 
-    public static final String WRITE_CL = "usergrid.write.cl";
 
-    public static final String SHARD_VALUES = "cassandra.shardvalues";
-
-    public static final String THRIFT_TRANSPORT_SIZE = "cassandra.thrift.transport.frame";
+    // re-usable default values
+    String DEFAULT_CONNECTION_POOLSIZE = "15";
 
 
     @Key( "cassandra.hosts" )
@@ -67,7 +77,7 @@ public interface CassandraFig extends GuicyFig {
     String getLocalDataCenter();
 
     @Key( "cassandra.connections" )
-    @Default( "15" )
+    @Default( DEFAULT_CONNECTION_POOLSIZE )
     int getConnections();
 
     @Key( "cassandra.timeout" )
@@ -111,5 +121,53 @@ public interface CassandraFig extends GuicyFig {
     int getThriftBufferSize();
 
 
+    /**
+     * Returns the name of the keyspace that should be used for Locking
+     */
+    @Key( LOCKS_KEYSPACE_NAME )
+    @Default("Locks")
+    String getLocksKeyspace();
+
+    /**
+     * Returns the Astyanax consistency level for reading a Lock
+     */
+    @Key( LOCKS_READ_CL )
+    @Default("CL_QUORUM")
+    String getLocksReadCl();
+
+    /**
+     * Returns the Astyanax consistency level for writing a Lock
+     */
+    @Key( LOCKS_WRITE_CL )
+    @Default("CL_QUORUM")
+    String getLocksWriteCl();
+
+    /**
+     * Returns a flag on whether or not to share the connection pool with other keyspaces
+     */
+    @Key( LOCKS_SHARED_POOL_FLAG )
+    @Default("true")
+    boolean useSharedPoolForLocks();
+
+    /**
+     * Returns a flag on whether or not to share the connection pool with other keyspaces
+     */
+    @Key( LOCKS_CONNECTIONS )
+    @Default( DEFAULT_CONNECTION_POOLSIZE )
+    int getConnectionsLocks();
+
+    /**
+     * Returns a flag on whether or not to share the connection pool with other keyspaces
+     */
+    @Key( LOCKS_KEYSPACE_REPLICATION )
+    @Default("replication_factor:1")
+    String getLocksKeyspaceReplication();
+
+    /**
+     * Returns a flag on whether or not to share the connection pool with other keyspaces
+     */
+    @Key( LOCKS_KEYSPACE_STRATEGY )
+    @Default( "org.apache.cassandra.locator.SimpleStrategy" )
+    String getLocksKeyspaceStrategy();
 
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/guice/CommonModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/guice/CommonModule.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/guice/CommonModule.java
index 75e2b29..f7a9926 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/guice/CommonModule.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/guice/CommonModule.java
@@ -19,12 +19,10 @@
 package org.apache.usergrid.persistence.core.guice;
 
 
+import com.netflix.astyanax.Keyspace;
+import org.apache.usergrid.persistence.core.astyanax.*;
 import org.safehaus.guicyfig.GuicyFigModule;
 
-import org.apache.usergrid.persistence.core.astyanax.AstyanaxKeyspaceProvider;
-import org.apache.usergrid.persistence.core.astyanax.CassandraConfig;
-import org.apache.usergrid.persistence.core.astyanax.CassandraConfigImpl;
-import org.apache.usergrid.persistence.core.astyanax.CassandraFig;
 import org.apache.usergrid.persistence.core.consistency.TimeService;
 import org.apache.usergrid.persistence.core.consistency.TimeServiceImpl;
 import org.apache.usergrid.persistence.core.guicyfig.ClusterFig;
@@ -46,7 +44,6 @@ import org.apache.usergrid.persistence.core.migration.schema.MigrationManagerImp
 import com.google.inject.AbstractModule;
 import com.google.inject.Key;
 import com.google.inject.multibindings.Multibinder;
-import com.netflix.astyanax.Keyspace;
 
 
 /**
@@ -57,9 +54,13 @@ public class CommonModule extends AbstractModule {
 
     @Override
     protected void configure() {
+
         //noinspection unchecked
         install(new GuicyFigModule(MigrationManagerFig.class, CassandraFig.class));
 
+        // bind our Cassandra cluster to the Astyanax Implementation
+        bind(CassandraCluster.class).to(CassandraClusterImpl.class).asEagerSingleton();
+
         // bind our keyspace to the AstyanaxKeyspaceProvider
         bind(Keyspace.class).toProvider(AstyanaxKeyspaceProvider.class).asEagerSingleton();
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java
index f1471ac..e02cafe 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java
@@ -26,11 +26,7 @@ import java.util.UUID;
 import org.apache.cassandra.db.marshal.BytesType;
 import org.apache.cassandra.db.marshal.UTF8Type;
 
-import org.apache.usergrid.persistence.core.astyanax.MultiTenantColumnFamily;
-import org.apache.usergrid.persistence.core.astyanax.MultiTenantColumnFamilyDefinition;
-import org.apache.usergrid.persistence.core.astyanax.ScopedRowKey;
-import org.apache.usergrid.persistence.core.astyanax.ScopedRowKeySerializer;
-import org.apache.usergrid.persistence.core.astyanax.StringRowCompositeSerializer;
+import org.apache.usergrid.persistence.core.astyanax.*;
 import org.apache.usergrid.persistence.core.migration.util.AstayanxUtils;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
@@ -78,8 +74,8 @@ public class MigrationInfoSerializationImpl implements MigrationInfoSerializatio
 
 
     @Inject
-    public MigrationInfoSerializationImpl( final Keyspace keyspace ) {
-        this.keyspace = keyspace;
+    public MigrationInfoSerializationImpl( final CassandraCluster cassandraCluster ) {
+        this.keyspace = cassandraCluster.getApplicationKeyspace();
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/ColumnNameIteratorTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/ColumnNameIteratorTest.java b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/ColumnNameIteratorTest.java
index d2c6f89..18c9327 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/ColumnNameIteratorTest.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/ColumnNameIteratorTest.java
@@ -59,6 +59,9 @@ public class ColumnNameIteratorTest {
     @Inject
     public CassandraFig cassandraFig;
 
+    @Inject
+    public CassandraCluster cassandraCluster;
+
     protected static Keyspace keyspace;
 
     protected ApplicationScope scope;
@@ -99,7 +102,7 @@ public class ColumnNameIteratorTest {
 
 
         AstyanaxKeyspaceProvider astyanaxKeyspaceProvider =
-                new AstyanaxKeyspaceProvider( cassandraFig, cassandraConfig );
+                new AstyanaxKeyspaceProvider( cassandraCluster );
 
         keyspace = astyanaxKeyspaceProvider.get();
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiKeyColumnNameIteratorTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiKeyColumnNameIteratorTest.java b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiKeyColumnNameIteratorTest.java
index 3c56763..bd1ea55 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiKeyColumnNameIteratorTest.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiKeyColumnNameIteratorTest.java
@@ -64,6 +64,9 @@ public class MultiKeyColumnNameIteratorTest {
     @Inject
     public CassandraFig cassandraFig;
 
+    @Inject
+    public CassandraCluster cassandraCluster;
+
     protected static Keyspace keyspace;
 
     protected ApplicationScope scope;
@@ -104,7 +107,7 @@ public class MultiKeyColumnNameIteratorTest {
 
 
         AstyanaxKeyspaceProvider astyanaxKeyspaceProvider =
-                new AstyanaxKeyspaceProvider( cassandraFig, cassandraConfig );
+                new AstyanaxKeyspaceProvider( cassandraCluster );
 
         keyspace = astyanaxKeyspaceProvider.get();
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java
index d88ebe5..9f5741b 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/MultiRowColumnIteratorTest.java
@@ -67,6 +67,9 @@ public class MultiRowColumnIteratorTest {
     @Inject
     public CassandraFig cassandraFig;
 
+    @Inject
+    public CassandraCluster cassandraCluster;
+
     protected static Keyspace keyspace;
 
     protected ApplicationScope scope;
@@ -107,7 +110,7 @@ public class MultiRowColumnIteratorTest {
 
 
         AstyanaxKeyspaceProvider astyanaxKeyspaceProvider =
-                new AstyanaxKeyspaceProvider( cassandraFig, cassandraConfig );
+                new AstyanaxKeyspaceProvider( cassandraCluster );
 
         keyspace = astyanaxKeyspaceProvider.get();
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/TestUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/TestUtils.java b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/TestUtils.java
index 8ee7e36..de2609d 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/TestUtils.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/TestUtils.java
@@ -55,7 +55,7 @@ public class TestUtils {
 
 
         try {
-            keyspace.createKeyspace( options );
+            keyspace.createKeyspaceIfNotExists( options );
         }
         catch ( Throwable t ) {
           logger.info( "Error on creating keyspace, ignoring", t );
@@ -68,7 +68,11 @@ public class TestUtils {
 
     public static <K, C> void createColumnFamiliy(final Keyspace keyspace, final ColumnFamily<K, C> columnFamily, final Map<String, Object> options){
         try{
-            keyspace.createColumnFamily( columnFamily, new HashMap<String, Object>() );
+
+            if(keyspace.describeKeyspace().getColumnFamily(columnFamily.getName()) == null){
+                keyspace.createColumnFamily( columnFamily, new HashMap<String, Object>() );
+            }
+
         }catch(Exception e){
            logger.error( "Error on creating column family, ignoring" , e);
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index 802f7b5..c15ea4b 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -98,6 +98,7 @@
         <!-- =================================================================== -->
 
         <amber-version>0.22-incubating</amber-version>
+        <astyanax.version>1.56.49-SNAPSHOT-UG-1</astyanax.version>
         <aws.version>1.10.20</aws.version>
         <cassandra-version>1.2.18</cassandra-version>
         <guava.version>18.0</guava.version>
@@ -1254,6 +1255,12 @@
                 <version>${io.apigee.gcm.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>com.netflix.astyanax</groupId>
+                <artifactId>astyanax-recipes</artifactId>
+                <version>${astyanax.version}</version>
+            </dependency>
+
         </dependencies>
 
     </dependencyManagement>

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java b/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java
index abab195..5274336 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java
@@ -21,6 +21,8 @@ import java.util.List;
 import java.util.Properties;
 import java.util.UUID;
 
+import com.google.inject.Injector;
+import org.apache.usergrid.locking.Lock;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
@@ -47,11 +49,11 @@ public class ServiceManagerFactory implements ApplicationContextAware {
 
 
     public ServiceManagerFactory( EntityManagerFactory emf, Properties properties, SchedulerService schedulerService,
-                                  LockManager lockManager, QueueManagerFactory qmf ) {
+                                  QueueManagerFactory qmf, final Injector injector ) {
         this.emf = emf;
         this.properties = properties;
         this.schedulerService = schedulerService;
-        this.lockManager = lockManager;
+        lockManager = injector.getInstance(LockManager.class);
         this.qmf = qmf;
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/services/src/main/resources/usergrid-services-context.xml
----------------------------------------------------------------------
diff --git a/stack/services/src/main/resources/usergrid-services-context.xml b/stack/services/src/main/resources/usergrid-services-context.xml
index a3c353f..02e01ad 100644
--- a/stack/services/src/main/resources/usergrid-services-context.xml
+++ b/stack/services/src/main/resources/usergrid-services-context.xml
@@ -69,11 +69,15 @@
 
 	<bean id="saltProvider" class="org.apache.usergrid.security.salt.NoOpSaltProvider" />
 
+    <bean id="injector"
+          class="org.apache.usergrid.corepersistence.GuiceFactory">
+    </bean>
+
 	<bean id="serviceManagerFactory" class="org.apache.usergrid.services.ServiceManagerFactory">
 		<constructor-arg ref="entityManagerFactory" />
 		<constructor-arg ref="properties" />
 		<constructor-arg ref="schedulerService"/>
-        <constructor-arg ref="lockManager"/>
+        <constructor-arg ref="injector"/>
         <constructor-arg ref="queueManagerFactory"/>
 	</bean>
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/71f32747/stack/websocket/src/test/resources/testApplicationContext.xml
----------------------------------------------------------------------
diff --git a/stack/websocket/src/test/resources/testApplicationContext.xml b/stack/websocket/src/test/resources/testApplicationContext.xml
index 8eccb74..8363021 100644
--- a/stack/websocket/src/test/resources/testApplicationContext.xml
+++ b/stack/websocket/src/test/resources/testApplicationContext.xml
@@ -102,14 +102,20 @@
 		<constructor-arg ref="cassandraCredentials" />
 	</bean>
 
-	<bean name="lockManager" class="org.apache.usergrid.locking.cassandra.HectorLockManagerImpl" />
+	<!--
+    <bean name="lockManager" class="org.apache.usergrid.locking.cassandra.HectorLockManagerImpl" />
+    -->
+
+    <bean id="injector"
+          class="org.apache.usergrid.corepersistence.GuiceFactory">
+    </bean>
 
 	<bean id="cassandraService"
 		class="org.apache.usergrid.persistence.cassandra.CassandraService" init-method="init">
 		<constructor-arg ref="properties" />
 		<constructor-arg ref="cassandraCluster" />
 		<constructor-arg ref="cassandraHostConfigurator" />
-		<constructor-arg ref="lockManager" />
+		<constructor-arg ref="injector" />
 	</bean>
 
 	<bean id="entityManagerFactory"


Mime
View raw message