Java Code Examples for org.apache.lucene.store.LockFactory

The following examples show how to use org.apache.lucene.store.LockFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   Source File: LuceneIndex.java    License: Apache License 2.0 6 votes vote down vote up
private static FSDirectory createFSDirectory (
        final File indexFolder,
        final LockFactory lockFactory) throws IOException {
    assert indexFolder != null;
    assert lockFactory != null;
    final FSDirectory directory;
    final String dirType = System.getProperty(PROP_DIR_TYPE);
    if(DIR_TYPE_MMAP.equals(dirType)) {
        directory = new MMapDirectory(indexFolder, lockFactory);
    } else if (DIR_TYPE_NIO.equals(dirType)) {
        directory = new NIOFSDirectory(indexFolder, lockFactory);
    } else if (DIR_TYPE_IO.equals(dirType)) {
        directory = new SimpleFSDirectory(indexFolder, lockFactory);
    } else {
        directory = FSDirectory.open(indexFolder, lockFactory);
    }
    return directory;
}
 
Example 2
Source Project: lucene-solr   Source File: MockFSDirectoryFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  // we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
  Directory dir = LuceneTestCase.newFSDirectory(new File(path).toPath(), lockFactory);
  // we can't currently do this check because of how
  // Solr has to reboot a new Directory sometimes when replicating
  // or rolling back - the old directory is closed and the following
  // test assumes it can open an IndexWriter when that happens - we
  // have a new Directory for the same dir and still an open IW at 
  // this point
  
  Directory cdir = reduce(dir);
  cdir = reduce(cdir);
  cdir = reduce(cdir);
  
  if (cdir instanceof MockDirectoryWrapper) {
    ((MockDirectoryWrapper)cdir).setAssertNoUnrefencedFilesOnClose(false);
  }
  return dir;
}
 
Example 3
Source Project: lucene-solr   Source File: HdfsDirectoryFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
  if (null == rawLockType) {
    rawLockType = DirectoryFactory.LOCK_TYPE_HDFS;
    log.warn("No lockType configured, assuming '{}'.", rawLockType);
  }
  final String lockType = rawLockType.toLowerCase(Locale.ROOT).trim();
  switch (lockType) {
    case DirectoryFactory.LOCK_TYPE_HDFS:
      return HdfsLockFactory.INSTANCE;
    case DirectoryFactory.LOCK_TYPE_SINGLE:
      return new SingleInstanceLockFactory();
    case DirectoryFactory.LOCK_TYPE_NONE:
      return NoLockFactory.INSTANCE;
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
          "Unrecognized lockType: " + rawLockType);
  }
}
 
Example 4
Source Project: lucene-solr   Source File: StandardDirectoryFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
  if (null == rawLockType) {
    rawLockType = DirectoryFactory.LOCK_TYPE_NATIVE;
    log.warn("No lockType configured, assuming '{}'.", rawLockType);
  }
  final String lockType = rawLockType.toLowerCase(Locale.ROOT).trim();
  switch (lockType) {
    case DirectoryFactory.LOCK_TYPE_SIMPLE:
      return SimpleFSLockFactory.INSTANCE;
    case DirectoryFactory.LOCK_TYPE_NATIVE:
      return NativeFSLockFactory.INSTANCE;
    case DirectoryFactory.LOCK_TYPE_SINGLE:
      return new SingleInstanceLockFactory();
    case DirectoryFactory.LOCK_TYPE_NONE:
      return NoLockFactory.INSTANCE;
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
          "Unrecognized lockType: " + rawLockType);
  }
}
 
Example 5
Source Project: crate   Source File: FsDirectoryService.java    License: Apache License 2.0 6 votes vote down vote up
private static Directory setPreload(Directory directory, Path location, LockFactory lockFactory,
        Set<String> preLoadExtensions) throws IOException {
    if (preLoadExtensions.isEmpty() == false
            && directory instanceof MMapDirectory
            && ((MMapDirectory) directory).getPreload() == false) {
        if (preLoadExtensions.contains("*")) {
            ((MMapDirectory) directory).setPreload(true);
            return directory;
        }
        MMapDirectory primary = new MMapDirectory(location, lockFactory);
        primary.setPreload(true);
        return new FileSwitchDirectory(preLoadExtensions, primary, directory, true) {
            @Override
            public String[] listAll() throws IOException {
                // avoid listing twice
                return primary.listAll();
            }
        };
    }
    return directory;
}
 
