Skip to content

Commit e25c967

Browse files
committed
Merge branch 'main' into SOLR-16398-replication-phase1
2 parents 46e14bc + 51a78ca commit e25c967

9 files changed

Lines changed: 168 additions & 28 deletions

File tree

‎.asf.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ github:
1818
merge: false
1919
rebase: false
2020

21+
# Cap how many pull requests a contributor without write access may have open at once.
22+
# See https://github.com/apache/infrastructure-asfyaml#pr_creation_cap
23+
pull_requests:
24+
creation_cap:
25+
enabled: true
26+
max_open_pull_requests: 7
27+
include_drafts: true
28+
2129
# TODO: Add to this list for each new minor release
2230
protected_branches:
2331
main: {}

‎.github/renovate.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
}
209209
],
210210
"schedule": ["before 9am on the first day of the month"],
211-
"prConcurrentLimit": 300,
211+
"prConcurrentLimit": 7,
212212
"prHourlyLimit": 20,
213213
"minimumReleaseAge": "5 days"
214214
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
2+
3+
title: >
4+
CREATESNAPSHOT now fails instead of reporting success when a shard has no active replica with a
5+
core snapshot
6+
type: fixed
7+
authors:
8+
- name: Boyi Dai
9+
nick: SpookyJumpyBeans
10+
links:
11+
- name: SOLR-18538
12+
url: https://issues.apache.org/jira/browse/SOLR-18538
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
2+
title: ManagedSynonymGraphFilterFactory no longer tags the original token as type `SYNONYM` for equivalence-group mappings (e.g. `[terma]->[terma, termb, termc]`), using Lucene's `includeOrig` flag so only the injected synonyms get that type.
3+
type: fixed
4+
authors:
5+
- name: Renato Haeberli
6+
nick: renatoh
7+
links:
8+
- name: PR#4960
9+
url: https://github.com/apache/solr/pull/4960

‎dev-docs/how-to-contribute.adoc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ In order to make a new contribution to Solr you will use the fork you have creat
4040
* The PR will run a gradle pre-commit task that will do some basic checks of your changes. This is run as a Github Action and the results can be viewed from your PR.
4141
* If you properly named your PR you will see it automatically linked to your Jira issue when you view the issue.
4242
* If your PR is still a work in progress, you can use the https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests#draft-pull-requests[PR Draft feature] of Github to denote draft status.
43+
* Contributors without write access to the repository can have at most seven pull requests open at a time, drafts included. GitHub will refuse to create further PRs until one of your open ones is merged or closed. If you hit the limit, please help your earlier contributions over the line before starting something new. Committers are not subject to this limit.
4344
5. At this point, you will need a Solr committer to review your change and help to get it merged upstream. You can use the https://solr.apache.org/community.html[Solr Developers Mailing List] to get attention to your issue.
4445
4546
## PR Do-s and Don't-s

