usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject usergrid git commit: First pass at creating a locks module
Date Tue, 01 Sep 2015 22:08:29 GMT
Repository: usergrid
Updated Branches:
  refs/heads/USERGRID-909 a3cf062ce -> 46033cdea


First pass at creating a locks module


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

Branch: refs/heads/USERGRID-909
Commit: 46033cdea157b4cf518b742022e76f6ce173ea5d
Parents: a3cf062
Author: Todd Nine <tnine@apigee.com>
Authored: Tue Sep 1 16:08:25 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Tue Sep 1 16:08:25 2015 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/core/CPManager.java    | 28 ------
 .../core/consistency/SubscriberFactory.java     | 33 -------
 .../persistence/graph/GraphManager.java         |  3 +-
 .../impl/shard/ShardEntryGroup.java             | 21 +++++
 .../shard/impl/NodeShardAllocationImpl.java     | 16 +++-
 .../shard/impl/ShardGroupCompactionImpl.java    |  1 -
 .../graph/GraphManagerShardConsistencyIT.java   |  1 +
 stack/corepersistence/locks/pom.xml             | 55 ++++++++++++
 .../apache/usergrid/persistence/locks/Lock.java | 44 +++++++++
 .../usergrid/persistence/locks/LockId.java      | 31 +++++++
 .../usergrid/persistence/locks/LockManager.java | 44 +++++++++
 .../persistence/locks/guice/LockModule.java     | 42 +++++++++
 .../locks/impl/CassandraLockManager.java        | 53 +++++++++++
 .../locks/impl/CassandraMultiRegionLock.java    | 70 +++++++++++++++
 .../impl/NodeShardProposalSerialization.java    | 53 +++++++++++
 .../NodeShardProposalSerializationImpl.java     | 48 ++++++++++
 .../persistence/locks/impl/Proposal.java        | 95 ++++++++++++++++++++
 stack/corepersistence/pom.xml                   |  1 +
 .../usergrid/persistence/index/EntityIndex.java |  9 +-
 19 files changed, 576 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/CPManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/CPManager.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/CPManager.java
deleted file mode 100644
index 347080f..0000000
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/CPManager.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *
- *  * 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.persistence.core;
-/**
- * Base Manager Class
- */
-
-public interface CPManager {
-}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/consistency/SubscriberFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/consistency/SubscriberFactory.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/consistency/SubscriberFactory.java
deleted file mode 100644
index 4d6a595..0000000
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/consistency/SubscriberFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.consistency;
-
-
-import rx.Subscriber;
-
-
-/**
- * Interface to create subscriptions.  Useful for creating custom listeners or composite
functionality
- * @param <T>
- */
-public interface SubscriberFactory<T> {
-
-
-    public Subscriber<T> getSubcriber();
-}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManager.java
b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManager.java
index 6100725..e06d6a5 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManager.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphManager.java
@@ -20,7 +20,6 @@
 package org.apache.usergrid.persistence.graph;
 
 
-import org.apache.usergrid.persistence.core.CPManager;
 import org.apache.usergrid.persistence.model.entity.Id;
 
 import rx.Observable;
@@ -50,7 +49,7 @@ import rx.Observable;
  * @author tnine
  * @see Edge
  */
