iamsanjay commented on code in PR #1740:
URL: https://github.com/apache/solr/pull/1740#discussion_r1256683858


##########
solr/core/src/java/org/apache/solr/handler/admin/BackupCoreOp.java:
##########
@@ -17,84 +17,48 @@
 
 package org.apache.solr.handler.admin;
 
-import java.net.URI;
-import java.nio.file.Paths;
-import java.util.Optional;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.CoreAdminParams;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.backup.BackupFilePaths;
+import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.core.backup.ShardBackupId;
-import org.apache.solr.core.backup.repository.BackupRepository;
-import org.apache.solr.handler.IncrementalShardBackup;
-import org.apache.solr.handler.SnapShooter;
+import org.apache.solr.handler.admin.api.BackupCoreAPI;
+import org.apache.solr.handler.api.V2ApiUtils;
+import org.apache.solr.jersey.SolrJerseyResponse;
 
 class BackupCoreOp implements CoreAdminHandler.CoreAdminOp {
 
   @Override
   public void execute(CoreAdminHandler.CallInfo it) throws Exception {
     final SolrParams params = it.req.getParams();
-
-    String cname = params.required().get(CoreAdminParams.CORE);
-    boolean incremental = isIncrementalBackup(params);
-    final String name = parseBackupName(params);
-    final ShardBackupId shardBackupId = parseShardBackupId(params);
-    String prevShardBackupIdStr = 
params.get(CoreAdminParams.PREV_SHARD_BACKUP_ID, null);
-    String repoName = params.get(CoreAdminParams.BACKUP_REPOSITORY);
+    BackupCoreAPI.BackupCoreRequestBody backupCoreRequestBody =
+        new BackupCoreAPI.BackupCoreRequestBody();
+    backupCoreRequestBody.repository = 
params.get(CoreAdminParams.BACKUP_REPOSITORY);
+    backupCoreRequestBody.location = 
params.get(CoreAdminParams.BACKUP_LOCATION);
     // An optional parameter to describe the snapshot to be backed-up. If this
     // parameter is not supplied, the latest index commit is backed-up.
-    String commitName = params.get(CoreAdminParams.COMMIT_NAME);
-
-    try (BackupRepository repository = 
it.handler.coreContainer.newBackupRepository(repoName);
-        SolrCore core = it.handler.coreContainer.getCore(cname)) {
-      String location = 
repository.getBackupLocation(params.get(CoreAdminParams.BACKUP_LOCATION));
-      if (location == null) {
-        throw new SolrException(
-            SolrException.ErrorCode.BAD_REQUEST,
-            "'location' is not specified as a query"
-                + " parameter or as a default repository property");
-      }
+    backupCoreRequestBody.commitName = params.get(CoreAdminParams.COMMIT_NAME);
 
-      URI locationUri = repository.createDirectoryURI(location);
-      repository.createDirectory(locationUri);
+    String cname = params.required().get(CoreAdminParams.CORE);
+    final String name = parseBackupName(params);
+    boolean incremental = isIncrementalBackup(params);
+    if (incremental) {
+      backupCoreRequestBody.shardBackupId = 
params.required().get(CoreAdminParams.SHARD_BACKUP_ID);
+      backupCoreRequestBody.prevShardBackupId =
+          params.get(CoreAdminParams.PREV_SHARD_BACKUP_ID, null);
+      backupCoreRequestBody.incremental = true;
+    }
+    BackupCoreAPI backupCoreAPI =
+        new BackupCoreAPI(
+            it.handler.coreContainer, it.req, it.rsp, 
it.handler.coreAdminAsyncTracker);
+    try {
+      SolrJerseyResponse response =
+          backupCoreAPI.createBackup(cname, name, backupCoreRequestBody, null);

Review Comment:
   I believe v1 calls come through `CoreAdminHandler.handleRequestBody()` and 
it looks for `async` parameter. If present, they create an CoreAdminOp object, 
such as  BackupCoreOp in our case and then run it asynchronously via calling 
`CoreAdminAsyncTracker.submitAsyncTask()`. As per my understanding, if we start 
submitting `async` in `BackupCoreOp` as well then same task will be submitted 
twice to `ExecutorService`. 
https://github.com/apache/solr/blob/583fdf0cc7438cd3a50e4d0aa865281ff209c5c6/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java#L196-L227
   But if call come via v2 api, then we are passing the actual taskID, not 
null. 
   
https://github.com/apache/solr/blob/cbe661547d7f12f0c4d21e6fef4e03455b97575c/solr/core/src/java/org/apache/solr/handler/admin/api/BackupCoreAPI.java#L78-L84
   Same way we are handling in `CreateSnapshotOp.java`.
   
https://github.com/apache/solr/blob/583fdf0cc7438cd3a50e4d0aa865281ff209c5c6/solr/core/src/java/org/apache/solr/handler/admin/CreateSnapshotOp.java#L37-L38



-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to