(boolean passOnPreviousState, boolean reload)
| 869 | private static boolean isWriterLocked(Directory directory) throws IOException { |
| 870 | try { |
| 871 | directory.obtainLock(IndexWriter.WRITE_LOCK_NAME).close(); |
| 872 | return false; |
| 873 | } catch (LockObtainFailedException failed) { |
| 874 | return true; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | void initIndex(boolean passOnPreviousState, boolean reload) throws IOException { |
| 879 | String indexDir = getNewIndexDir(); |
| 880 | boolean indexExists = getDirectoryFactory().exists(indexDir); |
| 881 | boolean firstTime; |
| 882 | synchronized (SolrCore.class) { |
| 883 | firstTime = dirs.add(getDirectoryFactory().normalize(indexDir)); |
| 884 | } |
| 885 | |
| 886 | initIndexReaderFactory(); |
| 887 | |
| 888 | if (indexExists && firstTime && !passOnPreviousState) { |
| 889 | final String lockType = getSolrConfig().indexConfig.lockType; |
| 890 | Directory dir = directoryFactory.get(indexDir, DirContext.DEFAULT, lockType); |
| 891 | try { |
| 892 | if (isWriterLocked(dir)) { |
| 893 | log.error( |
| 894 | "Solr index directory '{}' is locked (lockType={}). Throwing exception.", |
| 895 | indexDir, |
| 896 | lockType); |
| 897 | throw new LockObtainFailedException( |
| 898 | "Index dir '" |
| 899 | + indexDir |
| 900 | + "' of core '" |
| 901 | + name |
| 902 | + "' is already locked. " |
| 903 | + "The most likely cause is another Solr server (or another solr core in this server) " |
| 904 | + "also configured to use this directory; other possible causes may be specific to lockType: " |
| 905 | + lockType); |
| 906 | } |
| 907 | } finally { |
| 908 | directoryFactory.release(dir); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | // Create the index if it doesn't exist. |
| 913 | if (!indexExists) { |
| 914 | log.debug("Solr index directory '{}' doesn't exist. Creating new index...", indexDir); |
| 915 | SolrIndexWriter writer = null; |
| 916 | try { |
| 917 | writer = |
| 918 | SolrIndexWriter.create( |
| 919 | this, |
| 920 | "SolrCore.initIndex", |
| 921 | indexDir, |
| 922 | getDirectoryFactory(), |
| 923 | true, |
| 924 | getLatestSchema(), |
| 925 | solrConfig.indexConfig, |
| 926 | solrDelPolicy, |
| 927 | codec); |
| 928 | } finally { |
no test coverage detected