@Override public String getDataHome(CoreDescriptor cd) throws IOException { if (hdfsDataDir == null) { throw new SolrException( ErrorCode.SERVER_ERROR, "You must set the " + this.getClass().getSimpleName() + " param " + HDFS_HOME + " for relative dataDir paths to work"); } // by default, we go off the instance directory String path; if (cd.getCloudDescriptor() != null) { path = URLEncoder.encode(cd.getCloudDescriptor().getCollectionName(), "UTF-8") + "/" + URLEncoder.encode(cd.getCloudDescriptor().getCoreNodeName(), "UTF-8"); } else { path = cd.getName(); } return normalize( SolrResourceLoader.normalizeDir( ZkController.trimLeadingAndTrailingSlashes(hdfsDataDir) + "/" + path + "/" + cd.getDataDir())); }
/** * Creates a new core in a specified instance directory, publishing the core state to the cluster * * @param coreName the core name * @param instancePath the instance directory * @param parameters the core parameters * @return the newly created core */ public SolrCore create(String coreName, Path instancePath, Map<String, String> parameters) { CoreDescriptor cd = new CoreDescriptor(this, coreName, instancePath, parameters); // TODO: There's a race here, isn't there? if (getAllCoreNames().contains(coreName)) { log.warn("Creating a core with existing name is not allowed"); // TODO: Shouldn't this be a BAD_REQUEST? throw new SolrException( ErrorCode.SERVER_ERROR, "Core with name '" + coreName + "' already exists."); } boolean preExisitingZkEntry = false; try { if (getZkController() != null) { if (!Overseer.isLegacy(getZkController().getZkStateReader())) { if (cd.getCloudDescriptor().getCoreNodeName() == null) { throw new SolrException( ErrorCode.SERVER_ERROR, "non legacy mode coreNodeName missing " + parameters.toString()); } } preExisitingZkEntry = getZkController().checkIfCoreNodeNameAlreadyExists(cd); } SolrCore core = create(cd, true); // only write out the descriptor if the core is successfully created coresLocator.create(this, cd); return core; } catch (Exception ex) { if (isZooKeeperAware() && !preExisitingZkEntry) { try { getZkController().unregister(coreName, cd); } catch (InterruptedException e) { Thread.currentThread().interrupt(); SolrException.log(log, null, e); } catch (KeeperException e) { SolrException.log(log, null, e); } } Throwable tc = ex; Throwable c = null; do { tc = tc.getCause(); if (tc != null) { c = tc; } } while (tc != null); String rootMsg = ""; if (c != null) { rootMsg = " Caused by: " + c.getMessage(); } throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Error CREATEing SolrCore '" + coreName + "': " + ex.getMessage() + rootMsg, ex); } }