Example 6
Source Project: netbeans   Source File: RecordOwnerLockFactory.java    License: Apache License 2.0 5 votes vote down vote up
private static <T extends Exception> T annotateException(
    @NonNull final T e,
    @NullAllowed File indexDir,
    @NullAllowed Map<Thread,StackTraceElement[]> threads,
    @NullAllowed LockFactory lockFactory) {
    final StringBuilder message = new StringBuilder();
    if (indexDir != null) {
        final File[] children = indexDir.listFiles();
        if (children == null) {
            message.append("Non existing index folder");    //NOI18N
        } else {
            for (File c : children) {
                message.append(c.getName()).append(" f: ").append(c.isFile()).
                append(" r: ").append(c.canRead()).
                append(" w: ").append(c.canWrite()).append("\n");  //NOI18N
            }
        }
    }
    if (threads != null) {
        final Thread ct = Thread.currentThread();
        message.append("current thread: ").append(ct).append('(').append(ct.getId()).append(')');    //NOI18N
        message.append("threads: \n");     //NOI18N   //NOI18N
        stackTraces(threads, message);
    }
    if (lockFactory != null) {
        message.append("lockFactory: ").append(lockFactory);    //NOI18N
    }
    return Exceptions.attachMessage(e, message.toString());
}
 
Example 7
Source Project: lucene-solr   Source File: LuceneTestCase.java    License: Apache License 2.0 5 votes vote down vote up
private static Directory newFSDirectoryImpl(Class<? extends FSDirectory> clazz, Path path, LockFactory lf) throws IOException {
  FSDirectory d = null;
  try {
    d = CommandLineUtil.newFSDirectory(clazz, path, lf);
  } catch (ReflectiveOperationException e) {
    Rethrow.rethrow(e);
  }
  return d;
}
 
Example 8
Source Project: lucene-solr   Source File: MockDirectoryFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  Directory dir;
  if (useMockDirectoryWrapper) dir = LuceneTestCase.newMockDirectory();
  else dir = LuceneTestCase.newDirectory(); // we ignore the given lock factory
  
  Directory cdir = reduce(dir);
  cdir = reduce(cdir);
  cdir = reduce(cdir);
  
  if (cdir instanceof MockDirectoryWrapper) {
    MockDirectoryWrapper mockDirWrapper = (MockDirectoryWrapper) cdir;
    
    // we can't currently do this check because of how
    // Solr has to reboot a new Directory sometimes when replicating
    // or rolling back - the old directory is closed and the following
    // test assumes it can open an IndexWriter when that happens - we
    // have a new Directory for the same dir and still an open IW at 
    // this point
    mockDirWrapper.setAssertNoUnrefencedFilesOnClose(false);
    
    // ram dirs in cores that are restarted end up empty
    // and check index fails
    mockDirWrapper.setCheckIndexOnClose(false);
    
    if (allowReadingFilesStillOpenForWrite) {
      mockDirWrapper.setAllowReadingFilesStillOpenForWrite(true);
    }
  }
  
  return dir;
}
 
Example 9
Source Project: lucene-solr   Source File: MMapDirectoryFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  // we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
  MMapDirectory mapDirectory = new MMapDirectory(new File(path).toPath(), lockFactory, maxChunk);
  try {
    mapDirectory.setUseUnmap(unmapHack);
  } catch (IllegalArgumentException e) {
    log.warn("Unmap not supported on this JVM, continuing on without setting unmap", e);
  }
  mapDirectory.setPreload(preload);
  return mapDirectory;
}
 
Example 10
Source Project: lucene-solr   Source File: RAMDirectoryFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
  if (!(rawLockType == null || DirectoryFactory.LOCK_TYPE_SINGLE.equalsIgnoreCase(rawLockType.trim()))) {
    throw new SolrException(ErrorCode.FORBIDDEN,
        "RAMDirectory can only be used with the '" +
            DirectoryFactory.LOCK_TYPE_SINGLE+"' lock factory type.");
  }
  return new SingleInstanceLockFactory();
}
 
Example 11
Source Project: lucene-solr   Source File: ByteBuffersDirectoryFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
  if (!(rawLockType == null || DirectoryFactory.LOCK_TYPE_SINGLE.equalsIgnoreCase(rawLockType.trim()))) {
    throw new SolrException(ErrorCode.FORBIDDEN,
        "ByteBuffersDirectory can only be used with the '"+DirectoryFactory.LOCK_TYPE_SINGLE+"' lock factory type.");
  }
  return new SingleInstanceLockFactory();
}
 
