Apache Lucene open-source search software
Merge 'master' into feature/autoscaling
Cao Manh Datb53736155ae4
diff --cc solr/CHANGES.txtindex 3e369e200a7,b123477c92e..e128e832709--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@@ -75,19 -71,16 +75,23 @@@ Bug Fixe* SOLR-11012: Fix three (JavaBinCodec not being closed) Resource Leak warnings. (Christine Poerschke)+* SOLR-11026: MoveReplicaSuggester must check if the target becomes more 'loaded' than the source+ if an operation is performed (noble)++* SOLR-10994: CREATE, CREATESHARD & ADDREPLICA to use policy framework & support replica types (noble)++ * SOLR-11011: Assign.buildCoreName can lead to error in creating a new core when legacyCloud=false (Cao Manh Dat)+Optimizations----------------------* SOLR-10985: Remove unnecessary toString() calls in solr-core's search package's debug logging.(Michael Braun via Christine Poerschke)+* SOLR-11000: Changes made via AutoScalingHandler should be atomic. (ab, shalin)++ * SOLR-11124: MoveReplicaCmd should skip deleting old replica in case of its node is not live (Cao Manh Dat)+Other Changes----------------------@@@ -308,17 -310,11 +331,17 @@@ New FeatureThis also solves issues SOLR-8495, SOLR-6966, and SOLR-7058(janhoy, Steve Rowe, hossman, Alexandre Rafalovich, Shawn Heisey, Cao Manh Dat)-* SOLR-10123: Upgraded the Analytics Component to version 2.0 which now supports distributed collections, expressions over- multivalued fields, a new JSON request language, and more. DocValues are now required for any field used in the analytics+* SOLR-10123: Upgraded the Analytics Component to version 2.0 which now supports distributed collections, expressions over+ multivalued fields, a new JSON request language, and more. DocValues are now required for any field used in the analyticsexpression whereas previously docValues was not required. Please see SOLR-10123 for details. (Houston Putman)+* SOLR-10496: New ComputePlanAction for autoscaling which uses the policy framework to compute cluster+ operations upon a trigger fire. (Noble Paul, shalin)++* SOLR-10965: New ExecutePlanAction for autoscaling which executes the operations computed by ComputePlanAction+ against the cluster. (shalin)+- * SOLR-10282: bin/solr support for enabling Kerberos authentication (Ishan Chattopadhyaya)+ * SOLR-10282: bin/solr support for enabling Kerberos authentication (Ishan Chattopadhyaya, Jason Gerlowski)Bug Fixes----------------------diff --cc solr/core/src/java/org/apache/solr/cloud/Assign.javaindex c2fa1389058,98dcfde0e58..3c8900e042f--- a/solr/core/src/java/org/apache/solr/cloud/Assign.java+++ b/solr/core/src/java/org/apache/solr/cloud/Assign.java@@@ -52,10 -50,12 +51,13 @@@ import org.apache.solr.common.cloud.ZkSimport org.apache.solr.common.util.StrUtils;import org.apache.solr.common.util.Utils;import org.apache.solr.core.CoreContainer;+ import org.apache.solr.util.NumberUtils;+ import org.apache.zookeeper.CreateMode;import org.apache.zookeeper.KeeperException;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;+ import org.apache.zookeeper.data.Stat;-import static java.util.Collections.singletonMap;import static org.apache.solr.client.solrj.cloud.autoscaling.Policy.POLICY;import static org.apache.solr.cloud.OverseerCollectionMessageHandler.CREATE_NODE_SET;import static org.apache.solr.cloud.OverseerCollectionMessageHandler.CREATE_NODE_SET_EMPTY;@@@ -63,29 -63,66 +65,64 @@@ import static org.apache.solr.cloud.Oveimport static org.apache.solr.cloud.OverseerCollectionMessageHandler.CREATE_NODE_SET_SHUFFLE_DEFAULT;import static org.apache.solr.common.cloud.DocCollection.SNITCH;import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;-import static org.apache.solr.common.cloud.ZkStateReader.SOLR_AUTOSCALING_CONF_PATH;-public class Assign {+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());- private static Pattern COUNT = Pattern.compile("core_node(\\d+)");-- public static String assignNode(DocCollection collection) {- Map<String, Slice> sliceMap = collection != null ? collection.getSlicesMap() : null;- if (sliceMap == null) {- return "core_node1";+ public static int incAndGetId(SolrZkClient zkClient, String collection, int defaultValue) {+ String path = "/collections/"+collection;+ try {+ if (!zkClient.exists(path, true)) {+ try {+ zkClient.makePath(path, true);+ } catch (KeeperException.NodeExistsException e) {+ // it's okay if another beats us creating the node+ }+ }+ path += "/counter";+ if (!zkClient.exists(path, true)) {+ try {+ zkClient.create(path, NumberUtils.intToBytes(defaultValue), CreateMode.PERSISTENT, true);+ } catch (KeeperException.NodeExistsException e) {+ // it's okay if another beats us creating the node+ }+ }+ } catch (InterruptedException e) {+ Thread.interrupted();+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error creating counter node in Zookeeper for collection:" + collection, e);+ } catch (KeeperException e) {+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error creating counter node in Zookeeper for collection:" + collection, e);}- int max = 0;- for (Slice slice : sliceMap.values()) {- for (Replica replica : slice.getReplicas()) {- Matcher m = COUNT.matcher(replica.getName());- if (m.matches()) {- max = Math.max(max, Integer.parseInt(m.group(1)));+ while (true) {+ Stat stat = new Stat();+ try {+ byte[] data = zkClient.getData(path, null, stat, true);+ int currentId = NumberUtils.bytesToInt(data);+ data = NumberUtils.intToBytes(++currentId);+ zkClient.setData(path, data, stat.getVersion(), true);+ return currentId;+ } catch (KeeperException e) {+ if (e.code() != KeeperException.Code.BADVERSION) {+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error inc and get counter from Zookeeper for collection:"+collection, e);}+ } catch (InterruptedException e) {+ Thread.interrupted();+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error inc and get counter from Zookeeper for collection:" + collection, e);}}+ }- return "core_node" + (max + 1);+ public static String assignNode(SolrZkClient client, DocCollection collection) {+ // for backward compatibility;+ int numReplicas = collection.getReplicas().size();+ String coreNodeName = "core_node" + incAndGetId(client, collection.getName(), numReplicas * 20);+ while (collection.getReplica(coreNodeName) != null) {+ // there is wee chance that, the new coreNodeName id not totally unique,+ // but this will be guaranteed unique for new collections+ coreNodeName = "core_node" + incAndGetId(client, collection.getName(), numReplicas * 20);+ }+ return coreNodeName;}/**diff --cc solr/core/src/java/org/apache/solr/cloud/CreateShardCmd.javaindex 0dd7c760758,c3344eb261f..e277690dfdf--- a/solr/core/src/java/org/apache/solr/cloud/CreateShardCmd.java+++ b/solr/core/src/java/org/apache/solr/cloud/CreateShardCmd.java@@@ -119,10 -84,24 +119,10 @@@ public class CreateShardCmd implementsocmh.waitForNewShard(collectionName, sliceName);String async = message.getStr(ASYNC);-- int createdNrtReplicas = 0, createdTlogReplicas = 0, createdPullReplicas = 0;CountDownLatch countDownLatch = new CountDownLatch(totalReplicas);- for (int j = 1; j <= totalReplicas; j++) {- Replica.Type typeToCreate;- if (createdNrtReplicas < numNrtReplicas) {- createdNrtReplicas++;- typeToCreate = Replica.Type.NRT;- } else if (createdTlogReplicas < numTlogReplicas) {- createdTlogReplicas++;- typeToCreate = Replica.Type.TLOG;- } else {- createdPullReplicas++;- typeToCreate = Replica.Type.PULL;- }- String nodeName = sortedNodeList.get(((j - 1)) % sortedNodeList.size()).nodeName;- String coreName = Assign.buildCoreName(ocmh.zkStateReader.getZkClient(), collection, sliceName, typeToCreate);-// String coreName = collectionName + "_" + sliceName + "_replica" + j;+ for (ReplicaPosition position : positions) {+ String nodeName = position.node;- String coreName = Assign.buildCoreName(collectionName, sliceName, position.type, position.index);++ String coreName = Assign.buildCoreName(ocmh.zkStateReader.getZkClient(), collection, sliceName, position.type);log.info("Creating replica " + coreName + " as part of slice " + sliceName + " of collection " + collectionName+ " on " + nodeName);diff --cc solr/core/src/resources/SystemCollectionSchema.xmlindex 2077b3683dc,0c33022cc28..81f393f4f58--- a/solr/core/src/resources/SystemCollectionSchema.xml+++ b/solr/core/src/resources/SystemCollectionSchema.xml@@@ -1,21 -1,11 +1,21 @@@<?xml version="1.0" ?><schema name="_system collection or core" version="1.1"><fieldtype name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>- <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>- <fieldType name="double" class="solr.TrieDoubleField" positionIncrementGap="0" precisionStep="0"/>+ <fieldType name="long" class="solr.LongPointField" docValues="true" positionIncrementGap="0"/>++ <fieldType name="double" class="solr.DoublePointField" docValues="true" positionIncrementGap="0"/><fieldType name="bytes" class="solr.BinaryField"/>- <fieldType name="date" class="solr.TrieDateField"/>+ <fieldType name="date" class="solr.DatePointField" docValues="true"/>+ <fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">+ <analyzer>+ <tokenizer class="solr.WhitespaceTokenizerFactory"/>+ </analyzer>+ </fieldType>+ <uniqueKey>id</uniqueKey><field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>- <field name="md5" type="string" indexed="true" stored="true" multiValued="false" required="true"/>+ <field name="_version_" type="long" indexed="true" stored="true"/>+ <field name="type" type="string" indexed="true" stored="true" multiValued="false" required="true"/>+ <!-- blob repository fields -->+ <field name="md5" type="string" indexed="true" stored="true" multiValued="false"/><field name="blob" type="bytes" indexed="false" stored="true" multiValued="false" /><field name="size" type="long" indexed="true" stored="true" multiValued="false" /><field name="version" type="long" indexed="true" stored="true" multiValued="false" />