This is an automated email from the ASF dual-hosted git repository.
epugh 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 e158c4d564a SOLR-18403: fix snapshot-export to actually use the named
snapshot (#4807)
e158c4d564a is described below
commit e158c4d564ae002dfc1f1718e672c8013acb7ffc
Author: Serhiy Bzhezytskyy <[email protected]>
AuthorDate: Sat Sep 5 14:39:07 2026 +0300
SOLR-18403: fix snapshot-export to actually use the named snapshot (#4807)
---
.../org/apache/solr/cli/SnapshotExportTool.java | 1 +
.../apache/solr/cli/SnapshotExportToolTest.java | 82 ++++++++++++++++++++++
2 files changed, 83 insertions(+)
diff --git a/solr/core/src/java/org/apache/solr/cli/SnapshotExportTool.java
b/solr/core/src/java/org/apache/solr/cli/SnapshotExportTool.java
index d71b8df8b1a..208edb56ead 100644
--- a/solr/core/src/java/org/apache/solr/cli/SnapshotExportTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/SnapshotExportTool.java
@@ -116,6 +116,7 @@ public class SnapshotExportTool extends ToolBase {
CollectionAdminRequest.Backup backup =
new CollectionAdminRequest.Backup(collectionName, snapshotName);
backup.setCommitName(snapshotName);
+ backup.setIncremental(false);
backup.setIndexBackupStrategy(CollectionAdminParams.COPY_FILES_STRATEGY);
backup.setLocation(destPath);
if (backupRepo != null) {
diff --git a/solr/core/src/test/org/apache/solr/cli/SnapshotExportToolTest.java
b/solr/core/src/test/org/apache/solr/cli/SnapshotExportToolTest.java
new file mode 100644
index 00000000000..c39a38dcf5b
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/cli/SnapshotExportToolTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.cli;
+
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrInputDocument;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * SOLR-18403: SnapshotExportTool must export the state of the named snapshot,
not the live index at
+ * export time.
+ */
+public class SnapshotExportToolTest extends SolrCloudTestCase {
+
+ @BeforeClass
+ public static void setupCluster() throws Exception {
+ System.setProperty("solr.security.allow.paths", "*");
+ configureCluster(2).addConfig("conf",
configset("cloud-minimal")).configure();
+ }
+
+ @Test
+ public void testExportUsesSnapshotStateNotLiveIndex() throws Exception {
+ CloudSolrClient client = cluster.getSolrClient();
+ String collection = "snapshotexporttest";
+ CollectionAdminRequest.createCollection(collection, "conf", 1,
1).process(client);
+ cluster.waitForActiveCollection(collection, 1, 1);
+
+ // index 5 docs, commit, snapshot at this point
+ for (int i = 0; i < 5; i++) {
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField("id", "doc-" + i);
+ client.add(collection, doc);
+ }
+ client.commit(collection);
+
+ String snapshotName = "export-test-snap";
+ new CollectionAdminRequest.CreateSnapshot(collection,
snapshotName).process(client);
+
+ // index 5 MORE docs (6-10) and commit -- live index now has 10, snapshot
still reflects 5
+ for (int i = 5; i < 10; i++) {
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField("id", "doc-" + i);
+ client.add(collection, doc);
+ }
+ client.commit(collection);
+
+ assertEquals(10, client.query(collection, params("q",
"*:*")).getResults().getNumFound());
+
+ String backupLocation = createTempDir().toString();
+ SnapshotExportTool tool = new SnapshotExportTool(new DefaultToolRuntime());
+ tool.exportSnapshot(client, collection, snapshotName, backupLocation,
null, null);
+
+ String restoredCollection = collection + "_restored";
+ CollectionAdminRequest.Restore restore =
+ CollectionAdminRequest.restoreCollection(restoredCollection,
snapshotName)
+ .setLocation(backupLocation);
+ assertEquals(0, restore.process(client).getStatus());
+ cluster.waitForActiveCollection(restoredCollection, 1, 1);
+
+ assertEquals(
+ "export must reflect the snapshot's 5-doc state, not the live index's
10",
+ 5,
+ client.query(restoredCollection, params("q",
"*:*")).getResults().getNumFound());
+ }
+}