SOLR-6533 , changed the node name from solrConfig to config. handle empty command list

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1649486 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2015-01-05 09:18:10 +00:00
parent d7e0fd28dd
commit c8545d6dbf
6 changed files with 33 additions and 14 deletions

View File

@ -2151,10 +2151,9 @@ public final class ZkController {
* *
* @return true on success * @return true on success
*/ */
public static boolean persistConfigResourceToZooKeeper( SolrResourceLoader loader, int znodeVersion , public static boolean persistConfigResourceToZooKeeper( ZkSolrResourceLoader zkLoader, int znodeVersion ,
String resourceName, byte[] content, String resourceName, byte[] content,
boolean createIfNotExists) { boolean createIfNotExists) {
final ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader)loader;
final ZkController zkController = zkLoader.getZkController(); final ZkController zkController = zkLoader.getZkController();
final SolrZkClient zkClient = zkController.getZkClient(); final SolrZkClient zkClient = zkController.getZkClient();
final String resourceLocation = zkLoader.getConfigSetZkPath() + "/" + resourceName; final String resourceLocation = zkLoader.getConfigSetZkPath() + "/" + resourceName;
@ -2162,12 +2161,12 @@ public final class ZkController {
try { try {
try { try {
zkClient.setData(resourceLocation , content,znodeVersion, true); zkClient.setData(resourceLocation , content,znodeVersion, true);
zkClient.setData(zkLoader.getConfigSetZkPath(),new byte[]{0},true); touchConfDir(zkLoader);
} catch (NoNodeException e) { } catch (NoNodeException e) {
if(createIfNotExists){ if(createIfNotExists){
try { try {
zkClient.create(resourceLocation,content, CreateMode.PERSISTENT,true); zkClient.create(resourceLocation,content, CreateMode.PERSISTENT,true);
zkClient.setData(zkLoader.getConfigSetZkPath(), new byte[]{0}, true); touchConfDir(zkLoader);
} catch (KeeperException.NodeExistsException nee) { } catch (KeeperException.NodeExistsException nee) {
try { try {
Stat stat = zkClient.exists(resourceLocation, null, true); Stat stat = zkClient.exists(resourceLocation, null, true);
@ -2206,6 +2205,21 @@ public final class ZkController {
return true; return true;
} }
public static void touchConfDir(ZkSolrResourceLoader zkLoader) {
SolrZkClient zkClient = zkLoader.getZkController().getZkClient();
try {
zkClient.setData(zkLoader.getConfigSetZkPath(),new byte[]{0},true);
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt(); // Restore the interrupted status
}
final String msg = "Error 'touching' conf location " + zkLoader.getConfigSetZkPath();
log.error(msg, e);
throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
}
}
public static class ResourceModifiedInZkException extends SolrException { public static class ResourceModifiedInZkException extends SolrException {
public ResourceModifiedInZkException(ErrorCode code, String msg) { public ResourceModifiedInZkException(ErrorCode code, String msg) {
super(code, msg); super(code, msg);

View File

@ -99,7 +99,7 @@ public class SolrConfigHandler extends RequestHandlerBase {
private void handleGET() { private void handleGET() {
if(parts.size() == 1) { if(parts.size() == 1) {
resp.add("solrConfig", req.getCore().getSolrConfig().toMap()); resp.add("config", req.getCore().getSolrConfig().toMap());
} else { } else {
if(ConfigOverlay.NAME.equals(parts.get(1))){ if(ConfigOverlay.NAME.equals(parts.get(1))){
resp.add(ConfigOverlay.NAME, req.getCore().getSolrConfig().getOverlay().toMap()); resp.add(ConfigOverlay.NAME, req.getCore().getSolrConfig().getOverlay().toMap());
@ -119,7 +119,7 @@ public class SolrConfigHandler extends RequestHandlerBase {
} else { } else {
Map<String, Object> m = req.getCore().getSolrConfig().toMap(); Map<String, Object> m = req.getCore().getSolrConfig().toMap();
resp.add("solrConfig", ZkNodeProps.makeMap(parts.get(1),m.get(parts.get(1)))); resp.add("config", ZkNodeProps.makeMap(parts.get(1),m.get(parts.get(1))));
} }
} }
} }
@ -236,8 +236,13 @@ public class SolrConfigHandler extends RequestHandlerBase {
SolrResourceLoader loader = req.getCore().getResourceLoader(); SolrResourceLoader loader = req.getCore().getResourceLoader();
if (loader instanceof ZkSolrResourceLoader) { if (loader instanceof ZkSolrResourceLoader) {
ZkController.persistConfigResourceToZooKeeper(loader,params.getZnodeVersion(), ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
RequestParams.RESOURCE,params.toByteArray(),true); if(ops.isEmpty()) {
ZkController.touchConfDir(zkLoader);
}else {
ZkController.persistConfigResourceToZooKeeper(zkLoader, params.getZnodeVersion(),
RequestParams.RESOURCE, params.toByteArray(), true);
}
} else { } else {
SolrResourceLoader.persistConfLocally(loader, ConfigOverlay.RESOURCE_NAME, params.toByteArray()); SolrResourceLoader.persistConfLocally(loader, ConfigOverlay.RESOURCE_NAME, params.toByteArray());
@ -278,7 +283,7 @@ public class SolrConfigHandler extends RequestHandlerBase {
SolrResourceLoader loader = req.getCore().getResourceLoader(); SolrResourceLoader loader = req.getCore().getResourceLoader();
if (loader instanceof ZkSolrResourceLoader) { if (loader instanceof ZkSolrResourceLoader) {
ZkController.persistConfigResourceToZooKeeper(loader,overlay.getZnodeVersion(), ZkController.persistConfigResourceToZooKeeper((ZkSolrResourceLoader) loader,overlay.getZnodeVersion(),
ConfigOverlay.RESOURCE_NAME,overlay.toByteArray(),true); ConfigOverlay.RESOURCE_NAME,overlay.toByteArray(),true);
} else { } else {

View File

@ -134,7 +134,7 @@ public class SchemaManager {
if (!errs.isEmpty()) return errs; if (!errs.isEmpty()) return errs;
SolrResourceLoader loader = req.getCore().getResourceLoader(); SolrResourceLoader loader = req.getCore().getResourceLoader();
if (loader instanceof ZkSolrResourceLoader) { if (loader instanceof ZkSolrResourceLoader) {
ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
try { try {
managedIndexSchema.persist(sw); managedIndexSchema.persist(sw);
@ -145,7 +145,7 @@ public class SchemaManager {
} }
try { try {
ZkController.persistConfigResourceToZooKeeper(loader, ZkController.persistConfigResourceToZooKeeper(zkLoader,
managedIndexSchema.getSchemaZkVersion(), managedIndexSchema.getSchemaZkVersion(),
managedIndexSchema.getResourceName(), managedIndexSchema.getResourceName(),
sw.toString().getBytes(StandardCharsets.UTF_8), sw.toString().getBytes(StandardCharsets.UTF_8),

View File

@ -103,7 +103,7 @@ public class TestSolrConfigHandler extends RestTestBase {
assertEquals("100", String.valueOf(getObjectByPath(props, true, ImmutableList.of("updateHandler", "autoCommit", "maxDocs")) )); assertEquals("100", String.valueOf(getObjectByPath(props, true, ImmutableList.of("updateHandler", "autoCommit", "maxDocs")) ));
assertEquals("10", String.valueOf(getObjectByPath(props, true, ImmutableList.of("updateHandler", "autoCommit", "maxTime")) )); assertEquals("10", String.valueOf(getObjectByPath(props, true, ImmutableList.of("updateHandler", "autoCommit", "maxTime")) ));
m = (Map) getRespMap("/config?wt=json" ,harness).get("solrConfig"); m = (Map) getRespMap("/config?wt=json" ,harness).get("config");
assertNotNull(m); assertNotNull(m);
assertEquals( "100",String.valueOf(getObjectByPath(m, true, ImmutableList.of("updateHandler", "autoCommit", "maxDocs")))); assertEquals( "100",String.valueOf(getObjectByPath(m, true, ImmutableList.of("updateHandler", "autoCommit", "maxDocs"))));

View File

@ -72,7 +72,7 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
Map map = TestSolrConfigHandlerConcurrent.getAsMap(url, cloudClient); Map map = TestSolrConfigHandlerConcurrent.getAsMap(url, cloudClient);
assertNotNull(map); assertNotNull(map);
assertEquals("solr.BlobHandler", getObjectByPath(map, true, Arrays.asList( assertEquals("solr.BlobHandler", getObjectByPath(map, true, Arrays.asList(
"solrConfig", "config",
"requestHandler", "requestHandler",
"/blob", "/blob",
"class"))); "class")));

View File

@ -81,7 +81,7 @@ public class TestConfigReload extends AbstractFullDistribZkTestBase {
log.info("live_nodes_count : " + cloudClient.getZkStateReader().getClusterState().getLiveNodes()); log.info("live_nodes_count : " + cloudClient.getZkStateReader().getClusterState().getLiveNodes());
String confPath = ZkController.CONFIGS_ZKNODE+"/conf1/"; String confPath = ZkController.CONFIGS_ZKNODE+"/conf1/";
// checkConfReload(client, confPath + ConfigOverlay.RESOURCE_NAME, "overlay"); // checkConfReload(client, confPath + ConfigOverlay.RESOURCE_NAME, "overlay");
checkConfReload(client, confPath + SolrConfig.DEFAULT_CONF_FILE,"solrConfig", "/config"); checkConfReload(client, confPath + SolrConfig.DEFAULT_CONF_FILE,"config", "/config");
} }