Added fixes around caching and changed the endpoint to selective indexing to be /_index instead of /_indexes
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/255bba31 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/255bba31 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/255bba31 Branch: refs/heads/USERGRID-1246-MASTER Commit: 255bba3106f64564ebc6e912794a2d153fdab05b Parents: 14f7e29 Author: George Reyes <g...@apache.org> Authored: Fri Apr 22 14:45:07 2016 -0700 Committer: George Reyes <g...@apache.org> Committed: Mon May 2 10:49:34 2016 -0700 ---------------------------------------------------------------------- .../index/IndexSchemaCacheFig.java | 2 +- .../index/IndexSchemaCacheImpl.java | 3 +- .../rest/applications/CollectionResource.java | 8 ++--- .../collection/CollectionsResourceIT.java | 38 ++++++++++---------- 4 files changed, 24 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/255bba31/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFig.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFig.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFig.java index 0953abd..a99b48e 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFig.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFig.java @@ -33,7 +33,7 @@ public interface IndexSchemaCacheFig extends GuicyFig { int getCacheSize(); @Key( "usergrid.index_schema_cache_timeout_ms" ) - @Default( "60000" ) + @Default( "15000" ) int getCacheTimeout(); } http://git-wip-us.apache.org/repos/asf/usergrid/blob/255bba31/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java index fd0b676..d4bade4 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java @@ -19,6 +19,7 @@ package org.apache.usergrid.corepersistence.index; import java.util.Map; +import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +50,7 @@ public class IndexSchemaCacheImpl implements IndexSchemaCache { this.mapManager = mapManager; indexSchemaCache = CacheBuilder.newBuilder() .maximumSize( indexSchemaCacheFig.getCacheSize() ) - //.expireAfterWrite( indexSchemaCacheFig.getCacheTimeout(), TimeUnit.MILLISECONDS ) <-- I don't think we want this to expire that quickly. + .expireAfterWrite( indexSchemaCacheFig.getCacheTimeout(), TimeUnit.MILLISECONDS ) .build( new CacheLoader<String, Optional<Map>>() { @Override public Optional<Map> load( final String collectionName ) throws Exception { http://git-wip-us.apache.org/repos/asf/usergrid/blob/255bba31/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java index 5bd895c..1e94832 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java @@ -91,7 +91,7 @@ public class CollectionResource extends ServiceResource { * @throws Exception */ @POST - @Path( "{itemName}/_indexes" ) + @Path( "{itemName}/_index" ) @Produces({ MediaType.APPLICATION_JSON,"application/javascript"}) @RequireApplicationAccess @JSONP @@ -153,7 +153,7 @@ public class CollectionResource extends ServiceResource { } @DELETE - @Path( "{itemName}/_indexes" ) + @Path( "{itemName}/_index" ) @Produces({ MediaType.APPLICATION_JSON,"application/javascript"}) @RequireApplicationAccess @JSONP @@ -222,10 +222,6 @@ public class CollectionResource extends ServiceResource { addItemToServiceContext( ui, itemName ); -// final ReIndexRequestBuilder request = -// createRequest().withApplicationId( services.getApplicationId() ).withCollection( -// String.valueOf( getServiceParameters().get( 0 ) ) ).withDelay( 50, TimeUnit.MILLISECONDS ); -// IndexResource indexResource = new IndexResource(injector); return indexResource.rebuildIndexesPost( services.getApplicationId().toString(),itemName.getPath(),false,callback ); } http://git-wip-us.apache.org/repos/asf/usergrid/blob/255bba31/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java index 0e682a7..db07c3f 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java @@ -136,7 +136,7 @@ public class CollectionsResourceIT extends AbstractRestIT { try { - this.pathResource( getOrgAppPath( "testcollections/_indexes" ) ).post( false, payload, + this.pathResource( getOrgAppPath( "testcollections/_index" ) ).post( false, payload, new QueryParameters().addParam( "grant_type", "client_credentials" ).addParam( "client_id", String.valueOf( ( ( Map ) appCredentials.get( "credentials" ) ).get( "client_id" ) ) ) .addParam( "client_secret", String.valueOf( @@ -167,7 +167,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - Entity thing = this.app().collection( "testCollections" ).collection( "_indexes" ).post( payload ); + Entity thing = this.app().collection( "testCollections" ).collection( "_index" ).post( payload ); refreshIndex(); @@ -206,7 +206,7 @@ public class CollectionsResourceIT extends AbstractRestIT { //to prove that the entity exists //next part is to delete the schema then reindex it and it should work. - this.app().collection( "testCollections" ).collection( "_indexes" ).delete(); + this.app().collection( "testCollections" ).collection( "_index" ).delete(); refreshIndex(); this.app().collection( "testCollections" ).collection( "_reindex" ) @@ -245,7 +245,7 @@ public class CollectionsResourceIT extends AbstractRestIT { //Post index to the collection metadata try { - this.app().collection( "testCollections" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollections" ).collection( "_index" ).post( payload ); fail(); }catch(BadRequestException bre){ //this is expected. @@ -259,7 +259,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingMap); try { - this.app().collection( "testCollections" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollections" ).collection( "_index" ).post( payload ); fail(); }catch(BadRequestException bre){ //this is expected. @@ -269,7 +269,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); try { - this.app().collection( "testCollections" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollections" ).collection( "_index" ).post( payload ); }catch(BadRequestException bre){ fail( "This shouldn't fail" ); } @@ -292,7 +292,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - Entity thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + Entity thing = this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); refreshIndex(); @@ -366,7 +366,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - Entity thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + Entity thing = this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); refreshIndex(); @@ -417,7 +417,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - Entity thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + Entity thing = this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); refreshIndex(); Collection collection = this.app().collection( "testCollection" ).collection( "_index" ).get(); @@ -445,7 +445,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); collection = this.app().collection( "testCollection" ).collection( "_index" ).get(); @@ -497,7 +497,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); refreshIndex(); //Create test collection with a test entity that is partially indexed. @@ -539,7 +539,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); refreshIndex(); Map<String,Object> arrayFieldsForTesting = new HashMap<>(); @@ -589,7 +589,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); refreshIndex(); Map<String,Object> arrayFieldsForTesting = new HashMap<>(); @@ -632,7 +632,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); refreshIndex(); Map<String,Object> arrayFieldsForTestingSelectiveIndexing = new HashMap<>(); @@ -687,7 +687,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); refreshIndex(); Map<String,Object> arrayFieldsForTestingSelectiveIndexing = new HashMap<>(); @@ -738,7 +738,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_index" ).post( payload ); refreshIndex(); //Create test collection with a test entity that is partially indexed. @@ -961,7 +961,7 @@ public class CollectionsResourceIT extends AbstractRestIT { String randomizer = RandomStringUtils.randomAlphanumeric(10); String collectionName = "col_" + randomizer; - app().collection( collectionName ).collection( "_indexes" ).post( payload ); + app().collection( collectionName ).collection( "_index" ).post( payload ); refreshIndex(); // was the no-index wildcard saved and others ignored? @@ -1009,7 +1009,7 @@ public class CollectionsResourceIT extends AbstractRestIT { String randomizer = RandomStringUtils.randomAlphanumeric(10); String unIndexedCollectionName = "col_" + randomizer; - app().collection( unIndexedCollectionName ).collection( "_indexes" ).post( payload ); + app().collection( unIndexedCollectionName ).collection( "_index" ).post( payload ); refreshIndex(); String entityName1 = "unindexed1"; @@ -1070,7 +1070,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); String unIndexedCollectionName = "col_" + randomizer; - app().collection( unIndexedCollectionName ).collection( "_indexes" ).post( payload ); + app().collection( unIndexedCollectionName ).collection( "_index" ).post( payload ); refreshIndex(); String entityName1 = "unindexed1";