nick-boss-tech commented on code in PR #5314:
URL: https://github.com/apache/solr/pull/5314#discussion_r4570135296
##########
solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java:
##########
@@ -360,6 +362,50 @@ private CloudSolrClient
createHttpCSPBasedCloudSolrClient() {
return new CloudSolrClient.Builder(solrUrls).build();
}
+ @Test
+ public void testZkAliasDoesNotReadAliasCollectionState() throws Exception {
+ String collection = getSaferTestName();
+ String alias = collection + "_alias";
+ CollectionAdminRequest.createCollection(collection, "conf", 2, 1)
+ .process(cluster.getSolrClient());
+ cluster.waitForActiveCollection(collection, 2, 2);
+ CollectionAdminRequest.createAlias(alias,
collection).process(cluster.getSolrClient());
+
+ try (CloudSolrClient client =
+ new
CloudSolrClient.Builder(cluster.getZkServer().getZkAddress()).build()) {
+ assertEquals(List.of(collection),
client.getClusterStateProvider().resolveAlias(alias));
+ assertEquals(0, client.query(alias, params("q",
"*:*")).getResults().getNumFound());
+
+ var zkClient =
ZkClientClusterStateProvider.from(client).getZkStateReader().getZkClient();
Review Comment:
🤖 *AI text below* 🤖 *(reviewed by Nick Shanin)*
Thanks. The earlier metrics version used `cluster.getZkClient()`. The
current test records reads on the client supplied to the provider's reader.
That lets it observe the client and path under test. The cluster client is a
different instance.
##########
solr/solrj-zookeeper/src/test/org/apache/solr/client/solrj/impl/ZkClientClusterStateProviderTest.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.cloud.ZkController;
+import org.apache.solr.cloud.ZkTestServer;
+import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.util.Utils;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.data.Stat;
+import org.junit.Test;
+
+public class ZkClientClusterStateProviderTest extends SolrTestCaseJ4 {
+
+ private record ReadAttempt(String path, String failure) {}
+
+ private static class RecordingSolrZkClient extends SolrZkClient {
+ private final List<ReadAttempt> readAttempts = new
CopyOnWriteArrayList<>();
+
+ RecordingSolrZkClient(Builder builder) {
+ super(builder);
+ }
+
+ @Override
+ public byte[] getData(String path, Watcher watcher, Stat stat)
+ throws KeeperException, InterruptedException {
+ try {
+ byte[] data = super.getData(path, watcher, stat);
+ readAttempts.add(new ReadAttempt(path, null));
+ return data;
+ } catch (KeeperException | InterruptedException e) {
+ readAttempts.add(new ReadAttempt(path, e.getClass().getSimpleName()));
+ throw e;
+ }
+ }
+
+ List<ReadAttempt> getReadAttempts() {
+ return List.copyOf(readAttempts);
+ }
+
+ void clearReadAttempts() {
+ readAttempts.clear();
+ }
+ }
+
+ @Test
+ public void testKnownAliasDoesNotReadAliasCollectionState() throws Exception
{
Review Comment:
🤖 *AI text below* 🤖 *(reviewed by Nick Shanin)*
I tried the metrics listener. Its read counter did not capture the failed
`getData` for the missing alias state. The recording client observes that read
on the specific path.
You're right that the recording test calls the provider directly. The
repeated `CloudSolrClient` query test checks that requests succeed, but it does
not count resolutions or reads. I agree that moving alias resolution and
caching into the provider is worth considering separately.
<details>
<summary>Linux verification at
2dbfc9f32aa34cef586f32c7b473a5cd689e8705</summary>
The provider test and the repeated-query test each passed once with seed
`18606CAFE`, with no skips. Removing the alias guard made the provider test
fail on the alias state path. Under the same change, the earlier metrics test
still passed. The [verification
record](https://github.com/nick-boss-tech/solr/blob/coordination-v2/records/receipt/solr-18606-pr5314-alias-signal-linux-gate-r2-20261113-receipt.json)
has the results. The root check passed with test, Docker, and reference-guide
checks excluded.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]