Example usage for org.apache.lucene.store NoLockFactory INSTANCE

List of usage examples for org.apache.lucene.store NoLockFactory INSTANCE

Introduction

In this page you can find the example usage for org.apache.lucene.store NoLockFactory INSTANCE.

Prototype

NoLockFactory INSTANCE

To view the source code for org.apache.lucene.store NoLockFactory INSTANCE.

Click Source Link

Document

The singleton

Usage

From source file:org.apache.solr.core.backup.repository.HdfsBackupRepository.java

License:Apache License

@Override
public void copyFileFrom(Directory sourceDir, String fileName, URI dest) throws IOException {
    try (HdfsDirectory dir = new HdfsDirectory(new Path(dest), NoLockFactory.INSTANCE, hdfsConfig,
            HdfsDirectory.DEFAULT_BUFFER_SIZE)) {
        dir.copyFrom(sourceDir, fileName, fileName, DirectoryFactory.IOCONTEXT_NO_CACHE);
    }/*w w w  .  j ava 2  s.  c  o m*/
}

From source file:org.apache.solr.core.backup.repository.HdfsBackupRepository.java

License:Apache License

@Override
public void copyFileTo(URI sourceRepo, String fileName, Directory dest) throws IOException {
    try (HdfsDirectory dir = new HdfsDirectory(new Path(sourceRepo), NoLockFactory.INSTANCE, hdfsConfig,
            HdfsDirectory.DEFAULT_BUFFER_SIZE)) {
        dest.copyFrom(dir, fileName, fileName, DirectoryFactory.IOCONTEXT_NO_CACHE);
    }/*from  ww  w. j a v a  2  s  . c  o  m*/
}

From source file:org.apache.solr.core.backup.repository.LocalFileSystemRepository.java

License:Apache License

@Override
public IndexInput openInput(URI dirPath, String fileName, IOContext ctx) throws IOException {
    try (FSDirectory dir = new SimpleFSDirectory(Paths.get(dirPath), NoLockFactory.INSTANCE)) {
        return dir.openInput(fileName, ctx);
    }/* www  .  j  a  v a2  s  .  c o  m*/
}

From source file:org.apache.solr.core.backup.repository.LocalFileSystemRepository.java

License:Apache License

@Override
public String[] listAll(URI dirPath) throws IOException {
    try (FSDirectory dir = new SimpleFSDirectory(Paths.get(dirPath), NoLockFactory.INSTANCE)) {
        return dir.listAll();
    }/*from  w  w w.  j  a v  a2 s  .co  m*/
}

From source file:org.apache.solr.core.backup.repository.LocalFileSystemRepository.java

License:Apache License

@Override
public void copyFileFrom(Directory sourceDir, String fileName, URI dest) throws IOException {
    try (FSDirectory dir = new SimpleFSDirectory(Paths.get(dest), NoLockFactory.INSTANCE)) {
        dir.copyFrom(sourceDir, fileName, fileName, DirectoryFactory.IOCONTEXT_NO_CACHE);
    }//  w ww  .  j a va2 s.  c om
}

From source file:org.apache.solr.core.backup.repository.LocalFileSystemRepository.java

License:Apache License

@Override
public void copyFileTo(URI sourceDir, String fileName, Directory dest) throws IOException {
    try (FSDirectory dir = new SimpleFSDirectory(Paths.get(sourceDir), NoLockFactory.INSTANCE)) {
        dest.copyFrom(dir, fileName, fileName, DirectoryFactory.IOCONTEXT_NO_CACHE);
    }//from   w w w  .j a  va2 s . c o  m
}

From source file:org.apache.solr.core.HdfsDirectoryFactoryTest.java

License:Apache License

