Search in sources :

Example 6 with NIOFSDirectory

use of org.apache.lucene.store.NIOFSDirectory in project exhibitor by soabase.

the class IndexBuilder method open.

public void open() throws Exception {
    if (!directory.exists() && !directory.mkdirs()) {
        throw new IOException("Could not make: " + directory);
    }
    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer()).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    niofsDirectory = new NIOFSDirectory(directory, new SingleInstanceLockFactory());
    writer = new IndexWriter(niofsDirectory, conf);
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.KeywordAnalyzer) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) SingleInstanceLockFactory(org.apache.lucene.store.SingleInstanceLockFactory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 7 with NIOFSDirectory

use of org.apache.lucene.store.NIOFSDirectory in project geode by apache.

the class RawLuceneRepositoryManagerJUnitTest method checkRepository.

@Override
protected void checkRepository(IndexRepositoryImpl repo0, int bucketId) {
    IndexWriter writer0 = repo0.getWriter();
    Directory dir0 = writer0.getDirectory();
    assertTrue(dir0 instanceof NIOFSDirectory);
}
Also used : NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexWriter(org.apache.lucene.index.IndexWriter) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory)

Example 8 with NIOFSDirectory

use of org.apache.lucene.store.NIOFSDirectory in project lucene-solr by apache.

the class TestIndexWriter method testDeleteUnusedFiles.

public void testDeleteUnusedFiles() throws Exception {
    assumeFalse("test relies on exact filenames", Codec.getDefault() instanceof SimpleTextCodec);
    assumeWorkingMMapOnWindows();
    for (int iter = 0; iter < 2; iter++) {
        // relies on windows semantics
        Path path = createTempDir();
        FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
        Path indexPath = new FilterPath(path, fs);
        // NOTE: on Unix, we cannot use MMapDir, because WindowsFS doesn't see/think it keeps file handles open.  Yet, on Windows, we MUST use
        // MMapDir because the windows OS will in fact prevent file deletion for us, and fails otherwise:
        FSDirectory dir;
        if (Constants.WINDOWS) {
            dir = new MMapDirectory(indexPath);
        } else {
            dir = new NIOFSDirectory(indexPath);
        }
        MergePolicy mergePolicy = newLogMergePolicy(true);
        // This test expects all of its segments to be in CFS
        mergePolicy.setNoCFSRatio(1.0);
        mergePolicy.setMaxCFSSegmentSizeMB(Double.POSITIVE_INFINITY);
        IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(mergePolicy).setUseCompoundFile(true));
        Document doc = new Document();
        doc.add(newTextField("field", "go", Field.Store.NO));
        w.addDocument(doc);
        DirectoryReader r;
        if (iter == 0) {
            // use NRT
            r = w.getReader();
        } else {
            // don't use NRT
            w.commit();
            r = DirectoryReader.open(dir);
        }
        assertTrue(Files.exists(indexPath.resolve("_0.cfs")));
        assertTrue(Files.exists(indexPath.resolve("_0.cfe")));
        assertTrue(Files.exists(indexPath.resolve("_0.si")));
        if (iter == 1) {
            // we run a full commit so there should be a segments file etc.
            assertTrue(Files.exists(indexPath.resolve("segments_1")));
        } else {
            // this is an NRT reopen - no segments files yet
            assertFalse(Files.exists(indexPath.resolve("segments_1")));
        }
        w.addDocument(doc);
        w.forceMerge(1);
        if (iter == 1) {
            w.commit();
        }
        IndexReader r2 = DirectoryReader.openIfChanged(r);
        assertNotNull(r2);
        assertTrue(r != r2);
        // NOTE: here we rely on "Windows" behavior, ie, even
        // though IW wanted to delete _0.cfs since it was
        // merged away, because we have a reader open
        // against this file, it should still be here:
        assertTrue(Files.exists(indexPath.resolve("_0.cfs")));
        // forceMerge created this
        //assertTrue(files.contains("_2.cfs"));
        w.deleteUnusedFiles();
        // r still holds this file open
        assertTrue(Files.exists(indexPath.resolve("_0.cfs")));
        //assertTrue(files.contains("_2.cfs"));
        r.close();
        if (iter == 0) {
            // on closing NRT reader, it calls writer.deleteUnusedFiles
            assertFalse(Files.exists(indexPath.resolve("_0.cfs")));
        } else {
            // now FSDir can remove it
            dir.deletePendingFiles();
            assertFalse(Files.exists(indexPath.resolve("_0.cfs")));
        }
        w.close();
        r2.close();
        dir.close();
    }
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) FilterPath(org.apache.lucene.mockfile.FilterPath) SimpleTextCodec(org.apache.lucene.codecs.simpletext.SimpleTextCodec) FSDirectory(org.apache.lucene.store.FSDirectory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) Document(org.apache.lucene.document.Document) MMapDirectory(org.apache.lucene.store.MMapDirectory) WindowsFS(org.apache.lucene.mockfile.WindowsFS) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) FileSystem(java.nio.file.FileSystem)

Aggregations

NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)8 MMapDirectory (org.apache.lucene.store.MMapDirectory)4 IndexWriter (org.apache.lucene.index.IndexWriter)3 Directory (org.apache.lucene.store.Directory)3 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)3 File (java.io.File)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)2 FSDirectory (org.apache.lucene.store.FSDirectory)2 RAMDirectory (org.apache.lucene.store.RAMDirectory)2 SingleInstanceLockFactory (org.apache.lucene.store.SingleInstanceLockFactory)2 FileSystem (java.nio.file.FileSystem)1 RegionDirectory (org.apache.geode.cache.lucene.internal.directory.RegionDirectory)1 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)1 IndexRepositoryImpl (org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 KeywordAnalyzer (org.apache.lucene.analysis.KeywordAnalyzer)1 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)1 SimpleTextCodec (org.apache.lucene.codecs.simpletext.SimpleTextCodec)1