usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject incubator-usergrid git commit: Fixes issue with atomically moving indexes
Date Wed, 18 Mar 2015 16:05:58 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-490 03341191a -> c16bb0039


Fixes issue with atomically moving indexes


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

Branch: refs/heads/USERGRID-490
Commit: c16bb003931e273dd8d5e57e833c82dac1927fed
Parents: 0334119
Author: Todd Nine <tnine@apigee.com>
Authored: Wed Mar 18 10:05:55 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Wed Mar 18 10:05:55 2015 -0600

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           | 83 +++++++++-----------
 1 file changed, 35 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c16bb003/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 16f4b3f..cae9cb0 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -56,6 +56,8 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
 import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest;
 import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse;
+import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
+import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
 import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
@@ -110,8 +112,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
     private final IndexBufferProducer indexBatchBufferProducer;
     private final IndexFig indexFig;
     private final Timer addTimer;
-    private final Timer addWriteAliasTimer;
-    private final Timer addReadAliasTimer;
+    private final Timer updateAliasTimer;
     private final Timer searchTimer;
 
     /**
@@ -142,7 +143,6 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
     private static final MatchAllQueryBuilder MATCH_ALL_QUERY_BUILDER = QueryBuilders.matchAllQuery();
 
     private EsIndexCache aliasCache;
-    private Timer removeAliasTimer;
     private Timer mappingTimer;
     private Timer refreshTimer;
     private Timer cursorTimer;
@@ -171,12 +171,8 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         this.aliasCache = indexCache;
         this.addTimer = metricsFactory
             .getTimer( EsEntityIndexImpl.class, "add.timer" );
-        this.removeAliasTimer = metricsFactory
-            .getTimer( EsEntityIndexImpl.class, "remove.alias.timer" );
-        this.addReadAliasTimer = metricsFactory
-            .getTimer( EsEntityIndexImpl.class, "add.read.alias.timer" );
-        this.addWriteAliasTimer = metricsFactory
-            .getTimer( EsEntityIndexImpl.class, "add.write.alias.timer" );
+        this.updateAliasTimer = metricsFactory
+            .getTimer( EsEntityIndexImpl.class, "update.alias.timer" );
         this.mappingTimer = metricsFactory
             .getTimer( EsEntityIndexImpl.class, "create.mapping.timer" );
         this.refreshTimer = metricsFactory
@@ -261,60 +257,51 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
     @Override
     public void addAlias(final String indexSuffix) {
+
+        final Timer.Context timeRemoveAlias = updateAliasTimer.time();
         try {
-            Boolean isAck;
-            String indexName = indexIdentifier.getIndex(indexSuffix);
-            final AdminClient adminClient = esProvider.getClient().admin();
 
-            String[] indexNames = getIndexes(AliasType.Write);
 
-            for ( String currentIndex : indexNames ) {
+            String indexName = indexIdentifier.getIndex(indexSuffix);
+            final AdminClient adminClient = esProvider.getClient().admin();
 
-                final Timer.Context timeRemoveAlias = removeAliasTimer.time();
+            String[] indexNames = getIndexesFromEs( AliasType.Write );
 
-                try {
-                    //Added For Graphite Metrics
 
-                    isAck = adminClient.indices().prepareAliases().removeAlias( currentIndex,
alias.getWriteAlias() )
-                                       .execute().actionGet().isAcknowledged();
+            final IndicesAliasesRequestBuilder aliasesRequestBuilder = adminClient.indices().prepareAliases();
 
-                    logger.info( "Removed Index Name [{}] from Alias=[{}] ACK=[{}]", currentIndex,
alias, isAck );
-                }
-                catch ( AliasesMissingException aie ) {
-                    logger.info( "Alias does not exist Index Name [{}] from Alias=[{}] ACK=[{}]",
currentIndex, alias,
-                        aie.getMessage() );
-                    continue;
-                }
-                catch ( InvalidAliasNameException iane ) {
-                    logger.info( "Alias does not exist Index Name [{}] from Alias=[{}] ACK=[{}]",
currentIndex, alias,
-                        iane.getMessage() );
-                    continue;
-                }
-                finally {
-                    timeRemoveAlias.stop();
-                }
+            //remove the write alias from it's target
+            for ( String currentIndex : indexNames ) {
+                aliasesRequestBuilder.removeAlias( currentIndex, alias.getWriteAlias() );
+                logger.info("Removing existing write Alias Name [{}] from Index [{}]", alias.getReadAlias(),
currentIndex);
             }
 
             //Added For Graphite Metrics
-            Timer.Context timeAddReadAlias = addReadAliasTimer.time();
+
             // add read alias
-            isAck = adminClient.indices().prepareAliases().addAlias(
-                    indexName, alias.getReadAlias()).execute().actionGet().isAcknowledged();
-            timeAddReadAlias.stop();
-            logger.info("Created new read Alias Name [{}] ACK=[{}]", alias.getReadAlias(),
isAck);
+            aliasesRequestBuilder.addAlias(  indexName, alias.getReadAlias());
+            logger.info("Created new read Alias Name [{}] on Index [{}]", alias.getReadAlias(),
indexName);
+
 
-            //Added For Graphite Metrics
-            Timer.Context timeAddWriteAlias = addWriteAliasTimer.time();
             //add write alias
-            isAck = adminClient.indices().prepareAliases().addAlias(
-                    indexName, alias.getWriteAlias()).execute().actionGet().isAcknowledged();
-            timeAddWriteAlias.stop();
-            logger.info("Created new write Alias Name [{}] ACK=[{}]", alias.getWriteAlias(),
isAck);
+            aliasesRequestBuilder.addAlias( indexName, alias.getWriteAlias() );
 
-            aliasCache.invalidate(alias);
+            logger.info("Created new write Alias Name [{}] on Index [{}]", alias.getWriteAlias(),
indexName);
+
+            final IndicesAliasesResponse result = aliasesRequestBuilder.execute().actionGet();
 
-        } catch (Exception e) {
-            logger.warn("Failed to create alias ", e);
+            final boolean isAcknowledged = result.isAcknowledged();
+
+            if(!isAcknowledged){
+                throw new RuntimeException( "Unable to add aliases to the new index " + indexSuffix
);
+            }
+
+        }
+        finally{
+            //invalidate the alias
+            aliasCache.invalidate(alias);
+            //stop the timer
+            timeRemoveAlias.stop();
         }
     }
 


Mime
View raw message