usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [21/44] usergrid git commit: Add retry logic and logging in AstyanaxLockManagerImpl and CpEntityManagerFactory, also ASL header in CassandraCluster
Date Tue, 14 Jun 2016 17:15:00 GMT
Add retry logic and logging in AstyanaxLockManagerImpl and CpEntityManagerFactory, also ASL
header in CassandraCluster


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

Branch: refs/heads/usergrid-1268-akka-211
Commit: 910811d258b359a3c207c1ef34014d1ba28afebe
Parents: ba10e7f
Author: Dave Johnson <snoopdave@apache.org>
Authored: Wed May 25 13:56:51 2016 -0400
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Wed May 25 13:56:51 2016 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java |  8 ++---
 .../cassandra/AstyanaxLockManagerImpl.java      | 36 +++++++++++++-------
 .../core/astyanax/CassandraCluster.java         | 24 ++++++++++---
 3 files changed, 47 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/910811d2/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index d2417be..84872aa 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -174,17 +174,17 @@ public class CpEntityManagerFactory implements EntityManagerFactory,
Application
         int maxRetries = 1000;
         int retries = 0;
         boolean managementAppFound = false;
-        Set<Class> seenBefore = new HashSet<>(100);
         while ( !managementAppFound && retries++ < maxRetries ) {
             try {
                 getEntityManager( getManagementAppId() ).getApplication();
                 managementAppFound = true;
 
             } catch ( Throwable t ) {
-                if ( seenBefore.contains( t.getClass() )) { // don't log full stack trace
if we've seen same before
-                    logger.error("Error {} getting management app on try {}", t.getClass().getSimpleName(),
retries);
+                String msg = "Error " + t.getClass() + " getting management app on try "
+ retries;
+                if ( logger.isDebugEnabled() ) {
+                    logger.error( msg, t);
                 } else {
-                    logger.error("Error getting management app on try {}", t.getClass().getSimpleName(),
t);
+                    logger.error(msg);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/910811d2/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 a69aee2..49ff52e 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
@@ -37,9 +37,7 @@ 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;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 @Singleton
@@ -50,8 +48,8 @@ public class AstyanaxLockManagerImpl implements LockManager {
 
 
     private final CassandraFig cassandraFig;
-    private final Keyspace keyspace;
-    private final ColumnFamily columnFamily;
+    private Keyspace keyspace;
+    private ColumnFamily columnFamily;
     private static final int MINIMUM_LOCK_EXPIRATION = 60000; // 1 minute
 
     @Inject
@@ -59,14 +57,28 @@ public class AstyanaxLockManagerImpl implements LockManager {
                                    CassandraCluster cassandraCluster ) throws ConnectionException
{
 
         this.cassandraFig = cassandraFig;
-        this.keyspace = cassandraCluster.getLocksKeyspace();
-
-        createLocksKeyspace();
-
-        this.columnFamily = createLocksColumnFamily();
-
-
 
+        // hold up construction until we can create the column family
+        int maxRetries = 1000;
+        int retries = 0;
+        boolean famReady = false;
+        while ( !famReady && retries++ < maxRetries ) {
+            try {
+                keyspace = cassandraCluster.getLocksKeyspace();
+                createLocksKeyspace();
+                columnFamily = createLocksColumnFamily();
+                famReady = true;
+
+            } catch ( Throwable t ) {
+                String msg = "Error " + t.getClass().getSimpleName() + " creating locks keyspace
try " + retries;
+                if ( logger.isDebugEnabled() ) {
+                    logger.error( msg, t );
+                } else {
+                    logger.error( msg );
+                }
+                try { Thread.sleep(1000); } catch (InterruptedException ignored) {}
+            }
+        }
 
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/910811d2/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
index 0adac8e..6abc143 100644
--- 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
@@ -1,15 +1,29 @@
-package org.apache.usergrid.persistence.core.astyanax;
-
+/*
+ * 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 com.netflix.astyanax.Keyspace;
-
 import java.util.Map;
 
-
 public interface CassandraCluster {
 
-
     Map<String, Keyspace> getKeyspaces();
 
     Keyspace getApplicationKeyspace();


Mime
View raw message