SOLR-11783: Rename core in solr standalone mode is not persisted

This commit is contained in:
Erick Erickson 2017-12-26 22:16:52 -08:00
parent e3f90385b4
commit 137675ace7
3 changed files with 46 additions and 0 deletions

View File

@ -63,6 +63,11 @@ New Features
* SOLR-11201: Implement autoscaling trigger for arbitrary metrics that creates events when
a given metric breaches a threshold (shalin)
Bug Fixes
----------------------
* SOLR-11783: Rename core in solr standalone mode is not persisted (Erick Erickson)
Optimizations
----------------------

View File

@ -116,6 +116,12 @@ public class CorePropertiesLocator implements CoresLocator {
@Override
public void rename(CoreContainer cc, CoreDescriptor oldCD, CoreDescriptor newCD) {
String oldName = newCD.getPersistableStandardProperties().getProperty(CoreDescriptor.CORE_NAME);
String newName = newCD.coreProperties.getProperty(CoreDescriptor.CORE_NAME);
if (oldName == null ||
(newName != null && oldName.equals(newName) == false)) {
newCD.getPersistableStandardProperties().put(CoreDescriptor.CORE_NAME, newName);
}
persist(cc, newCD);
}

View File

@ -17,11 +17,14 @@
package org.apache.solr.handler.admin;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Properties;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import org.apache.commons.io.FileUtils;
@ -256,6 +259,13 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
copySolrHomeToTemp(solrHomeDirectory, "corex");
File corex = new File(solrHomeDirectory, "corex");
FileUtils.write(new File(corex, "core.properties"), "", StandardCharsets.UTF_8);
copySolrHomeToTemp(solrHomeDirectory, "corerename");
File coreRename = new File(solrHomeDirectory, "corerename");
File renamePropFile = new File(coreRename, "core.properties");
FileUtils.write(renamePropFile, "", StandardCharsets.UTF_8);
JettySolrRunner runner = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), buildJettyConfig("/solr"));
runner.start();
@ -273,11 +283,36 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
req.process(client);
}
// Make sure a renamed core
// 1> has the property persisted (SOLR-11783)
// 2> is deleted after rename properly.
try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString(), DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT)) {
CoreAdminRequest.renameCore("corerename", "brand_new_core_name", client);
Properties props = new Properties();
try (InputStreamReader is = new InputStreamReader(new FileInputStream(renamePropFile), StandardCharsets.UTF_8)) {
props.load(is);
}
assertEquals("Name should have been persisted!", "brand_new_core_name", props.getProperty("name"));
}
try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString(), DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT)) {
CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false);
req.setDeleteInstanceDir(true);
req.setCoreName("brand_new_core_name");
req.process(client);
}
runner.stop();
assertFalse("Instance directory exists after core unload with deleteInstanceDir=true : " + corex,
corex.exists());
assertFalse("Instance directory exists after core unload with deleteInstanceDir=true : " + coreRename,
coreRename.exists());
}
@Test