mirror of https://github.com/apache/lucene.git
SOLR-11783: Rename core in solr standalone mode is not persisted
This commit is contained in:
parent
e3f90385b4
commit
137675ace7
|
@ -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
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue