Solr7中调用solrj给指定集合创建副本失败non legacy mode coreNodeName missing

【问题描述】

在solr7.7.1中调用solrj给指定集合创建副本

    private void addCore(CoreInfomation needTransferCore, HttpSolrClient HttpSolrClient,String collection)
            throws SolrServerException, IOException {
        Create req = new Create();
        String oldCoreName = needTransferCore.getCoreName();
        String newCoreName = oldCoreName + "_new";
        req.setCoreName(newCoreName);
        req.setInstanceDir(newCoreName);
        req.setCollection(collection);
        req.setShardId(needTransferCore.getShardName());

        log.info("begin to add core " + newCoreName + " to " + HttpSolrClient.getBaseURL());
        CoreAdminResponse coreAdminResponse = req.process(HttpSolrClient);
        log.info("addCoreResponse is : " + coreAdminResponse);
        if (0 != coreAdminResponse.getStatus()) {
            log.error("add core failed. exit and please check.");
            System.exit(1);
        }
    }

调用时,报如下错误:

org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://wkh183:8983/solr: Error CREATEing SolrCore 'coll4_shard1_0_0_replica_n7_new': non legacy mode coreNodeName missing {shard=shard1_0_0, collection=coll4}

【问题分析】

solr5时调用同样代码均无错误,估计是哪里的配置问题,因此只能寻找度娘的帮助。

最终查到了解决办法:
http://lucene.472066.n3.nabble.com/Migrating-from-Solr-6-X-to-Solr-7-X-quot-non-legacy-mode-coreNodeName-missing-quot-td4361128.html

You may have to set legacyCloud=true in your cluster properties. In
the Solr reference guide (7.0) there's a section "Changes to Default
Behaviors" that'll tell you a bit about that. Check your cluster
properties (top level znode in ZooKeeper).

参考《apache-solr-ref-guide-7.7》 P107,可以得知legacyCloud参数默认是false,如果一个replica在state.json中不存在时,replica将无法注册。
The legacyCloud parameter now defaults to false. If an entry for a replica does not exist in state.json, that replica will not get registered.

【问题解决】

因此,如果我们需要针对指定结合新增副本,那么我们需要在solr7中预置legacyCloud属性为true。
This may affect users who bring up replicas and they are automatically registered as a part of a shard. It is possible to fall back to the old behavior by setting the property legacyCloud=true, in the cluster properties using the following command:
./server/scripts/cloud-scripts/zkcli.sh -zkhost 127.0.0.1:2181 -cmd clusterprop -name
legacyCloud -val true

你可能感兴趣的:(Solr7中调用solrj给指定集合创建副本失败non legacy mode coreNodeName missing)