Example 12
@Override
public Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  if (fail) {
    throw new FailingDirectoryFactoryException();
  } else {
    return super.create(path, lockFactory, dirContext);
  }
}
 
Example 13
Source Project: lucene-solr   Source File: AlternateDirectoryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  openCalled = true;

  // we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
  return dir = newFSDirectory(new File(path).toPath(), lockFactory);
}
 
Example 14
private LockFactory getLockFactory(Path indexDir, Properties properties) {
	try {
		return serviceManager.requestService(LockFactoryCreator.class).createLockFactory(indexDir, properties);
	} finally {
		serviceManager.releaseService(LockFactoryCreator.class);
	}
}
 
Example 15
Source Project: crate   Source File: FsDirectoryService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Directory newDirectory() throws IOException {
    final Path location = path.resolveIndex();
    final LockFactory lockFactory = indexSettings.getValue(INDEX_LOCK_FACTOR_SETTING);
    Files.createDirectories(location);
    Directory wrapped = newFSDirectory(location, lockFactory);
    Set<String> preLoadExtensions = new HashSet<>(
            indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING));
    wrapped = setPreload(wrapped, location, lockFactory, preLoadExtensions);
    return wrapped;
}
 
Example 16
Source Project: crate   Source File: FsDirectoryService.java    License: Apache License 2.0 5 votes vote down vote up
protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException {
    final String storeType = indexSettings.getSettings()
        .get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), IndexModule.Type.FS.getSettingsKey());
    IndexModule.Type type;
    if (IndexModule.Type.FS.match(storeType)) {
        type = IndexModule.defaultStoreType(
            IndexModule.NODE_STORE_ALLOW_MMAP.getWithFallback(indexSettings.getNodeSettings()));
    } else {
        type = IndexModule.Type.fromSettingsKey(storeType);
    }
    switch (type) {
        case HYBRIDFS:
            // Use Lucene defaults
            final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
            if (primaryDirectory instanceof MMapDirectory) {
                MMapDirectory mMapDirectory = (MMapDirectory) primaryDirectory;
                return new HybridDirectory(lockFactory, mMapDirectory);
            } else {
                return primaryDirectory;
            }
        case MMAPFS:
            return new MMapDirectory(location, lockFactory);
        case SIMPLEFS:
            return new SimpleFSDirectory(location, lockFactory);
        case NIOFS:
            return new NIOFSDirectory(location, lockFactory);
        default:
            throw new AssertionError("unexpected built-in store type [" + type + "]");
    }
}
 
Example 17
Source Project: linden   Source File: FileSystemDirectory.java    License: Apache License 2.0 4 votes vote down vote up
@Override public LockFactory getLockFactory() {
  return null;
}
 
Example 18
Source Project: lucene-solr   Source File: LuceneTestCase.java    License: Apache License 2.0 4 votes vote down vote up
public static MockDirectoryWrapper newMockDirectory(Random r, LockFactory lf) {
  return (MockDirectoryWrapper) wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY, lf), false, false);
}
 
Example 19
Source Project: lucene-solr   Source File: LuceneTestCase.java    License: Apache License 2.0 4 votes vote down vote up
public static MockDirectoryWrapper newMockFSDirectory(Path f, LockFactory lf) {
  return (MockDirectoryWrapper) newFSDirectory(f, lf, false);
}
 
Example 20
Source Project: lucene-solr   Source File: LuceneTestCase.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns a new FSDirectory instance over the given file, which must be a folder. */
public static BaseDirectoryWrapper newFSDirectory(Path f, LockFactory lf) {
  return newFSDirectory(f, lf, rarely());
}
 
Example 21
Source Project: lucene-solr   Source File: MockDirectoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
  return NoLockFactory.INSTANCE; // dummy, actually unused
}
 
