This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new f588ab90ccf SOLR-18559: Refresh aliases before rejecting an update to
a routed alias (#5189)
f588ab90ccf is described below
commit f588ab90ccf7f7b0a4af7c1b51a713d728055156
Author: Boyi Dai <[email protected]>
AuthorDate: Sun Nov 15 00:50:36 2026 -0500
SOLR-18559: Refresh aliases before rejecting an update to a routed alias
(#5189)
Updates to a routed alias no longer fail on a node whose cached aliases
don't include the alias yet; the node now refreshes its aliases from ZooKeeper
before rejecting the update
---
.../SOLR-18559-routed-alias-stale-aliases.yml | 12 +++++
.../processor/RoutedAliasUpdateProcessor.java | 19 ++++++--
.../apache/solr/cloud/CreateRoutedAliasTest.java | 51 ++++++++++++++++++++++
3 files changed, 79 insertions(+), 3 deletions(-)
diff --git a/changelog/unreleased/SOLR-18559-routed-alias-stale-aliases.yml
b/changelog/unreleased/SOLR-18559-routed-alias-stale-aliases.yml
new file mode 100644
index 00000000000..28f4b2c67cf
--- /dev/null
+++ b/changelog/unreleased/SOLR-18559-routed-alias-stale-aliases.yml
@@ -0,0 +1,12 @@
+# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
+
+title: >
+ Updates to a routed alias no longer fail on a node whose cached aliases
don't include the alias
+ yet; the node now refreshes its aliases from ZooKeeper before rejecting the
update
+type: fixed
+authors:
+ - name: Boyi Dai
+ nick: SpookyJumpyBeans
+links:
+ - name: SOLR-18559
+ url: https://issues.apache.org/jira/browse/SOLR-18559
diff --git
a/solr/core/src/java/org/apache/solr/update/processor/RoutedAliasUpdateProcessor.java
b/solr/core/src/java/org/apache/solr/update/processor/RoutedAliasUpdateProcessor.java
index b38cc5d1e6b..d58b2400226 100644
---
a/solr/core/src/java/org/apache/solr/update/processor/RoutedAliasUpdateProcessor.java
+++
b/solr/core/src/java/org/apache/solr/update/processor/RoutedAliasUpdateProcessor.java
@@ -51,6 +51,7 @@ import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.update.DeleteUpdateCommand;
import org.apache.solr.update.SolrCmdDistributor;
import
org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase;
+import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -132,9 +133,21 @@ public class RoutedAliasUpdateProcessor extends
UpdateRequestProcessor {
}
private static Map<String, String> getAliasProps(SolrQueryRequest req,
String aliasName) {
- ZkController zkController = req.getCoreContainer().getZkController();
- final Map<String, String> aliasProperties =
-
zkController.getZkStateReader().getAliases().getCollectionAliasProperties(aliasName);
+ ZkStateReader zkStateReader =
req.getCoreContainer().getZkController().getZkStateReader();
+ Map<String, String> aliasProperties =
+ zkStateReader.getAliases().getCollectionAliasProperties(aliasName);
+ if (aliasProperties.isEmpty()) {
+ // our cached aliases may be behind ZooKeeper, so check ZK before
failing.
+ // If the refresh fails with a ZooKeeper error, we fail as if the alias
is gone.
+ try {
+ zkStateReader.aliasesManager.update();
+ } catch (KeeperException e) {
+ log.error("Error trying to update aliases while resolving routed alias
{}", aliasName, e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ aliasProperties =
zkStateReader.getAliases().getCollectionAliasProperties(aliasName);
+ }
if (aliasProperties.isEmpty()) {
throw RoutedAlias.newAliasMustExistException(
aliasName); // if it did exist, we'd have a non-null map
diff --git
a/solr/core/src/test/org/apache/solr/cloud/CreateRoutedAliasTest.java
b/solr/core/src/test/org/apache/solr/cloud/CreateRoutedAliasTest.java
index 8475fd432db..ddb45575ca5 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CreateRoutedAliasTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CreateRoutedAliasTest.java
@@ -339,6 +339,57 @@ public class CreateRoutedAliasTest extends
SolrCloudTestCase {
assertTrue(collectionList.contains(initialCollectionName));
}
+ /** A node whose cached aliases are stale must still accept updates for an
existing alias. */
+ @Test
+ @SuppressForbidden(reason = "Reflection needed to make a node's cached
aliases stale")
+ public void testUpdateOnNodeWithStaleAliases() throws Exception {
+ final String aliasName = getSaferTestName();
+ CollectionAdminRequest.createTimeRoutedAlias(
+ aliasName,
+ "2017-10-23T00:00:00Z",
+ "+1DAY",
+ "evt_dt",
+ CollectionAdminRequest.createCollection("_unused_", "_default", 1,
1))
+ .process(solrClient);
+ final String collectionName = aliasName + TIME.getSeparatorPrefix() +
"2017-10-23";
+ cluster.waitForActiveCollection(collectionName, 1, 1);
+
+ // send the update to the node hosting the collection, so that node
handles it itself
+ String nodeName =
+ cluster
+ .getZkStateReader()
+ .getCollection(collectionName)
+ .replicaStream()
+ .findFirst()
+ .orElseThrow()
+ .getNodeName();
+ JettySolrRunner jetty =
+ cluster.getJettySolrRunners().stream()
+ .filter(j -> j.getNodeName().equals(nodeName))
+ .findFirst()
+ .orElseThrow();
+ ZkStateReader reader =
jetty.getCoreContainer().getZkController().getZkStateReader();
+ int zkVersion = cluster.getZkClient().exists(ZkStateReader.ALIASES,
null).getVersion();
+ new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME)
+ .waitFor(
+ "node did not catch up with aliases.json",
+ () -> reader.getAliases().getZNodeVersion() == zkVersion);
+
+ // simulate a node whose cached aliases don't include the alias yet:
nothing changes in ZK, so
+ // no later watch event will repair its cached aliases
+ Field aliasesField =
ZkStateReader.AliasesManager.class.getDeclaredField("aliases");
+ aliasesField.setAccessible(true);
+ aliasesField.set(reader.aliasesManager, Aliases.EMPTY);
+ assertSame(
+ "the node's cached aliases were refreshed before the document was
sent",
+ Aliases.EMPTY,
+ reader.getAliases());
+
+ SolrInputDocument doc = new SolrInputDocument("id", "1", "evt_dt",
"2017-10-23T00:00:00Z");
+ assertEquals(0, jetty.getSolrClient().add(collectionName,
doc).getStatus());
+
assertFalse(reader.getAliases().getCollectionAliasProperties(aliasName).isEmpty());
+ }
+
public void testCantAddRoutingToNonRouted() throws Exception {
String aliasName = getSaferTestName() + "Alias";
createCollection();