usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject usergrid git commit: Make Locks keyspace creation more robust ( IF NOT EXISTS sometimes has problems ).
Date Wed, 25 Jan 2017 18:14:06 GMT
Repository: usergrid
Updated Branches:
  refs/heads/master 280ac8b1e -> 691d6b2ec


Make Locks keyspace creation more robust ( IF NOT EXISTS sometimes has problems ).


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

Branch: refs/heads/master
Commit: 691d6b2ec99c9c98dd9954b666c373932fa093c7
Parents: 280ac8b
Author: Michael Russo <mrusso@apigee.com>
Authored: Wed Jan 25 10:13:39 2017 -0800
Committer: Michael Russo <mrusso@apigee.com>
Committed: Wed Jan 25 10:13:39 2017 -0800

----------------------------------------------------------------------
 .../cassandra/AstyanaxLockManagerImpl.java      | 28 +++++++++++---------
 1 file changed, 15 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/691d6b2e/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
index c0b1f03..a4efde8 100644
--- 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
@@ -21,9 +21,7 @@ import com.google.common.collect.ImmutableMap;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import com.netflix.astyanax.Keyspace;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-import com.netflix.astyanax.connectionpool.exceptions.NoAvailableHostsException;
-import com.netflix.astyanax.connectionpool.exceptions.PoolTimeoutException;
+import com.netflix.astyanax.connectionpool.exceptions.*;
 import com.netflix.astyanax.ddl.ColumnFamilyDefinition;
 import com.netflix.astyanax.ddl.KeyspaceDefinition;
 import com.netflix.astyanax.model.ColumnFamily;
@@ -195,20 +193,24 @@ public class AstyanaxLockManagerImpl implements LockManager {
 
     private void createLocksKeyspace() throws ConnectionException {
 
-        ImmutableMap.Builder<String, Object> strategyOptions = getKeySpaceProps();
+        try {
+            KeyspaceDefinition keyspaceDefinition = keyspace.describeKeyspace();
+            if ( keyspaceDefinition != null ) {
+                logger.info("Keyspace {} already exists", keyspace.getKeyspaceName());
+                return;
+            }
+        } catch (ConnectionException ce){
+            logger.debug( "Received a NotFoundException when attempting to describe keyspace.
 It does not exist" );
+        }
 
+        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 );
+            ImmutableMap.<String, Object>builder().put("strategy_class", cassandraFig.getLocksKeyspaceStrategy())
+                .put("strategy_options", strategyOptions.build()).build();
 
-        strategyOptions.toString();
+        keyspace.createKeyspace(options);
+        logger.info("Keyspace {} created with options {}",  keyspace.getKeyspaceName(), options.toString());
 
-        logger.info( "Keyspace {} created or already exists with options {}",
-            keyspace.getKeyspaceName(),
-            options.toString() );
     }
 
     /**


Mime
View raw message