-public interface GraphManager extends CPManager {
+public interface GraphManager {
 
 
     /**

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/ShardEntryGroup.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/ShardEntryGroup.java
b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/ShardEntryGroup.java
index 333c3bb..cc8dceb 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/ShardEntryGroup.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/ShardEntryGroup.java
@@ -314,6 +314,27 @@ public class ShardEntryGroup {
 
 
     @Override
+    public boolean equals( final Object o ) {
+        if ( this == o ) {
+            return true;
+        }
+        if ( !( o instanceof ShardEntryGroup ) ) {
+            return false;
+        }
+
+        final ShardEntryGroup that = ( ShardEntryGroup ) o;
+
+        return shards.equals( that.shards );
+    }
+
+
+    @Override
+    public int hashCode() {
+        return shards.hashCode();
+    }
+
+
+    @Override
     public String toString() {
         return "ShardEntryGroup{" +
             "shards=" + shards +

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardAllocationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardAllocationImpl.java
b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardAllocationImpl.java
index 60e0376..3af2c41 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardAllocationImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardAllocationImpl.java
@@ -152,10 +152,17 @@ public class NodeShardAllocationImpl implements NodeShardAllocation
{
 
         final ShardEntryGroup shardEntryGroup = shardEntryGroupIterator.next();
 
+        //someone has already allocated, it's a different group.  Move on, nothing to see
here
+        if ( !shardEntryGroup.equals( lastLoadedShardEntryGroup ) ) {
+            logger.info( "Stale shard group on audit or group {} found, ignoring", lastLoadedShardEntryGroup
);
+            return false;
+        }
+
         /**
          * Nothing to do, it's been created very recently, we don't create a new one
          */
         if ( shardEntryGroup.isCompactionPending() ) {
+            logger.info("Shard group {} is compacting, skipping", lastLoadedShardEntryGroup);
             return false;
         }
 
@@ -225,8 +232,9 @@ public class NodeShardAllocationImpl implements NodeShardAllocation {
          * element will suffice.
          */
 
+        long i = 1;
 
-        for ( long i = 1; edges.hasNext(); i++ ) {
+        for ( ; edges.hasNext(); i++ ) {
             //we hit a pivot shard, set it since it could be the last one we encounter
             if ( i % shardSize == 0 ) {
                 marked = edges.next();
@@ -236,6 +244,8 @@ public class NodeShardAllocationImpl implements NodeShardAllocation {
             }
         }
 
+        logger.debug( "Iterated {} edges to find the last marked edge", i );
+
 
         /**
          * Sanity check in case our counters become severely out of sync with our edge state
in cassandra.
@@ -249,7 +259,7 @@ public class NodeShardAllocationImpl implements NodeShardAllocation {
 
         final Shard newShard = new Shard( marked.getTimestamp(), createTimestamp, false );
 
-        logger.info( "Allocating new shard {} for edge meta {}", newShard, directedEdgeMeta
);
+        logger.info( "Allocating new shard {} for edge meta {} into group {}", newShard,
directedEdgeMeta, shardEntryGroup );
 
         final MutationBatch batch = this.edgeShardSerialization.writeShardMeta( scope, newShard,
directedEdgeMeta );
 
@@ -274,7 +284,7 @@ public class NodeShardAllocationImpl implements NodeShardAllocation {
 
         //we're not the target of compaction, remove ourselves
         if ( !newShard.equals( currentStateGroup.getCompactionTarget() ) ) {
-            logger.debug("Our proposed shard is not the comaction target.  Removing shard
{}", newShard);
+            logger.debug( "Our proposed shard is not the comaction target.  Removing shard
{}", newShard );
             this.edgeShardSerialization.removeShardMeta( scope, newShard, directedEdgeMeta
);
         }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/ShardGroupCompactionImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/ShardGroupCompactionImpl.java
b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/ShardGroupCompactionImpl.java
index f33181f..77ff53d 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/ShardGroupCompactionImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/ShardGroupCompactionImpl.java
@@ -141,7 +141,6 @@ public class ShardGroupCompactionImpl implements ShardGroupCompaction
{
                                      final ShardEntryGroup group ) {
 
 
-        final long startTime = timeService.getCurrentTime();
 
 
         Preconditions.checkNotNull( group, "group cannot be null" );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java
b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java
index 5b240f9..9d4273f 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerShardConsistencyIT.java
@@ -316,6 +316,7 @@ public class GraphManagerShardConsistencyIT {
 
                 log.info( "Compaction pending status for group {} is {}", group, group.isCompactionPending()
);
 
+                //we don't count compaction pending groups, we need to ensure they're completed
compacting before testing
                 if ( !group.isCompactionPending() ) {
                     compactedCount++;
                 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/pom.xml b/stack/corepersistence/locks/pom.xml
new file mode 100644
index 0000000..8747658
--- /dev/null
+++ b/stack/corepersistence/locks/pom.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<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.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <description>The module for handling all distributed locks</description>
+
+    <name>Usergrid Locks</name>
+
+    <artifactId>locks</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.usergrid</groupId>
+            <artifactId>common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <!-- tests -->
+
+        <dependency>
+            <groupId>org.apache.usergrid</groupId>
+            <artifactId>common</artifactId>
+            <version>${project.version}</version>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/Lock.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/Lock.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/Lock.java
new file mode 100644
index 0000000..2729066
--- /dev/null
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/Lock.java
@@ -0,0 +1,44 @@
+/*
+ * 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.locks;
+
+
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * Interface for lock operations
+ */
+public interface Lock {
+
+    /**
+     * Try the lock. Return true if it was acquired, false otherwise.
+     *
+     * @param timeToLive The maximum amount of time the lock can exist.  After this time,
the lock will no longer be valid.
+     *
+     * @return True if the lock was acquired, false otherwise
+     */
+    boolean tryLock( final long timeToLive, final TimeUnit timeUnit );
+
+    /**
+     * Unlock this lock
+     */
+    void unlock();
+
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/LockId.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/LockId.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/LockId.java
new file mode 100644
index 0000000..ca7001e
--- /dev/null
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/LockId.java
@@ -0,0 +1,31 @@
+/*
+ * 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.locks;
+
+
+/**
+ * Key that uniquely represents a lock
+ */
+public interface LockId {
+
+    /**
+     * Generate a string unique key for this lock.  Note that this key can be used by multiple
processes
+     * @return
+     */
+    String generateKey();
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/LockManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/LockManager.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/LockManager.java
new file mode 100644
index 0000000..16d2c3e
--- /dev/null
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/LockManager.java
@@ -0,0 +1,44 @@
+/*
+ * 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.locks;
+
+
+/**
+ * A simple interface for distributed locks.  These locks can be assumed to be cluster wide
in multi regions. It is up
+ * to the implementor to determine how to best accomplish this.
+ */
+public interface LockManager {
+
+
+    /**
+     * Create a lock instance with the given key that is valid across all regions
+     *
+     * @param key The key to use when locking
+     *
+     *
+     * @return A new instance of the lock, without any lock acquired
+     */
+    Lock createMultiRegionLock( final LockId key );
+
+    /**
+     * Create a lock in the local region
+     * @param key
+     * @return
+     */
+    Lock createLocalLock(final LockId key);
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/guice/LockModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/guice/LockModule.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/guice/LockModule.java
new file mode 100644
index 0000000..3bd0e0a
--- /dev/null
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/guice/LockModule.java
@@ -0,0 +1,42 @@
+/*
+ * 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.locks.guice;
+
+
+import org.apache.usergrid.persistence.locks.LockManager;
+import org.apache.usergrid.persistence.locks.impl.CassandraLockManager;
+import org.apache.usergrid.persistence.locks.impl.NodeShardProposalSerialization;
+import org.apache.usergrid.persistence.locks.impl.NodeShardProposalSerializationImpl;
+
+import com.google.inject.AbstractModule;
+
+
+/**
+ * Guice configuration of the lock module
+ */
+public abstract class LockModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+
+        //bind our lockManager
+        bind( LockManager.class).to( CassandraLockManager.class );
+
+        bind( NodeShardProposalSerialization.class).to( NodeShardProposalSerializationImpl.class
);
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraLockManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraLockManager.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraLockManager.java
new file mode 100644
index 0000000..61e243e
--- /dev/null
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraLockManager.java
@@ -0,0 +1,53 @@
+/*
+ * 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.locks.impl;
+
+
+import org.apache.usergrid.persistence.locks.Lock;
+import org.apache.usergrid.persistence.locks.LockId;
+import org.apache.usergrid.persistence.locks.LockManager;
+
+import com.google.common.base.Preconditions;
+
+
+/**
+ * Create a lock manager that is cassandra based
+ */
+public class CassandraLockManager implements LockManager {
+
+    private final NodeShardProposalSerialization nodeShardProposalSerialization;
+
+
+    public CassandraLockManager( final NodeShardProposalSerialization nodeShardProposalSerialization
) {
+        this.nodeShardProposalSerialization = nodeShardProposalSerialization;
+    }
+
+
+    @Override
+    public Lock createMultiRegionLock( final LockId key ) {
+        Preconditions.checkNotNull(key, "Key is required");
+
+        return new CassandraMultiRegionLock(key, nodeShardProposalSerialization);
+    }
+
+
+    @Override
+    public Lock createLocalLock( final LockId key ) {
+        throw new UnsupportedOperationException( "Only multi region locks are supported"
);
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraMultiRegionLock.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraMultiRegionLock.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraMultiRegionLock.java
new file mode 100644
index 0000000..decacc2
--- /dev/null
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraMultiRegionLock.java
@@ -0,0 +1,70 @@
+/*
+ * 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.locks.impl;
+
+
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.usergrid.persistence.locks.Lock;
+import org.apache.usergrid.persistence.locks.LockId;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.common.base.Preconditions;
+
+
+/**
+ * Lock that uses cassandra for multiple regions
+ */
+public class CassandraMultiRegionLock implements Lock {
+
+    private final LockId lockId;
+    private final NodeShardProposalSerialization nodeShardProposalSerialization;
+    private final UUID lockUUID;
+
+
+    public CassandraMultiRegionLock(final LockId lockId,
+                          final NodeShardProposalSerialization nodeShardProposalSerialization
) {
+        this.lockId = lockId;
+        this.nodeShardProposalSerialization = nodeShardProposalSerialization;
+        this.lockUUID = UUIDGenerator.newTimeUUID();
+    }
+
+
+    @Override
+    public boolean tryLock( final long timeToLive, final TimeUnit timeUnit ) {
+
+        final long expiration = timeUnit.toSeconds( timeToLive );
+
+        Preconditions.checkArgument(expiration > Integer.MAX_VALUE, "Expiration cannot
be longer than "  + Integer.MAX_VALUE);
+
+        this.nodeShardProposalSerialization.writeNewValue( lockId, lockUUID, ( int ) expiration
);
+
+        //now read back our proposal
+
+
+
+        return false;
+    }
+
+
+    @Override
+    public void unlock() {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/NodeShardProposalSerialization.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/NodeShardProposalSerialization.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/NodeShardProposalSerialization.java
new file mode 100644
index 0000000..6bf294e
--- /dev/null
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/NodeShardProposalSerialization.java
@@ -0,0 +1,53 @@
+/*
+ * 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.locks.impl;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.locks.LockId;
+
+
+/**
+ * Interface for serializing node shard proposals
+ */
+public interface NodeShardProposalSerialization {
+
+
+    /**
+     * Propose a new shard and return the UUID of the proposal
+     * @param lockId The key for the locks
+     * @param proposed The proposed time uuid key
+     * @param expirationInSeconds The time to allow the proposal to live.
+     */
+    void writeNewValue( final LockId lockId, final UUID proposed, final int expirationInSeconds
);
+
+    /**
+     * Get the proposed locks from the proposed value
+     * @param lockId The key for the locks
+     * @return
+     */
+    Proposal getProposal(  final LockId lockId);
+
+    /**
+     * Remove all the proposals
+     * @param lockId The key for the locks
+     * @param proposed The proposed value
+     */
+    void delete(  final LockId lockId, final UUID proposed );
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/NodeShardProposalSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/NodeShardProposalSerializationImpl.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/NodeShardProposalSerializationImpl.java
new file mode 100644
index 0000000..9fb35d5
--- /dev/null
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/NodeShardProposalSerializationImpl.java
@@ -0,0 +1,48 @@
+/*
+ * 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.locks.impl;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.locks.LockId;
+
+
+/**
+ * Serialization of locks
+ */
+public class NodeShardProposalSerializationImpl implements NodeShardProposalSerialization
{
+
+
+    @Override
+    public void writeNewValue( final LockId lockId, final UUID proposed, final int expirationInSeconds
) {
+
+    }
+
+
+    @Override
+    public Proposal getProposal( final LockId lockId ) {
+        return null;
+    }
+
+
+    @Override
+    public void delete( final LockId lockId, final UUID proposed ) {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/Proposal.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/Proposal.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/Proposal.java
new file mode 100644
index 0000000..4eb91e0
--- /dev/null
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/Proposal.java
@@ -0,0 +1,95 @@
+/*
+ * 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.locks.impl;
+
+
+import java.util.UUID;
+
+import com.fasterxml.uuid.UUIDComparator;
+import com.google.common.base.Optional;
+
+
+/**
+ * Represents a proposed value
+ */
+public class Proposal {
+
+
+    private final UUID first;
+    private final Optional<UUID> second;
+    private final Optional<UUID> secondAcked;
+
+
+    public Proposal( final UUID first, final Optional<UUID> second, final Optional<UUID>
secondAcked ) {
+        this.first = first;
+        this.second = second;
+        this.secondAcked = secondAcked;
+    }
+
+
+    /**
+     * Return true if the proposedUuid is the first UUID
+     * @param proposedUuid
+     * @return
+     */
+    public boolean isFirst(final UUID proposedUuid){
+        return UUIDComparator.staticCompare( first, proposedUuid ) ==0 ;
+    }
+
+
+    /**
+     * Return trus if the proposedUuid is the
+     * @param proposedUuid
+     * @return
+     */
+    public boolean isLocked(final UUID proposedUuid){
+        if(!isFirst( proposedUuid )) {
+            return false;
+        }
+
+
+        //we have an "acked" value from a previous time uuid.  Compare them and be sure the
+        //second has recognized the first as the being first, otherwise we can't proceed.
+        if(secondAcked.isPresent()) {
+            return UUIDComparator.staticCompare( first, secondAcked.get() ) == 0;
+        }
+
+        //there is no second we have the lock
+        return true;
+    }
+
+
+    /**
+     * True if the proposed UUID is the second Id, and we haven't acked the first
+     *
+     * @param proposedUuid
+     * @return
+     */
+    public boolean shouldAck(final UUID proposedUuid){
+        //no second, or the second isn't equal to our proposed
+        if(!second.isPresent() || UUIDComparator.staticCompare( proposedUuid, second.get())
!= 0){
+            return false;
+        }
+
+        /**
+         * If our second hasn't acked the first, ack it
+         */
+        return !secondAcked.isPresent();
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 4b47bc0..9fd67d0 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -86,6 +86,7 @@ limitations under the License.
         <module>common</module>
         <module>map</module>
         <module>queue</module>
+        <module>locks</module>
     </modules>
 
     <build>

http://git-wip-us.apache.org/repos/asf/usergrid/blob/46033cde/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
index 7fa2f07..84b90c9 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
@@ -20,19 +20,18 @@
 package org.apache.usergrid.persistence.index;
 
 
-import com.google.common.base.Optional;
-import org.apache.usergrid.persistence.core.CPManager;
+import java.util.UUID;
+
 import org.apache.usergrid.persistence.core.util.Health;
 import org.apache.usergrid.persistence.model.entity.Id;
-import rx.Observable;
 
-import java.util.UUID;
+import rx.Observable;
 
 
 /**
  * Provides management operations for single index
  */
-public interface EntityIndex extends CPManager {
+public interface EntityIndex {
 
 
     public static final int MAX_LIMIT = 1000;


Mime
View raw message