usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [22/50] [abbrv] incubator-usergrid git commit: add caching to indexes
Date Fri, 12 Dec 2014 14:30:21 GMT
add caching to 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/574fe644
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/574fe644
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/574fe644

Branch: refs/heads/two-dot-o-events
Commit: 574fe6449a96a7f8a8531cdb0c2f81ad7a2643e9
Parents: 1d2697f
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Tue Dec 9 11:16:16 2014 -0700
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Tue Dec 9 11:16:16 2014 -0700

----------------------------------------------------------------------
 .../usergrid/persistence/index/IndexFig.java    |  3 +++
 .../persistence/index/impl/EsIndexCache.java    | 23 ++++++++++++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/574fe644/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
index ea0a4f3..d78ed72 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
@@ -110,4 +110,7 @@ public interface IndexFig extends GuicyFig {
     @Default( "20" )
     @Key( ELASTICSEARCH_FAIL_REFRESH )
     int getFailRefreshCount();
+
+    @Default("2")
+    int getIndexCacheMaxWorkers();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/574fe644/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java
index f418590..c607222 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexCache.java
@@ -24,9 +24,13 @@ import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListenableFutureTask;
+import com.google.common.util.concurrent.ListeningScheduledExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import org.apache.usergrid.persistence.index.AliasedEntityIndex;
+import org.apache.usergrid.persistence.index.IndexFig;
 import org.apache.usergrid.persistence.index.IndexIdentifier;
 import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
 import org.elasticsearch.client.AdminClient;
@@ -36,7 +40,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.List;
+import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -46,21 +52,30 @@ import java.util.concurrent.TimeUnit;
 public class EsIndexCache {
 
     private static final Logger logger = LoggerFactory.getLogger(EsEntityIndexImpl.class);
+    private final ListeningScheduledExecutorService refreshExecutors;
 
     private LoadingCache<String, String[]> aliasIndexCache;
 
     @Inject
-    public EsIndexCache(final EsProvider provider) {
+    public EsIndexCache(final EsProvider provider, final IndexFig indexFig) {
+        this.refreshExecutors = MoreExecutors
+                .listeningDecorator(Executors.newScheduledThreadPool(indexFig.getIndexCacheMaxWorkers()));
         aliasIndexCache = CacheBuilder.newBuilder().maximumSize(1000)
                 .refreshAfterWrite(5,TimeUnit.MINUTES)
                 .build(new CacheLoader<String, String[]>() {
                     @Override
-                    public ListenableFuture<String[]> reload(String key, String[] oldValue)
throws Exception {
-                        return super.reload(key, oldValue);
+                    public ListenableFuture<String[]> reload(final String key, String[]
oldValue) throws Exception {
+                        ListenableFutureTask<String[]> task = ListenableFutureTask.create(
new Callable<String[]>() {
+                            public String[] call() {
+                                return load( key );
+                            }
+                        } );
+                        refreshExecutors.execute(task);
+                        return task;
                     }
 
                     @Override
-                    public String[] load(String aliasName) {
+                    public String[] load(final String aliasName) {
                         final AdminClient adminClient = provider.getClient().admin();
                         //remove write alias, can only have one
                         ImmutableOpenMap<String, List<AliasMetaData>> aliasMap
= adminClient.indices().getAliases(new GetAliasesRequest(aliasName)).actionGet().getAliases();


Mime
View raw message