You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/03/20 03:11:07 UTC

[GitHub] [lucene-solr] dsmiley commented on a change in pull request #1366: SOLR-14342: Optimize core loading order in SolrCloud.

dsmiley commented on a change in pull request #1366: SOLR-14342: Optimize core loading order in SolrCloud.
URL: https://github.com/apache/lucene-solr/pull/1366#discussion_r395421862
 
 

 ##########
 File path: solr/core/src/test/org/apache/solr/core/CoreSorterTest.java
 ##########
 @@ -71,168 +69,141 @@ public void testComparator() {
 
     );
 
+    testComparator(expected, l);
+
+    integrationTest(expected, l);
+  }
+
+  private void testComparator(List<CountsForEachShard> expectedCounts, List<CountsForEachShard> inputCounts) {
     for (int i = 0; i < 10; i++) {
-      List<CountsForEachShard> copy = new ArrayList<>(l);
+      List<CountsForEachShard> copy = new ArrayList<>(inputCounts);
       Collections.shuffle(copy, random());
       Collections.sort(copy, CoreSorter.countsComparator);
       for (int j = 0; j < copy.size(); j++) {
-        assertEquals(expected.get(j), copy.get(j));
+        assertEquals(expectedCounts.get(j), copy.get(j));
       }
     }
   }
 
-  public void testSort() throws Exception {
-    CoreContainer mockCC = getMockContainer();
-    MockCoreSorter coreSorter = (MockCoreSorter) new MockCoreSorter().init(mockCC);
-    List<CoreDescriptor> copy = new ArrayList<>(coreSorter.getLocalCores());
-    Collections.sort(copy, coreSorter::compare);
-    List<CountsForEachShard> l = copy.stream()
-        .map(CoreDescriptor::getCloudDescriptor)
-        .map(it -> coreSorter.shardsVsReplicaCounts.get(getShardName(it)))
-        .collect(toList());
-    for (int i = 1; i < l.size(); i++) {
-      CountsForEachShard curr = l.get(i);
-      CountsForEachShard prev = l.get(i-1);
-      assertTrue(CoreSorter.countsComparator.compare(prev, curr) < 1);
-    }
-
-    for (CountsForEachShard c : l) {
-      System.out.println(c);
-    }
-  }
-
-  private CoreContainer getMockContainer() {
+  private void integrationTest(List<CountsForEachShard> expectedCounts, List<CountsForEachShard> _inputCounts) {
     assumeWorkingMockito();
-    
-    CoreContainer mockCC = mock(CoreContainer.class);
-    ZkController mockZKC = mock(ZkController.class);
-    ClusterState mockClusterState = mock(ClusterState.class);
-    when(mockCC.isZooKeeperAware()).thenReturn(true);
-    when(mockCC.getZkController()).thenReturn(mockZKC);
-    when(mockClusterState.getLiveNodes()).thenReturn(liveNodes);
-    when(mockZKC.getClusterState()).thenReturn(mockClusterState);
-    return mockCC;
-  }
 
-  static class ReplicaInfo {
-    final int coll, slice, replica;
-    final String replicaName;
-    CloudDescriptor cd;
-
-    ReplicaInfo(int coll, int slice, int replica) {
-      this.coll = coll;
-      this.slice = slice;
-      this.replica = replica;
-      replicaName = "coll_" + coll + "_" + slice + "_" + replica;
-      Properties p = new Properties();
-      p.setProperty(CoreDescriptor.CORE_SHARD, "shard_" + slice);
-      p.setProperty(CoreDescriptor.CORE_COLLECTION, "coll_" + slice);
-      p.setProperty(CoreDescriptor.CORE_NODE_NAME, replicaName);
-      cd = new CloudDescriptor(null, replicaName, p);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-      if (obj instanceof ReplicaInfo) {
-        ReplicaInfo replicaInfo = (ReplicaInfo) obj;
-        return replicaInfo.replicaName.equals(replicaName);
+    List<CountsForEachShard> perShardCounts = new ArrayList<>(_inputCounts);
+    Collections.shuffle(perShardCounts);
+
+    // compute nodes, some live, some down
+    final int maxNodesOfAType = perShardCounts.stream() // not too important how many we have, but lets have plenty
+        .mapToInt(c -> c.totalReplicasInLiveNodes + c.totalReplicasInDownNodes + c.myReplicas).max().getAsInt();
+    List<String> liveNodes = IntStream.range(0, maxNodesOfAType).mapToObj(i -> "192.168.0." + i + "_8983").collect(Collectors.toList());
+    Collections.shuffle(liveNodes, random());
+    String thisNode = liveNodes.get(0);
+    List<String> otherLiveNodes = liveNodes.subList(1, liveNodes.size());
+    List<String> downNodes = IntStream.range(0, maxNodesOfAType).mapToObj(i -> "192.168.1." + i + "_8983").collect(Collectors.toList());
+
+    // divide into two collections
+    int numCol1 = random().nextInt(perShardCounts.size());
 
 Review comment:
   I know; yup.  Then we get one collection and that's fine.  The actual collection distribution shouldn't matter but I wanted to add some multi-collection in there to mix things up.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org