/** * Creates a new StorageIO instance for a Solr core, taking into account whether the core is * running in cloud mode as well as initArgs. */ public static StorageIO newStorageIO( String collection, SolrResourceLoader resourceLoader, NamedList<String> initArgs) { StorageIO storageIO = null; SolrZkClient zkClient = null; String zkConfigName = null; if (resourceLoader instanceof ZkSolrResourceLoader) { zkClient = ((ZkSolrResourceLoader) resourceLoader).getZkController().getZkClient(); try { zkConfigName = ((ZkSolrResourceLoader) resourceLoader) .getZkController() .getZkStateReader() .readConfigName(collection); } catch (Exception e) { log.error( "Failed to get config name for collection {} due to: {}", collection, e.toString()); } if (zkConfigName == null) { throw new SolrException( ErrorCode.SERVER_ERROR, "Could not find config name for collection:" + collection); } } if (initArgs.get(STORAGE_IO_CLASS_INIT_ARG) != null) { storageIO = resourceLoader.newInstance(initArgs.get(STORAGE_IO_CLASS_INIT_ARG), StorageIO.class); } else { if (zkClient != null) { String znodeBase = "/configs/" + zkConfigName; log.info( "Setting up ZooKeeper-based storage for the RestManager with znodeBase: " + znodeBase); storageIO = new ManagedResourceStorage.ZooKeeperStorageIO(zkClient, znodeBase); } else { storageIO = new FileStorageIO(); } } if (storageIO instanceof FileStorageIO) { // using local fs, if storageDir is not set in the solrconfig.xml, assume the configDir for // the core if (initArgs.get(STORAGE_DIR_INIT_ARG) == null) { initArgs.add(STORAGE_DIR_INIT_ARG, resourceLoader.getConfigDir()); } } storageIO.configure(resourceLoader, initArgs); return storageIO; }