Skip to content

Commit dc31be6

Browse files
authored
SOLR-18104: Remove deprecated constructor in SnapShooter (#4137)
1 parent c1ac036 commit dc31be6

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,37 @@ public boolean abortFetch() {
379379
private void deleteSnapshot(ModifiableSolrParams params, SolrQueryResponse rsp) {
380380
params.required().get(NAME);
381381

382+
String repoName = params.get(CoreAdminParams.BACKUP_REPOSITORY);
382383
String location = params.get(CoreAdminParams.BACKUP_LOCATION);
383-
core.getCoreContainer().assertPathAllowed(location == null ? null : Path.of(location));
384-
SnapShooter snapShooter = new SnapShooter(core, location, params.get(NAME));
384+
385+
// commitName is not documented in ref guide for the backup option.
386+
// copying to here, an dit may be that both are just null?
387+
String commitName = params.get(CoreAdminParams.COMMIT_NAME);
388+
389+
CoreContainer cc = core.getCoreContainer();
390+
BackupRepository repo = null;
391+
if (repoName != null) {
392+
repo = cc.newBackupRepository(repoName);
393+
location = repo.getBackupLocation(location);
394+
if (location == null) {
395+
throw new IllegalArgumentException("location is required");
396+
}
397+
} else {
398+
repo = new LocalFileSystemRepository();
399+
if (location == null) {
400+
location = core.getDataDir();
401+
} else {
402+
location =
403+
core.getCoreDescriptor().getInstanceDir().resolve(location).normalize().toString();
404+
}
405+
}
406+
if ("file".equals(repo.createURI("x").getScheme())) {
407+
core.getCoreContainer().assertPathAllowed(Path.of(location));
408+
}
409+
410+
URI locationUri = repo.createDirectoryURI(location);
411+
SnapShooter snapShooter =
412+
new SnapShooter(repo, core, locationUri, params.get(NAME), commitName);
385413
snapShooter.validateDeleteSnapshot();
386414
snapShooter.deleteSnapAsync(this);
387415
rsp.add(STATUS, OK_STATUS);
@@ -1505,7 +1533,11 @@ public void postCommit() {
15051533
if (numberToKeep < 1) {
15061534
numberToKeep = Integer.MAX_VALUE;
15071535
}
1508-
SnapShooter snapShooter = new SnapShooter(core, null, null);
1536+
1537+
URI locationUri = Path.of(core.getDataDir()).toUri();
1538+
1539+
SnapShooter snapShooter =
1540+
new SnapShooter(new LocalFileSystemRepository(), core, locationUri, null, null);
15091541
snapShooter.validateCreateSnapshot();
15101542
snapShooter.createSnapAsync(numberToKeep, (nl) -> snapShootDetails = nl);
15111543
} catch (Exception e) {

solr/core/src/java/org/apache/solr/handler/SnapShooter.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.apache.solr.core.SolrCore;
4646
import org.apache.solr.core.backup.repository.BackupRepository;
4747
import org.apache.solr.core.backup.repository.BackupRepository.PathType;
48-
import org.apache.solr.core.backup.repository.LocalFileSystemRepository;
4948
import org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager;
5049
import org.apache.solr.handler.api.V2ApiUtils;
5150
import org.slf4j.Logger;
@@ -67,22 +66,6 @@ public class SnapShooter {
6766
private BackupRepository backupRepo = null;
6867
private String commitName; // can be null
6968

70-
@Deprecated
71-
public SnapShooter(SolrCore core, String location, String snapshotName) {
72-
String snapDirStr = null;
73-
// Note - This logic is only applicable to the usecase where a shared file-system is exposed via
74-
// local file-system interface (primarily for backwards compatibility). For other use-cases,
75-
// users will be required to specify "location" where the backup should be stored.
76-
if (location == null) {
77-
snapDirStr = core.getDataDir();
78-
} else {
79-
snapDirStr =
80-
core.getCoreDescriptor().getInstanceDir().resolve(location).normalize().toString();
81-
}
82-
initialize(
83-
new LocalFileSystemRepository(), core, Path.of(snapDirStr).toUri(), snapshotName, null);
84-
}
85-
8669
public SnapShooter(
8770
BackupRepository backupRepo,
8871
SolrCore core,
@@ -245,8 +228,7 @@ public static IndexCommit getAndSaveNamedIndexCommit(SolrCore solrCore, String c
245228
+ solrCore.getName());
246229
}
247230

248-
public void createSnapAsync(final int numberToKeep, Consumer<NamedList<?>> result)
249-
throws IOException {
231+
public void createSnapAsync(final int numberToKeep, Consumer<NamedList<?>> result) {
250232
// TODO should use Solr's ExecutorUtil
251233
new Thread(
252234
() -> {

solr/solr-ref-guide/modules/deployment-guide/pages/user-managed-index-replication.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ The snapshot will be created in a directory called `snapshot.<name>` within the
518518
By default the name is generated using date in `yyyyMMddHHmmssSSS` format.
519519
If the `location` parameter is passed, that would be used instead of the data directory.
520520

521-
`repository`::: The name of the backup repository to use
521+
`repository`::: The name of the backup repository to use.
522522
When not specified, it defaults to local file system.
523523

524524
`location`::: Backup location.
@@ -569,6 +569,9 @@ There are two supported parameters:
569569
`name`::: The name of the snapshot.
570570
A snapshot with the name `snapshot._name_` must exist or an error will be returned.
571571

572+
`repository`::: The name of the backup repository to use.
573+
When not specified, it defaults to local file system.
574+
572575
`location`::: The location where the snapshot is created.
573576

574577

0 commit comments

Comments
 (0)