lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsmi...@apache.org
Subject [3/3] lucene-solr:solr-5750: SOLR-5750: BACKUP insist the backup parent dir exists. (in SolrCloud this critically ensures we throw if not used on a shared file system)
Date Mon, 02 May 2016 04:05:55 GMT
SOLR-5750: BACKUP insist the backup parent dir exists.
(in SolrCloud this critically ensures we throw if not used on a shared file system)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b073d625
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b073d625
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b073d625

Branch: refs/heads/solr-5750
Commit: b073d6252a9c1ccfea27378e720ff4e2b15a4292
Parents: 8ada9ed
Author: David Smiley <dsmiley@apache.org>
Authored: Mon May 2 00:05:26 2016 -0400
Committer: David Smiley <dsmiley@apache.org>
Committed: Mon May 2 00:05:26 2016 -0400

----------------------------------------------------------------------
 .../src/java/org/apache/solr/handler/SnapShooter.java     | 10 +++++++++-
 .../org/apache/solr/handler/admin/CoreAdminOperation.java |  9 +++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b073d625/solr/core/src/java/org/apache/solr/handler/SnapShooter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java
index 92b9246..2365fca 100644
--- a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java
+++ b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java
@@ -19,6 +19,8 @@ package org.apache.solr.handler;
 import java.io.File;
 import java.io.IOException;
 import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -58,6 +60,7 @@ public class SnapShooter {
   private String snapshotName = null;
   private String directoryName = null;
   private File snapShotDir = null;
+  //TODO update to NIO Path API
 
   public SnapShooter(SolrCore core, String location, String snapshotName) {
     solrCore = core;
@@ -77,6 +80,11 @@ public class SnapShooter {
     }
   }
 
+  /** Gets the parent directory of the snapshots.  This is the {@code location} given in
the constructor after
+   * being resolved against the core instance dir. */
+  public Path getLocation() {
+    return Paths.get(snapDir);
+  }
 
   public void validateDeleteSnapshot() {
     boolean dirFound = false;
@@ -107,7 +115,7 @@ public class SnapShooter {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
           "Snapshot directory already exists: " + snapShotDir.getAbsolutePath());
     }
-    if (!snapShotDir.mkdirs()) {
+    if (!snapShotDir.mkdirs()) { // note: TODO reconsider mkdirs vs mkdir
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
           "Unable to create snapshot directory: " + snapShotDir.getAbsolutePath());
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b073d625/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java
index 6cf4589..51e776d 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java
@@ -18,6 +18,7 @@ package org.apache.solr.handler.admin;
 
 import java.io.IOException;
 import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -864,6 +865,14 @@ enum CoreAdminOperation {
 
       try (SolrCore core = callInfo.handler.coreContainer.getCore(cname)) {
         SnapShooter snapShooter = new SnapShooter(core, location, name);
+        // validateCreateSnapshot will create parent dirs instead of throw; that choice is
dubious.
+        //  But we want to throw. One reason is that
+        //  this dir really should, in fact must, already exist here if triggered via a collection
backup on a shared
+        //  file system. Otherwise, perhaps the FS location isn't shared -- we want an error.
+        if (!Files.exists(snapShooter.getLocation())) {
+          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+              "Directory to contain snapshots doesn't exist: " + snapShooter.getLocation().toAbsolutePath());
+        }
         snapShooter.validateCreateSnapshot();
         snapShooter.createSnapshot();
       } catch (Exception e) {


Mime
View raw message