SOLR-9242: fix windows path issue + load live cluster properties. This closes #62

This commit is contained in:
Varun Thacker 2016-08-04 22:13:05 +05:30
parent d07f2dd87d
commit d5a7ca79f3
4 changed files with 16 additions and 17 deletions

View File

@ -32,6 +32,7 @@ import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.NoLockFactory;
import org.apache.lucene.store.SimpleFSDirectory;
import org.apache.lucene.util.Constants;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.DirectoryFactory;
@ -59,10 +60,22 @@ public class LocalFileSystemRepository implements BackupRepository {
@Override
public URI createURI(String... pathComponents) {
Preconditions.checkArgument(pathComponents.length > 0);
Path result = Paths.get(pathComponents[0]);
String basePath = Preconditions.checkNotNull(pathComponents[0]);
// Note the URI.getPath() invocation on Windows platform generates an invalid URI.
// Refer to http://stackoverflow.com/questions/9834776/java-nio-file-path-issue
// Since the caller may have used this method to generate the string representation
// for the pathComponents, we implement a work-around specifically for Windows platform
// to remove the leading '/' character.
if (Constants.WINDOWS) {
basePath = basePath.replaceFirst("^/(.:/)", "$1");
}
Path result = Paths.get(basePath);
for (int i = 1; i < pathComponents.length; i++) {
result = result.resolve(pathComponents[i]);
}
return result.toUri();
}

View File

@ -714,10 +714,8 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission
String location = repository.getBackupLocation(req.getParams().get(CoreAdminParams.BACKUP_LOCATION));
if (location == null) {
//Refresh the cluster property file to make sure the value set for location is the latest
h.coreContainer.getZkController().getZkStateReader().forceUpdateClusterProperties();
// Check if the location is specified in the cluster property.
location = h.coreContainer.getZkController().getZkStateReader().getClusterProperty(CoreAdminParams.BACKUP_LOCATION, null);
location = new ClusterProperties(h.coreContainer.getZkController().getZkClient()).getClusterProperty(CoreAdminParams.BACKUP_LOCATION, null);
if (location == null) {
throw new SolrException(ErrorCode.BAD_REQUEST, "'location' is not specified as a query"
+ " parameter or as a default repository property or as a cluster property.");
@ -755,10 +753,8 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission
String location = repository.getBackupLocation(req.getParams().get(CoreAdminParams.BACKUP_LOCATION));
if (location == null) {
//Refresh the cluster property file to make sure the value set for location is the latest
h.coreContainer.getZkController().getZkStateReader().forceUpdateClusterProperties();
// Check if the location is specified in the cluster property.
location = h.coreContainer.getZkController().getZkStateReader().getClusterProperty("location", null);
location = new ClusterProperties(h.coreContainer.getZkController().getZkClient()).getClusterProperty("location", null);
if (location == null) {
throw new SolrException(ErrorCode.BAD_REQUEST, "'location' is not specified as a query"
+ " parameter or as a default repository property or as a cluster property.");

View File

@ -16,7 +16,6 @@
*/
package org.apache.solr.cloud;
import org.apache.lucene.util.Constants;
import org.junit.BeforeClass;
/**
@ -28,7 +27,6 @@ public class TestLocalFSCloudBackupRestore extends AbstractCloudBackupRestoreTes
@BeforeClass
public static void setupClass() throws Exception {
assumeFalse("Backup/Restore is currently buggy on Windows. Tracking the fix on SOLR-9242", Constants.WINDOWS);
configureCluster(NUM_SHARDS)// nodes
.addConfig("conf1", TEST_PATH().resolve("configsets").resolve("cloud-minimal").resolve("conf"))
.configure();

View File

@ -866,14 +866,6 @@ public class ZkStateReader implements Closeable {
loadClusterProperties();
};
/**
* We should try keeping this to a minimum. Only in scenarios where the value being read is a user facing property
* should we force update to make sure we are reading the latest value.
*/
public void forceUpdateClusterProperties() {
loadClusterProperties();
}
@SuppressWarnings("unchecked")
private void loadClusterProperties() {
try {