Github user dsmiley commented on a diff in the pull request: https://github.com/apache/lucene-solr/pull/433#discussion_r208718224 --- Diff: solr/core/src/test/org/apache/solr/update/processor/TimeRoutedAliasUpdateProcessorTest.java --- @@ -322,6 +325,104 @@ public void testSliceRouting() throws Exception { } } + @Test + public void testPreemptiveCreation() throws Exception { + String configName = TimeRoutedAliasUpdateProcessorTest.configName + getTestName(); + createConfigSet(configName); + + final int numShards = 1 ; + final int numReplicas = 1 ; + CollectionAdminRequest.createTimeRoutedAlias(alias, "2017-10-23T00:00:00Z", "+1DAY", timeField, + CollectionAdminRequest.createCollection("_unused_", configName, numShards, numReplicas) + .setMaxShardsPerNode(numReplicas)).setPreemptiveCreateWindow("3HOUR") + .process(solrClient); + + // cause some collections to be created + assertUpdateResponse(solrClient.add(alias, + sdoc("id","1","timestamp_dt", "2017-10-25T00:00:00Z") + )); + assertUpdateResponse(solrClient.commit(alias)); + + // wait for all the collections to exist... + waitCol("2017-10-23", numShards); + waitCol("2017-10-24", numShards); + waitCol("2017-10-25", numShards); + + // normal update, nothing special, no collection creation required. + List<String> cols = new CollectionAdminRequest.ListAliases().process(solrClient).getAliasesAsLists().get(alias); + assertEquals(3,cols.size()); + + assertNumDocs("2017-10-23", 0); + assertNumDocs("2017-10-24", 0); + assertNumDocs("2017-10-25", 1); + + // cause some collections to be created + + ModifiableSolrParams params = params(); + assertUpdateResponse(add(alias, Arrays.asList( + sdoc("id", "2", "timestamp_dt", "2017-10-24T00:00:00Z"), + sdoc("id", "3", "timestamp_dt", "2017-10-25T00:00:00Z"), + sdoc("id", "4", "timestamp_dt", "2017-10-23T00:00:00Z"), + sdoc("id", "5", "timestamp_dt", "2017-10-25T23:00:00Z")), // should cause preemptive creation + params)); + assertUpdateResponse(solrClient.commit(alias)); + + cols = new CollectionAdminRequest.ListAliases().process(solrClient).getAliasesAsLists().get(alias); + assertEquals(3,cols.size()); + assertNumDocs("2017-10-23", 1); + assertNumDocs("2017-10-24", 1); + assertNumDocs("2017-10-25", 3); + + assertUpdateResponse(add(alias, Collections.singletonList( + sdoc("id", "6", "timestamp_dt", "2017-10-25T23:01:00Z")), // might cause duplicate preemptive creation + params)); + assertUpdateResponse(solrClient.commit(alias)); + + waitCol("2017-10-26", numShards); + cols = new CollectionAdminRequest.ListAliases().process(solrClient).getAliasesAsLists().get(alias); + assertEquals(4,cols.size()); + assertNumDocs("2017-10-23", 1); + assertNumDocs("2017-10-24", 1); + assertNumDocs("2017-10-25", 4); + assertNumDocs("2017-10-26", 0); + + // now test with pre-create window longer than time slice, and forcing multiple creations. + CollectionAdminRequest.setAliasProperty(alias) + .addProperty(TimeRoutedAlias.ROUTER_PREEMPTIVE_CREATE_MATH, "3DAY").process(solrClient); + + Thread.sleep(1000); // a moment to be sure the alias change has taken effect --- End diff -- curious; has this been shown to be necessary? I can imagine it might be... since a new TRA URP isn't doing to do a ZK sync to view the alias state.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org