← Back to Pull requests

SOLR-17731: Fix shadowed v2 alias and snapshot APIs #5353

Merged
epugh merged 32 files (1274 lines) on Nov 22, 2026 16:27 UTC
View on GitHub
epugh epugh commented on Nov 16, 2026 19:52 UTC
Author

https://issues.apache.org/jira/browse/SOLR-17731

Description

The DELETE resource paths shadow GET /api/aliases/{aliasName} and POST /api/collections/{collName}/snapshots/{snapshotName}, causing valid requests to return HTTP 405. This PR restores both routes and brings the alias and collection snapshot APIs into line with the v2 conventions.

Solution

  • Align the class-level resource roots and move resource names to method-level paths, preserving the public URLs.

  • Reuse GetAliasByNameResponse for each entry in the v2 alias listing. Entries now contain name, a collections array, and properties, matching the detail response. Update the Admin UI to consume this structure and preserve the v1 LISTALIASES response format.

  • Introduce typed collection snapshot metadata, including replica details and creation time in epoch milliseconds. Use the narrower synchronous listing response base and include CREATE response fields consistently in JSON, XML, and Javabin.

  • Return HTTP 404 for missing aliases, collections, and snapshots, and HTTP 400 for a missing snapshot creation body. Preserve the v1 snapshot collection error codes, missing-snapshot deletion no-op, and listing format in the adapters.

  • Migrate bin/solr snapshot create, delete, list, and describe to the generated v2 clients. Use typed metadata directly when describing a snapshot, removing the legacy response parsing.

  • Update the reference guide examples and API conventions documentation.
  • Implementation and test development assisted by Claude and Codex.

    Tests

    Validation performed during development:

  • Generated-client HTTP tests for alias and collection snapshot APIs, covering routing, response data, missing resources, alias resolution, v1 compatibility, and snapshot XML/Javabin responses.

  • Snapshot CLI tests through both parsers: 10 passing tests after the final cleanup.

  • AdminUiCollectionsScreenTest: 7 passing Selenium tests, including alias collections and properties.

  • ./gradlew tidy

  • ./gradlew check -x test

  • ./gradlew :solr:packaging:devFull
  • The snapshot BATS suite has not been run.

    Diff: 1274 lines (+959 / -315) across 32 files Reviewer: None requested Review duration: 8435m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.84) × (1 − Review Confidence (0.67)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.84 · 1274 lines diff across 32 files
    0.84
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.58 · 5 substantive comment(s)
    0.58
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 10%
    66%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    No Reviewer Assigned no_reviewer_assigned
    0.120
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    11 items
    nick-boss-tech nick-boss-tech commented on code on Nov 20, 2026 00:02 UTC
    Code Review
    solr/core/src/test/org/apache/solr/cli/SnapshotToolsTest.java:1
    @@ -62,19 +62,32 @@ String run(Class<? extends ToolBase> tool, String name, String... extra) throws
     
       @Test
       public void testSnapshotLifecycle() throws Exception {
    -    run(SnapshotCreateTool.class, "snapshot-create", "--snapshot-name", "snap1");
    +    assertTrue(
    +        run(SnapshotCreateTool.class, "snapshot-create", "--snapshot-name", "snap1")
    +            .contains("Successfully created snapshot"));
     
         assertTrue(run(SnapshotListTool.class, "snapshot-list").contains("snap1"));
     
         String described =
             run(SnapshotDescribeTool.class, "snapshot-describe", "--snapshot-name", "snap1");
         assertTrue(described, described.contains("Name: snap1"));
    +    assertTrue(described, described.contains("Status: Successful"));
    +    assertTrue(described, described.contains("Total number of cores with snapshot: 1"));
    +    assertTrue(described, described.contains("leader=true"));
     
         run(SnapshotDeleteTool.class, "snapshot-delete", "--snapshot-name", "snap1");
     
         assertFalse(run(SnapshotListTool.class, "snapshot-list").contains("snap1"));
       }
     
    +  @Test
    +  public void testDeleteMissingSnapshot() throws Exception {

    🤖 AI text below 🤖

    Should deleting a missing snapshot remain a no-op for the CLI? It succeeded idempotently on v1. After this change the v2 404 prints “Failed,” but the command still exits 0. This test explicitly enforces both because run() requires exit 0. I’d preserve the CLI’s no-op for an already absent snapshot. If we want to make it a CLI error instead, the test should require a nonzero exit status.

    nick-boss-tech nick-boss-tech commented on code on Nov 20, 2026 00:06 UTC
    Code Review
    solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java:1
    @@ -98,20 +95,9 @@ void listSnapshots(SnapshotListParams params) throws Exception {
       }
     
       public void listSnapshots(SolrClient solrClient, String collectionName) {
    -    CollectionAdminRequest.ListSnapshots listSnaps =
    -        new CollectionAdminRequest.ListSnapshots(collectionName);
    -    CollectionAdminResponse resp;
         try {
    -      resp = listSnaps.process(solrClient);
    -      if (resp.getStatus() != 0) {
    -        throw new IllegalStateException(
    -            "The LISTSNAPSHOTS request failed. The status code is " + resp.getStatus());
    -      }
    -
    -      NamedList<?> apiResult =
    -          (NamedList<?>) resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO);
    -      apiResult.forEach((name, value) -> echo(name));
    -
    +      var response = new CollectionSnapshotsApi.ListSnapshots(collectionName).process(solrClient);

    🤖 AI text below 🤖

    Could we cover a proxied base URL before moving all four CLI commands to v2? With a base path like /solr-tenant/solr, the v2 URL builder replaces the first /solr substring, producing /api-tenant/solr instead of /solr-tenant/api. That rewrite already exists, but the v1 snapshot CLI didn’t use it. Can we preserve the configured prefix or keep these commands on v1 until the rewrite is fixed?

    nick-boss-tech nick-boss-tech commented on code on Nov 20, 2026 00:06 UTC
    Code Review
    solr/core/src/test/org/apache/solr/handler/admin/api/CreateCollectionSnapshotAPITest.java:1
    @@ -16,70 +16,236 @@
      */
     package org.apache.solr.handler.admin.api;
     
    -import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;
    -import static org.apache.solr.common.params.CollectionAdminParams.FOLLOW_ALIASES;
    -import static org.hamcrest.Matchers.containsInAnyOrder;
    -import static org.mockito.ArgumentMatchers.anyString;
    -import static org.mockito.Mockito.when;
    -
    -import org.apache.solr.client.api.model.CreateCollectionSnapshotRequestBody;
    -import org.apache.solr.common.params.CollectionParams;
    -import org.apache.solr.common.params.CoreAdminParams;
    -import org.junit.Before;
    +import java.io.ByteArrayInputStream;
    +import java.util.List;
    +import java.util.Map;
    +import org.apache.solr.client.solrj.RemoteSolrException;
    +import org.apache.solr.client.solrj.request.CollectionAdminRequest;
    +import org.apache.solr.client.solrj.request.CollectionSnapshotsApi;
    +import org.apache.solr.client.solrj.response.JavaBinResponseParser;
    +import org.apache.solr.client.solrj.response.XMLResponseParser;
    +import org.apache.solr.cloud.SolrCloudTestCase;
    +import org.apache.solr.common.SolrInputDocument;
    +import org.apache.solr.common.util.NamedList;
    +import org.apache.solr.common.util.Utils;
    +import org.apache.solr.core.snapshots.CollectionSnapshotMetaData;
    +import org.eclipse.jetty.client.StringRequestContent;
    +import org.junit.After;
    +import org.junit.BeforeClass;
     import org.junit.Test;
    -import org.mockito.Mockito;
     
    -public class CreateCollectionSnapshotAPITest extends MockV2APITest {
    +/** HTTP integration tests for creating collection snapshots through the generated client. */
    +public class CreateCollectionSnapshotAPITest extends SolrCloudTestCase {
    +  private static final String COLLECTION = "snapshot_api_collection";
    +  private static final String ALIAS = "snapshot_api_alias";
     
    -  private CreateCollectionSnapshot api;
    +  @BeforeClass
    +  public static void setupCluster() throws Exception {
    +    configureCluster(1).addConfig("conf", configset("cloud-minimal")).configure();
    +    CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1)
    +        .process(cluster.getSolrClient());
    +    cluster.waitForActiveCollection(COLLECTION, 1, 1);
    +    cluster.getSolrClient().add(COLLECTION, new SolrInputDocument("id", "1"));
    +    cluster.getSolrClient().commit(COLLECTION);
    +    CollectionAdminRequest.createAlias(ALIAS, COLLECTION).process(cluster.getSolrClient());
    +  }
     
    -  @Override
    -  @Before
    -  public void setUp() throws Exception {
    -    super.setUp();
    -    when(mockCoreContainer.isZooKeeperAware()).thenReturn(true);
    +  @After
    +  public void clearSnapshots() throws Exception {
    +    var response =
    +        new CollectionSnapshotsApi.ListSnapshots(COLLECTION).process(cluster.getSolrClient());
    +    for (String snapshot : response.snapshots.keySet()) {
    +      new CollectionSnapshotsApi.DeleteCollectionSnapshot(COLLECTION, snapshot)
    +          .process(cluster.getSolrClient());
    +    }
    +  }
     
    -    api = new CreateCollectionSnapshot(mockCoreContainer, mockQueryRequest, queryResponse);
    +  @Test
    +  public void testMissingCollections() throws Exception {
    +    var client = cluster.getSolrClient();
    +    assertEquals(
    +        404,
    +        expectThrows(
    +                RemoteSolrException.class,
    +                () ->
    +                    new CollectionSnapshotsApi.CreateCollectionSnapshot("missing", "snapshot")
    +                        .process(client))
    +            .code());
    +    assertEquals(
    +        404,
    +        expectThrows(
    +                RemoteSolrException.class,
    +                () -> new CollectionSnapshotsApi.ListSnapshots("missing").process(client))
    +            .code());
    +    assertEquals(
    +        404,
    +        expectThrows(
    +                RemoteSolrException.class,
    +                () ->
    +                    new CollectionSnapshotsApi.DeleteCollectionSnapshot("missing", "snapshot")
    +                        .process(client))
    +            .code());
    +    assertEquals(
    +        400,
    +        expectThrows(
    +                RemoteSolrException.class,
    +                () ->
    +                    new CollectionAdminRequest.CreateSnapshot("missing", "snapshot")
    +                        .process(client))
    +            .code());
    +    assertEquals(
    +        400,
    +        expectThrows(
    +                RemoteSolrException.class,
    +                () -> new CollectionAdminRequest.ListSnapshots("missing").process(client))
    +            .code());
    +    assertEquals(
    +        400,
    +        expectThrows(
    +                RemoteSolrException.class,
    +                () ->
    +                    new CollectionAdminRequest.DeleteSnapshot("missing", "snapshot")
    +                        .process(client))
    +            .code());
       }
     
       @Test
    -  public void testConstructsValidOverseerMessage() throws Exception {
    -    when(mockClusterState.hasCollection("myCollName")).thenReturn(true);
    -    when(mockSolrZkClient.exists(anyString())).thenReturn(false);
    +  public void testMissingSnapshot() throws Exception {
    +    var request = new CollectionSnapshotsApi.DeleteCollectionSnapshot(COLLECTION, "missing");
    +    var error =
    +        expectThrows(RemoteSolrException.class, () -> request.process(cluster.getSolrClient()));
    +    assertEquals(404, error.code());
    +    assertTrue(error.getMessage(), error.getMessage().contains("missing"));
    +    new CollectionAdminRequest.DeleteSnapshot(COLLECTION, "missing")
    +        .process(cluster.getSolrClient());
    +  }
     
    -    CreateCollectionSnapshotRequestBody body = new CreateCollectionSnapshotRequestBody();
    -    body.followAliases = false;
    +  @Test
    +  public void testMissingRequestBody() throws Exception {
    +    var jetty = cluster.getJettySolrRunner(0);
    +    var response =
    +        jetty
    +            .getSolrClient()
    +            .getHttpClient()
    +            .newRequest(
    +                jetty.getBaseURLV2() + "/collections/" + COLLECTION + "/snapshots/missing_body")
    +            .method("POST")
    +            .send();
    +    assertEquals(400, response.getStatus());
    +    var error = (Map<?, ?>) ((Map<?, ?>) Utils.fromJSON(response.getContent())).get("error");
    +    assertEquals(400L, ((Number) error.get("code")).longValue());
    +    assertTrue(error.toString(), error.get("msg").toString().contains("request-body"));
    +  }
     
    -    api.createCollectionSnapshot("myCollName", "mySnapshotName", body);
    +  @Test
    +  public void testCreateResponseFormats() throws Exception {
    +    var jetty = cluster.getJettySolrRunner(0);
    +    for (String format : List.of("xml", "javabin")) {
    +      String snapshot = "snapshot_" + format;
    +      var response =
    +          jetty
    +              .getSolrClient()
    +              .getHttpClient()
    +              .newRequest(
    +                  jetty.getBaseURLV2()
    +                      + "/collections/"
    +                      + ALIAS
    +                      + "/snapshots/"
    +                      + snapshot
    +                      + "?wt="
    +                      + format)
    +              .method("POST")
    +              .body(new StringRequestContent("application/json", "{\"followAliases\":true}"))
    +              .send();
    +      assertEquals(200, response.getStatus());
    +      var parser = format.equals("xml") ? new XMLResponseParser() : new JavaBinResponseParser();
    +      var body = parser.processResponse(new ByteArrayInputStream(response.getContent()), "UTF-8");
    +      assertEquals(ALIAS, body.get("collection"));
    +      assertEquals(true, body.get("followAliases"));
    +      assertEquals(snapshot, body.get("snapshot"));
    +      var listing =
    +          jetty
    +              .getSolrClient()
    +              .getHttpClient()
    +              .newRequest(
    +                  jetty.getBaseURLV2() + "/collections/" + COLLECTION + "/snapshots?wt=" + format)
    +              .send();
    +      assertEquals(200, listing.getStatus());
    +      var listingBody =
    +          parser.processResponse(new ByteArrayInputStream(listing.getContent()), "UTF-8");
    +      assertEquals(snapshot, listingBody._get("snapshots/" + snapshot + "/name"));
    +      assertEquals("Successful", listingBody._get("snapshots/" + snapshot + "/status"));
    +    }
    +  }
    +
    +  @Test
    +  public void testCreateListAndDeleteSnapshot() throws Exception {

    🤖 AI text below 🤖

    Could we keep an async-create assertion in the new HTTP tests? The removed unit test checked that the body’s async ID reached the collection command; the replacement cases all submit synchronously. A generated-client test could assert the returned request ID, wait for terminal success via REQUESTSTATUS, and then check that the snapshot appears in the listing.

    nick-boss-tech nick-boss-tech commented on code on Nov 20, 2026 00:07 UTC
    Code Review
    solr/solr-ref-guide/modules/deployment-guide/pages/collection-management.adoc:1
    @@ -2537,6 +2537,8 @@ This is particularly useful prior to reindexing or making config changes to a co
     Unlike backups, which copy collection data off-disk, snapshots themselves don't provide disaster recovery in case of disk or hardware failure.
     They provide less protection than backups, at a much cheaper cost.
     
    +The v2 API requires a JSON request body (use `{}` for the defaults) and returns HTTP 404 if the collection does not exist.

    🤖 AI text below 🤖

    If the CLI migration stays in this PR, could the upgrade notes say that snapshot create now requires a server with the v2 route fix? A new CLI pointed at an unupgraded node through --solr-url can hit the same HTTP 405 this PR fixes. Operators with proxy allowlists or custom permissions scoped to /solr/admin/collections should also check the new /api/collections/.../snapshots paths.

    epugh epugh commented on code on Nov 21, 2026 11:45 UTC
    Code Review
    solr/solr-ref-guide/modules/deployment-guide/pages/collection-management.adoc:1
    @@ -2537,6 +2537,8 @@ This is particularly useful prior to reindexing or making config changes to a co
     Unlike backups, which copy collection data off-disk, snapshots themselves don't provide disaster recovery in case of disk or hardware failure.
     They provide less protection than backups, at a much cheaper cost.
     
    +The v2 API requires a JSON request body (use `{}` for the defaults) and returns HTTP 404 if the collection does not exist.

    yeah, i think the version of bin/solr is in lockstep with the version of Solr server. We don't ship a seperate binary (maybe we should), so these types of things I think are okay..

    epugh epugh commented on code on Nov 21, 2026 11:50 UTC
    Code Review
    solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java:1
    @@ -98,20 +95,9 @@ void listSnapshots(SnapshotListParams params) throws Exception {
       }
     
       public void listSnapshots(SolrClient solrClient, String collectionName) {
    -    CollectionAdminRequest.ListSnapshots listSnaps =
    -        new CollectionAdminRequest.ListSnapshots(collectionName);
    -    CollectionAdminResponse resp;
         try {
    -      resp = listSnaps.process(solrClient);
    -      if (resp.getStatus() != 0) {
    -        throw new IllegalStateException(
    -            "The LISTSNAPSHOTS request failed. The status code is " + resp.getStatus());
    -      }
    -
    -      NamedList<?> apiResult =
    -          (NamedList<?>) resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO);
    -      apiResult.forEach((name, value) -> echo(name));
    -
    +      var response = new CollectionSnapshotsApi.ListSnapshots(collectionName).process(solrClient);

    i see... took me and claude a bit to figure out what you mean, that the bug is already here, this PR just exposes it... I actually have similar worries for our v2 api calls in the Admin UI, though I have never tested that...

    epugh epugh commented on code on Nov 21, 2026 11:55 UTC
    Code Review
    solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java:1
    @@ -98,20 +95,9 @@ void listSnapshots(SnapshotListParams params) throws Exception {
       }
     
       public void listSnapshots(SolrClient solrClient, String collectionName) {
    -    CollectionAdminRequest.ListSnapshots listSnaps =
    -        new CollectionAdminRequest.ListSnapshots(collectionName);
    -    CollectionAdminResponse resp;
         try {
    -      resp = listSnaps.process(solrClient);
    -      if (resp.getStatus() != 0) {
    -        throw new IllegalStateException(
    -            "The LISTSNAPSHOTS request failed. The status code is " + resp.getStatus());
    -      }
    -
    -      NamedList<?> apiResult =
    -          (NamedList<?>) resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO);
    -      apiResult.forEach((name, value) -> echo(name));
    -
    +      var response = new CollectionSnapshotsApi.ListSnapshots(collectionName).process(solrClient);

    goign to move it to it's own PR...

    dsmiley dsmiley commented on code on Nov 27, 2026 14:56 UTC
    Code Review
    solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc:1

    @epugh You modified this file instead of the one for solr-10. That suggests that the changes here should be main-only. But the milestone is set to 10.x, which is a contradiction. What's going on?

    epugh epugh commented on code on Nov 27, 2026 23:21 UTC
    Code Review
    solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc:1

    thanks @dsmiley .. So, I think this is me getting a bit too fast and loose.. AI tooling really likes to add stuff to these major-changes-in docs, and often I delete the entry as "not a major chnage". In this case, I was a bit on the fence about if this change was going to be 11 only, but then decided it was 10 and 11.

    I'll open up a fresh PR in the morning to fix this, and beef up my workflow a bit to prevent it in the future.

    dsmiley dsmiley commented on code on Dec 01, 2026 05:31 UTC
    Code Review
    solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc:1

    I don't see an inbound reference in the timeline of the new PR you speak of. Anyway, I'm backporting this, including moving the major-changes-in-solr-11.adoc to major-changes-in-solr-10.adoc. I suggest you use that part for the fixup.

    Reviewers
    None requested
    Assignees
    epugh epugh
    Labels
    risk: low confidence: 66.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 83.5% (HIGH) · Higher = larger blast radius
    83.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 66.5% · Lower = rushed or shallow review
    66.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.0% · Safe to merge
    28.0%
    Repository