@Test
public void testInitArgsOrSysPropConfig() throws Exception {

    HdfsDirectoryFactory hdfsFactory = new HdfsDirectoryFactory();

    // test sys prop config

    System.setProperty("solr.hdfs.home", dfsCluster.getURI().toString() + "/solr1");
    hdfsFactory.init(new NamedList<>());
    String dataHome = hdfsFactory.getDataHome(new MockCoreDescriptor());

    assertTrue(dataHome.endsWith("/solr1/mock/data"));

    System.clearProperty("solr.hdfs.home");

    // test init args config

    NamedList<Object> nl = new NamedList<>();
    nl.add("solr.hdfs.home", dfsCluster.getURI().toString() + "/solr2");
    hdfsFactory.init(nl);//w  ww  . j  a v a  2  s .c  o  m
    dataHome = hdfsFactory.getDataHome(new MockCoreDescriptor());

    assertTrue(dataHome.endsWith("/solr2/mock/data"));

    // test sys prop and init args config - init args wins

    System.setProperty("solr.hdfs.home", dfsCluster.getURI().toString() + "/solr1");
    hdfsFactory.init(nl);
    dataHome = hdfsFactory.getDataHome(new MockCoreDescriptor());

    assertTrue(dataHome.endsWith("/solr2/mock/data"));

    System.clearProperty("solr.hdfs.home");

    // set conf dir by sys prop

    Path confDir = createTempDir();

    System.setProperty(HdfsDirectoryFactory.CONFIG_DIRECTORY, confDir.toString());

    Directory dir = hdfsFactory.create(dfsCluster.getURI().toString() + "/solr", NoLockFactory.INSTANCE,
            DirContext.DEFAULT);
    try {
        assertEquals(confDir.toString(), hdfsFactory.getConfDir());
    } finally {
        dir.close();
    }

    // check bool and int getConf impls
    nl = new NamedList<>();
    nl.add(HdfsDirectoryFactory.NRTCACHINGDIRECTORY_MAXMERGESIZEMB, 4);
    System.setProperty(HdfsDirectoryFactory.NRTCACHINGDIRECTORY_MAXMERGESIZEMB, "3");
    nl.add(HdfsDirectoryFactory.BLOCKCACHE_ENABLED, true);
    System.setProperty(HdfsDirectoryFactory.BLOCKCACHE_ENABLED, "false");

    hdfsFactory.init(nl);

    assertEquals(4, hdfsFactory.getConfig(HdfsDirectoryFactory.NRTCACHINGDIRECTORY_MAXMERGESIZEMB, 0));
    assertEquals(true, hdfsFactory.getConfig(HdfsDirectoryFactory.BLOCKCACHE_ENABLED, false));

    nl = new NamedList<>();
    hdfsFactory.init(nl);
    System.setProperty(HdfsDirectoryFactory.BLOCKCACHE_ENABLED, "true");

    assertEquals(3, hdfsFactory.getConfig(HdfsDirectoryFactory.NRTCACHINGDIRECTORY_MAXMERGESIZEMB, 0));
    assertEquals(true, hdfsFactory.getConfig(HdfsDirectoryFactory.BLOCKCACHE_ENABLED, false));

    System.clearProperty(HdfsDirectoryFactory.NRTCACHINGDIRECTORY_MAXMERGESIZEMB);
    System.clearProperty(HdfsDirectoryFactory.BLOCKCACHE_ENABLED);

    assertEquals(0, hdfsFactory.getConfig(HdfsDirectoryFactory.NRTCACHINGDIRECTORY_MAXMERGESIZEMB, 0));
    assertEquals(false, hdfsFactory.getConfig(HdfsDirectoryFactory.BLOCKCACHE_ENABLED, false));

    hdfsFactory.close();
}

From source file:org.elasticsearch.index.shard.LocalShardSnapshot.java

License:Apache License