Example 22
Source Project: lucene-solr   Source File: HdfsDirectoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("resource")
protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  assert params != null : "init must be called before create";
  log.info("creating directory factory for path {}", path);
  Configuration conf = getConf(new Path(path));
  
  if (metrics == null) {
    metrics = MetricsHolder.metrics;
  }
  
  boolean blockCacheEnabled = getConfig(BLOCKCACHE_ENABLED, true);
  boolean blockCacheGlobal = getConfig(BLOCKCACHE_GLOBAL, true);
  boolean blockCacheReadEnabled = getConfig(BLOCKCACHE_READ_ENABLED, true);
  
  final HdfsDirectory hdfsDir;

  final Directory dir;
  if (blockCacheEnabled && dirContext != DirContext.META_DATA) {
    int numberOfBlocksPerBank = getConfig(NUMBEROFBLOCKSPERBANK, 16384);
    
    int blockSize = BlockDirectory.BLOCK_SIZE;
    
    int bankCount = getConfig(BLOCKCACHE_SLAB_COUNT, 1);
    
    boolean directAllocation = getConfig(BLOCKCACHE_DIRECT_MEMORY_ALLOCATION, true);
    
    int slabSize = numberOfBlocksPerBank * blockSize;
    log.info(
        "Number of slabs of block cache [{}] with direct memory allocation set to [{}]",
        bankCount, directAllocation);
    if (log.isInfoEnabled()) {
      log.info(
          "Block cache target memory usage, slab size of [{}] will allocate [{}] slabs and use ~[{}] bytes",
          new Object[]{slabSize, bankCount,
              ((long) bankCount * (long) slabSize)});
    }
    
    int bsBufferSize = params.getInt("solr.hdfs.blockcache.bufferstore.buffersize", blockSize);
    int bsBufferCount = params.getInt("solr.hdfs.blockcache.bufferstore.buffercount", 0); // this is actually total size
    
    BlockCache blockCache = getBlockDirectoryCache(numberOfBlocksPerBank,
        blockSize, bankCount, directAllocation, slabSize,
        bsBufferSize, bsBufferCount, blockCacheGlobal);
    
    Cache cache = new BlockDirectoryCache(blockCache, path, metrics, blockCacheGlobal);
    int readBufferSize = params.getInt("solr.hdfs.blockcache.read.buffersize", blockSize);
    hdfsDir = new HdfsDirectory(new Path(path), lockFactory, conf, readBufferSize);
    dir = new BlockDirectory(path, hdfsDir, cache, null, blockCacheReadEnabled, false, cacheMerges, cacheReadOnce);
  } else {
    hdfsDir = new HdfsDirectory(new Path(path), conf);
    dir = hdfsDir;
  }
  if (params.getBool(LOCALITYMETRICS_ENABLED, false)) {
    LocalityHolder.reporter.registerDirectory(hdfsDir);
  }

  boolean nrtCachingDirectory = getConfig(NRTCACHINGDIRECTORY_ENABLE, true);
  if (nrtCachingDirectory) {
    double nrtCacheMaxMergeSizeMB = getConfig(NRTCACHINGDIRECTORY_MAXMERGESIZEMB, 16);
    double nrtCacheMaxCacheMB = getConfig(NRTCACHINGDIRECTORY_MAXCACHEMB, 192);
    
    return new NRTCachingDirectory(dir, nrtCacheMaxMergeSizeMB, nrtCacheMaxCacheMB);
  }
  return dir;
}
 
Example 23
Source Project: lucene-solr   Source File: StandardDirectoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  // we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
  return FSDirectory.open(new File(path).toPath(), lockFactory);
}
 
Example 24
Source Project: lucene-solr   Source File: NIOFSDirectoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  // we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
  return new NIOFSDirectory(new File(path).toPath(), lockFactory);
}
 
Example 25
Source Project: lucene-solr   Source File: NRTCachingDirectoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  // we pass NoLockFactory, because the real lock factory is set later by injectLockFactory:
  return new NRTCachingDirectory(FSDirectory.open(new File(path).toPath(), lockFactory), maxMergeSizeMB, maxCachedMB);
}
 
Example 26
Source Project: lucene-solr   Source File: RAMDirectoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  return new ByteBuffersDirectory(lockFactory);
}
 
Example 27
Source Project: lucene-solr   Source File: ByteBuffersDirectoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
  return new ByteBuffersDirectory(lockFactory);
}
 
Example 28
Source Project: incubator-retired-blur   Source File: FencedDirectory.java    License: Apache License 2.0 4 votes vote down vote up
public void setLockFactory(LockFactory lockFactory) throws IOException {
  _directory.setLockFactory(lockFactory);
}
 
Example 29
Source Project: incubator-retired-blur   Source File: FencedDirectory.java    License: Apache License 2.0 4 votes vote down vote up
public LockFactory getLockFactory() {
  return _directory.getLockFactory();
}
 
Example 30
Source Project: incubator-retired-blur   Source File: BlockDirectory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public LockFactory getLockFactory() {
  return _directory.getLockFactory();
}