‎solr/core/src/java/org/apache/solr/cloud/api/collections/CreateSnapshotCmd.java‎

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ public void call(AdminCmdContext adminCmdContext, ZkNodeProps message, NamedList
9999

100100
final ShardRequestTracker shardRequestTracker =
101101
CollectionHandlingUtils.asyncRequestTracker(adminCmdContext, ccc);
102-
for (Slice slice :
103-
ccc.getZkStateReader().getClusterState().getCollection(collectionName).getSlices()) {
102+
DocCollection collection =
103+
ccc.getZkStateReader().getClusterState().getCollection(collectionName);
104+
for (Slice slice : collection.getActiveSlices()) {
104105
for (Replica replica : slice.getReplicas()) {
105106
if (replica.getState() != State.ACTIVE) {
106107
if (log.isInfoEnabled()) {
@@ -166,26 +167,18 @@ public void call(AdminCmdContext adminCmdContext, ZkNodeProps message, NamedList
166167
"Unable to create a snapshot with name {} for following cores {}",
167168
commitName,
168169
shardByCoreName.keySet());
170+
}
169171

170-
// Count number of failures per shard.
171-
Map<String, Integer> failuresByShardId = new HashMap<>();
172-
for (Map.Entry<String, Slice> entry : shardByCoreName.entrySet()) {
173-
int f = 0;
174-
if (failuresByShardId.get(entry.getValue().getName()) != null) {
175-
f = failuresByShardId.get(entry.getValue().getName());
176-
}
177-
failuresByShardId.put(entry.getValue().getName(), f + 1);
178-
}
179-
180-
// Now that we know number of failures per shard, we can figure out
181-
// if at-least one replica per shard was able to create a snapshot or not.
182-
DocCollection collectionStatus =
183-
ccc.getZkStateReader().getClusterState().getCollection(collectionName);
184-
for (Map.Entry<String, Integer> entry : failuresByShardId.entrySet()) {
185-
int replicaCount = collectionStatus.getSlice(entry.getKey()).getReplicas().size();
186-
if (replicaCount <= entry.getValue()) {
187-
failedShards.add(entry.getKey());
188-
}
172+
// A shard counts as captured only if at least one of its replicas reported a snapshot. Shards
173+
// whose replicas were all skipped as inactive never received a request, so they must be
174+
// checked against the collection state rather than against the requests that were sent.
175+
Set<String> shardsWithSnapshot = new HashSet<>();
176+
for (CoreSnapshotMetaData replica : replicas) {
177+
shardsWithSnapshot.add(replica.getShardId());
178+
}
179+
for (Slice slice : collection.getActiveSlices()) {
180+
if (!shardsWithSnapshot.contains(slice.getName())) {
181+
failedShards.add(slice.getName());
189182
}
190183
}
191184

‎solr/core/src/java/org/apache/solr/rest/schema/analysis/ManagedSynonymGraphFilterFactory.java‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,24 @@ public void parse(Reader in) throws IOException, ParseException {
365365
boolean ignoreCase = synonymManager.getIgnoreCase();
366366
for (CasePreservedSynonymMappings cpsm : synonymManager.synonymMappings.values()) {
367367
for (Map.Entry<String, Set<String>> entry : cpsm.mappings.entrySet()) {
368+
// Use includeOrig=true so the original token keeps its upstream type and only the
369+
// injected synonyms are tagged as SYNONYM
370+
boolean mapsToItself = entry.getValue().contains(entry.getKey());
371+
CharsRef casedTerm =
372+
analyze(
373+
synonymManager.applyCaseSetting(ignoreCase, entry.getKey()),
374+
new CharsRefBuilder());
368375
for (String mapping : entry.getValue()) {
369-
// apply the case setting to match the behavior of the SynonymMap builder
370-
CharsRef casedTerm =
371-
analyze(
372-
synonymManager.applyCaseSetting(ignoreCase, entry.getKey()),
373-
new CharsRefBuilder());
374376
CharsRef casedMapping =
375377
analyze(
376378
synonymManager.applyCaseSetting(ignoreCase, mapping), new CharsRefBuilder());
377-
add(casedTerm, casedMapping, false);
379+
if (mapsToItself) {
380+
if (!casedTerm.equals(casedMapping)) {
381+
add(casedTerm, casedMapping, true);
382+
}
383+
} else {
384+
add(casedTerm, casedMapping, false);
385+
}
378386
}
379387
}
380388
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.solr.core.snapshots;
18+
19+
import java.util.Collection;
20+
import org.apache.solr.client.solrj.impl.CloudSolrClient;
21+
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
22+
import org.apache.solr.cloud.SolrCloudTestCase;
23+
import org.apache.solr.common.SolrException;
24+
import org.apache.solr.common.cloud.Replica;
25+
import org.apache.solr.common.cloud.ZkStateReader;
26+
import org.apache.solr.embedded.JettySolrRunner;
27+
import org.junit.BeforeClass;
28+
import org.junit.Test;
29+
30+
/**
31+
* A collection snapshot must not be recorded as successful when a shard has no active replica to
32+
* take a core snapshot.
33+
*/
34+
public class TestSolrCloudSnapshotInactiveShard extends SolrCloudTestCase {
35+
36+
@BeforeClass
37+
public static void setupClass() throws Exception {
38+
useFactory("solr.StandardDirectoryFactory");
39+
configureCluster(2)
40+
.addConfig(
41+
"conf1", TEST_PATH().resolve("configsets").resolve("cloud-minimal").resolve("conf"))
42+
.configure();
43+
}
44+
45+
@Test
46+
public void testSnapshotFailsWhenShardHasNoActiveReplica() throws Exception {
47+
CloudSolrClient solrClient = cluster.getSolrClient();
48+
String collectionName = "snapshotInactiveShard";
49+
JettySolrRunner hostingNode = cluster.getJettySolrRunner(1);
50+
51+
CollectionAdminRequest.createCollection(collectionName, "conf1", 1, 1)
52+
.setCreateNodeSet(hostingNode.getNodeName())
53+
.process(solrClient);
54+
cluster.waitForActiveCollection(collectionName, 1, 1);
55+
56+
cluster.stopJettySolrRunner(hostingNode);
57+
cluster.waitForJettyToStop(hostingNode);
58+
waitForState(
59+
"the only replica should not be active",
60+
collectionName,
61+
(liveNodes, collection) ->
62+
collection != null
63+
&& collection.replicaStream().noneMatch(r -> r.getState() == Replica.State.ACTIVE));
64+
65+
String commitName = "snap";
66+
SolrException e =
67+
expectThrows(
68+
SolrException.class,
69+
() ->
70+
new CollectionAdminRequest.CreateSnapshot(collectionName, commitName)
71+
.process(solrClient));
72+
assertTrue(e.getMessage(), e.getMessage().contains("Failed to create snapshot on shards"));
73+
74+
Collection<CollectionSnapshotMetaData> snapshots =
75+
SolrSnapshotManager.listSnapshots(
76+
ZkStateReader.from(solrClient).getZkClient(), collectionName);
77+
assertEquals(1, snapshots.size());
78+
CollectionSnapshotMetaData meta = snapshots.iterator().next();
79+
assertEquals(commitName, meta.getName());
80+
assertEquals(CollectionSnapshotMetaData.SnapshotStatus.Failed, meta.getStatus());
81+
assertTrue(meta.getReplicaSnapshots().isEmpty());
82+
}
83+
}

‎solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymGraphFilterFactory.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,32 @@ public void testManagedSynonyms() throws Exception {
247247
assertJDelete(endpoint + "/cheerful/joyful", "/error/code==404");
248248
}
249249

250+
@Test
251+
public void testUpstreamTokenTypeIsPreserved() throws Exception {
252+
String endpoint = "/schema/analysis/synonyms/englishgraph";
253+
254+
List<String> equivGroup = Arrays.asList("funny", "entertaining", "whimsical");
255+
assertJPut(endpoint, toJSONString(equivGroup), "/responseHeader/status==0");
256+
257+
assertJQ(endpoint + "/funny", "/funny==['entertaining','funny','whimsical']");
258+
259+
restTestHarness.reload();
260+
261+
String analysisUrl = "/analysis/field?analysis.fieldtype=managed_graph_en&analysis.query=funny";
262+
String synFilter = "//arr[contains(@name,'SynonymGraphFilter')]";
263+
assertQ(
264+
analysisUrl,
265+
"count("
266+
+ synFilter
267+
+ "/lst[str[@name='text'][.='funny']]/str[@name='type'][.='<ALPHANUM>']) = 1",
268+
"count("
269+
+ synFilter
270+
+ "/lst[str[@name='text'][.='entertaining']]/str[@name='type'][.='SYNONYM']) = 1",
271+
"count("
272+
+ synFilter
273+
+ "/lst[str[@name='text'][.='whimsical']]/str[@name='type'][.='SYNONYM']) = 1");
274+
}
275+
250276
/** Can we add and remove stopwords with umlauts */
251277
@Test
252278
public void testCanHandleDecodingAndEncodingForSynonyms() throws Exception {

0 commit comments

Comments
 (0)