Directory getSnapshotDirectory() {
    /* this directory will not be used for anything else but reading / copying files to another directory
     * we prevent all write operations on this directory with UOE - nobody should close it either. */
    return new FilterDirectory(store.directory()) {
        @Override/*from  w w w .j av  a 2s .c om*/
        public String[] listAll() throws IOException {
            Collection<String> fileNames = indexCommit.getFileNames();
            final String[] fileNameArray = fileNames.toArray(new String[fileNames.size()]);
            return fileNameArray;
        }

        @Override
        public void deleteFile(String name) throws IOException {
            throw new UnsupportedOperationException("this directory is read-only");
        }

        @Override
        public void sync(Collection<String> names) throws IOException {
            throw new UnsupportedOperationException("this directory is read-only");
        }

        @Override
        public void rename(String source, String dest) throws IOException {
            throw new UnsupportedOperationException("this directory is read-only");
        }

        @Override
        public IndexOutput createOutput(String name, IOContext context) throws IOException {
            throw new UnsupportedOperationException("this directory is read-only");
        }

        @Override
        public IndexOutput createTempOutput(String prefix, String suffix, IOContext context)
                throws IOException {
            throw new UnsupportedOperationException("this directory is read-only");
        }

        @Override
        public Lock obtainLock(String name) throws IOException {
            /* we do explicitly a no-lock instance since we hold an index commit from a SnapshotDeletionPolicy so we
             * can we certain that nobody messes with the files on disk. We also hold a ref on the store which means
             * no external source will delete files either.*/
            return NoLockFactory.INSTANCE.obtainLock(in, name);
        }

        @Override
        public void close() throws IOException {
            throw new UnsupportedOperationException("nobody should close this directory wrapper");
        }
    };
}

From source file:org.elasticsearch.index.store.IndexStoreTests.java

License:Apache License

public void testStoreDirectory() throws IOException {
    final Path tempDir = createTempDir().resolve("foo").resolve("0");
    final IndexStoreModule.Type[] values = IndexStoreModule.Type.values();
    final IndexStoreModule.Type type = RandomPicks.randomFrom(random(), values);
    Settings settings = Settings.settingsBuilder()
            .put(IndexStoreModule.STORE_TYPE, type.name().toLowerCase(Locale.ROOT)).build();
    FsDirectoryService service = new FsDirectoryService(settings, null,
            new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0)));
    try (final Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) {
        switch (type) {
        case NIOFS:
            assertTrue(type + " " + directory.toString(), directory instanceof NIOFSDirectory);
            break;
        case MMAPFS:
            assertTrue(type + " " + directory.toString(), directory instanceof MMapDirectory);
            break;
        case SIMPLEFS:
            assertTrue(type + " " + directory.toString(), directory instanceof SimpleFSDirectory);
            break;
        case FS:/*w w w. j  ava 2 s. c  om*/
        case DEFAULT:
            if (Constants.WINDOWS) {
                if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) {
                    assertTrue(type + " " + directory.toString(), directory instanceof MMapDirectory);
                } else {
                    assertTrue(type + " " + directory.toString(), directory instanceof SimpleFSDirectory);
                }
            } else if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) {
                assertTrue(type + " " + directory.toString(), directory instanceof FileSwitchDirectory);
            } else {
                assertTrue(type + " " + directory.toString(), directory instanceof NIOFSDirectory);
            }
            break;
        }
    }
}

From source file:org.elasticsearch.index.store.IndexStoreTests.java

License:Apache License

public void testStoreDirectoryDefault() throws IOException {
    final Path tempDir = createTempDir().resolve("foo").resolve("0");
    Settings settings = Settings.EMPTY;/*from  w w w . j  a  va2s. c o  m*/
    FsDirectoryService service = new FsDirectoryService(settings, null,
            new ShardPath(false, tempDir, tempDir, "foo", new ShardId("foo", 0)));
    try (final Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) {
        if (Constants.WINDOWS) {
            assertTrue(directory.toString(),
                    directory instanceof MMapDirectory || directory instanceof SimpleFSDirectory);
        } else if (Constants.JRE_IS_64BIT) {
            assertTrue(directory.toString(), directory instanceof FileSwitchDirectory);
        } else {
            assertTrue(directory.toString(), directory instanceof NIOFSDirectory);
        }
    }
}