private static Directory injectLockFactory(Directory dir, String lockPath, String rawLockType)
      throws IOException {
    if (null == rawLockType) {
      // we default to "simple" for backwards compatibility
      log.warn("No lockType configured for " + dir + " assuming 'simple'");
      rawLockType = "simple";
    }
    final String lockType = rawLockType.toLowerCase(Locale.ROOT).trim();

    if ("simple".equals(lockType)) {
      // multiple SimpleFSLockFactory instances should be OK
      dir.setLockFactory(new SimpleFSLockFactory(lockPath));
    } else if ("native".equals(lockType)) {
      dir.setLockFactory(new NativeFSLockFactory(lockPath));
    } else if ("single".equals(lockType)) {
      if (!(dir.getLockFactory() instanceof SingleInstanceLockFactory))
        dir.setLockFactory(new SingleInstanceLockFactory());
    } else if ("hdfs".equals(lockType)) {
      Directory del = dir;

      if (dir instanceof NRTCachingDirectory) {
        del = ((NRTCachingDirectory) del).getDelegate();
      }

      if (del instanceof BlockDirectory) {
        del = ((BlockDirectory) del).getDirectory();
      }

      if (!(del instanceof HdfsDirectory)) {
        throw new SolrException(
            ErrorCode.FORBIDDEN,
            "Directory: "
                + del.getClass().getName()
                + ", but hdfs lock factory can only be used with HdfsDirectory");
      }

      dir.setLockFactory(
          new HdfsLockFactory(
              ((HdfsDirectory) del).getHdfsDirPath(), ((HdfsDirectory) del).getConfiguration()));
    } else if ("none".equals(lockType)) {
      // Recipe for disaster
      log.error("CONFIGURATION WARNING: locks are disabled on " + dir);
      dir.setLockFactory(NoLockFactory.getNoLockFactory());
    } else {
      throw new SolrException(
          SolrException.ErrorCode.SERVER_ERROR, "Unrecognized lockType: " + rawLockType);
    }
    return dir;
  }
Esempio n. 2
0
 public FaultyFSDirectory(File dir) {
   fsDir = newFSDirectory(dir);
   lockFactory = fsDir.getLockFactory();
 }
Esempio n. 3
0
 public FaultyFSDirectory(File dir) throws IOException {
   fsDir = newFSDirectory(dir);
   lockFactory = fsDir.getLockFactory();
 }