I am using SolrJ to create collections. SolrCloud 8.10.1, SolrJ 8.10.1.

I specified this as my nodeset for the creation.

private static final String SOLR_NODESET = "solr-0001:8983_solr,solr-0003:8983_solr,solr-0002:8983_solr,solr-0004:8983_solr";

But the solrcloud assignments show to be:

shard1 -> [solr-0001, solr-0002]
shard2 -> [solr-0001, solr-0003]

Why did it assign two shards to node solr-0001? As max shards per node is 1, should it not have thrown an exception if node solr-0004 wasn't reachable?

Here is my create collection code:

    private static final int NUM_SHARDS = 2;
    private static final int NUM_SHARDS_PER_NODE = 1;
    private static final int NUM_REPLICAS = 2;
    private static final String SOLR_NODESET = "solr-0001:8983_solr,solr-0003:8983_solr,solr-0002:8983_solr,solr-0004:8983_solr";

public void createCollection(final String newCollection, final String newConfigSet)
            throws SolrServerException, IOException {
        try (SolrClient solrClient = solrCollection.getSolrClientInstance(true)) {
            Create req = CollectionAdminRequest //
                    .createCollection(newCollection, newConfigSet, NUM_SHARDS, NUM_REPLICAS);
            final SolrParams reqParams = req.getParams();
            if (reqParams instanceof ModifiableSolrParams) {
                ((ModifiableSolrParams) reqParams).set("createNodeSet.shuffle", false);
            }
            req.setAutoAddReplicas(false);
            req.setCreateNodeSet(SOLR_NODESET);
            req.setMaxShardsPerNode(NUM_SHARDS_PER_NODE);
            req.setWaitForFinalState(true);
            CollectionAdminResponse resp = req.process(solrClient);
            if (resp.isSuccess()) {
                System.out.printf("Created collection: %s.\n", newCollection);
            } else {
                if (resp.getException() != null) {
                    throw new RuntimeException(resp.getException());
                }
                throw new RuntimeException(resp.getResponse().toString());
            }
        } catch (BaseHttpSolrClient.RemoteSolrException e) {
            if (!e.getMessage().contains("already exists:")) {
                throw e;
            }
System.err.println(StringUtils.substringAfter(e.getMessage(), ": "));
        }
    }

Reply via email to