Search in sources :

Example 1 with SnapshotDirectoryTaxonomyWriter

use of org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter in project lucene-solr by apache.

the class IndexAndTaxonomyRevisionTest method testSegmentsFileLast.

@Test
public void testSegmentsFileLast() throws Exception {
    Directory indexDir = newDirectory();
    IndexWriterConfig conf = new IndexWriterConfig(null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    IndexWriter indexWriter = new IndexWriter(indexDir, conf);
    Directory taxoDir = newDirectory();
    SnapshotDirectoryTaxonomyWriter taxoWriter = new SnapshotDirectoryTaxonomyWriter(taxoDir);
    try {
        indexWriter.addDocument(newDocument(taxoWriter));
        indexWriter.commit();
        taxoWriter.commit();
        Revision rev = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
        Map<String, List<RevisionFile>> sourceFiles = rev.getSourceFiles();
        assertEquals(2, sourceFiles.size());
        for (List<RevisionFile> files : sourceFiles.values()) {
            String lastFile = files.get(files.size() - 1).fileName;
            assertTrue(lastFile.startsWith(IndexFileNames.SEGMENTS));
        }
        indexWriter.close();
    } finally {
        IOUtils.close(indexWriter, taxoWriter, taxoDir, indexDir);
    }
}
Also used : SnapshotDirectoryTaxonomyWriter(org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter) IndexWriter(org.apache.lucene.index.IndexWriter) List(java.util.List) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Test(org.junit.Test)

Example 2 with SnapshotDirectoryTaxonomyWriter

use of org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter in project lucene-solr by apache.

the class IndexAndTaxonomyRevisionTest method testOpen.

@Test
public void testOpen() throws Exception {
    Directory indexDir = newDirectory();
    IndexWriterConfig conf = new IndexWriterConfig(null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    IndexWriter indexWriter = new IndexWriter(indexDir, conf);
    Directory taxoDir = newDirectory();
    SnapshotDirectoryTaxonomyWriter taxoWriter = new SnapshotDirectoryTaxonomyWriter(taxoDir);
    try {
        indexWriter.addDocument(newDocument(taxoWriter));
        indexWriter.commit();
        taxoWriter.commit();
        Revision rev = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
        for (Entry<String, List<RevisionFile>> e : rev.getSourceFiles().entrySet()) {
            String source = e.getKey();
            // silly, both directories are closed in the end
            @SuppressWarnings("resource") Directory dir = source.equals(IndexAndTaxonomyRevision.INDEX_SOURCE) ? indexDir : taxoDir;
            for (RevisionFile file : e.getValue()) {
                IndexInput src = dir.openInput(file.fileName, IOContext.READONCE);
                InputStream in = rev.open(source, file.fileName);
                assertEquals(src.length(), in.available());
                byte[] srcBytes = new byte[(int) src.length()];
                byte[] inBytes = new byte[(int) src.length()];
                int offset = 0;
                if (random().nextBoolean()) {
                    int skip = random().nextInt(10);
                    if (skip >= src.length()) {
                        skip = 0;
                    }
                    in.skip(skip);
                    src.seek(skip);
                    offset = skip;
                }
                src.readBytes(srcBytes, offset, srcBytes.length - offset);
                in.read(inBytes, offset, inBytes.length - offset);
                assertArrayEquals(srcBytes, inBytes);
                IOUtils.close(src, in);
            }
        }
        indexWriter.close();
    } finally {
        IOUtils.close(indexWriter, taxoWriter, taxoDir, indexDir);
    }
}
Also used : InputStream(java.io.InputStream) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) SnapshotDirectoryTaxonomyWriter(org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter) IndexWriter(org.apache.lucene.index.IndexWriter) IndexInput(org.apache.lucene.store.IndexInput) List(java.util.List) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Test(org.junit.Test)

Example 3 with SnapshotDirectoryTaxonomyWriter

use of org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter in project lucene-solr by apache.

the class IndexAndTaxonomyReplicationClientTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    publishIndexDir = newDirectory();
    publishTaxoDir = newDirectory();
    handlerIndexDir = newMockDirectory();
    handlerTaxoDir = newMockDirectory();
    clientWorkDir = createTempDir("replicationClientTest");
    sourceDirFactory = new PerSessionDirectoryFactory(clientWorkDir);
    replicator = new LocalReplicator();
    callback = new IndexAndTaxonomyReadyCallback(handlerIndexDir, handlerTaxoDir);
    handler = new IndexAndTaxonomyReplicationHandler(handlerIndexDir, handlerTaxoDir, callback);
    client = new ReplicationClient(replicator, handler, sourceDirFactory);
    IndexWriterConfig conf = newIndexWriterConfig(null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    publishIndexWriter = new IndexWriter(publishIndexDir, conf);
    publishTaxoWriter = new SnapshotDirectoryTaxonomyWriter(publishTaxoDir);
    config = new FacetsConfig();
    config.setHierarchical("A", true);
}
Also used : SnapshotDirectoryTaxonomyWriter(org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter) FacetsConfig(org.apache.lucene.facet.FacetsConfig) IndexWriter(org.apache.lucene.index.IndexWriter) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 4 with SnapshotDirectoryTaxonomyWriter

use of org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter in project lucene-solr by apache.

the class IndexAndTaxonomyRevisionTest method testRevisionRelease.

@Test
public void testRevisionRelease() throws Exception {
    Directory indexDir = newDirectory();
    IndexWriterConfig conf = new IndexWriterConfig(null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    IndexWriter indexWriter = new IndexWriter(indexDir, conf);
    Directory taxoDir = newDirectory();
    SnapshotDirectoryTaxonomyWriter taxoWriter = new SnapshotDirectoryTaxonomyWriter(taxoDir);
    try {
        indexWriter.addDocument(newDocument(taxoWriter));
        indexWriter.commit();
        taxoWriter.commit();
        Revision rev1 = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
        // releasing that revision should not delete the files
        rev1.release();
        assertTrue(slowFileExists(indexDir, IndexFileNames.SEGMENTS + "_1"));
        assertTrue(slowFileExists(taxoDir, IndexFileNames.SEGMENTS + "_1"));
        // create revision again, so the files are snapshotted
        rev1 = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
        indexWriter.addDocument(newDocument(taxoWriter));
        indexWriter.commit();
        taxoWriter.commit();
        assertNotNull(new IndexAndTaxonomyRevision(indexWriter, taxoWriter));
        // this release should trigger the delete of segments_1
        rev1.release();
        assertFalse(slowFileExists(indexDir, IndexFileNames.SEGMENTS + "_1"));
        indexWriter.close();
    } finally {
        IOUtils.close(indexWriter, taxoWriter, taxoDir, indexDir);
    }
}
Also used : SnapshotDirectoryTaxonomyWriter(org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter) IndexWriter(org.apache.lucene.index.IndexWriter) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Test(org.junit.Test)

Example 5 with SnapshotDirectoryTaxonomyWriter

use of org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter in project lucene-solr by apache.

the class IndexAndTaxonomyRevisionTest method testNoCommit.

@Test
public void testNoCommit() throws Exception {
    Directory indexDir = newDirectory();
    IndexWriterConfig conf = new IndexWriterConfig(null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    IndexWriter indexWriter = new IndexWriter(indexDir, conf);
    Directory taxoDir = newDirectory();
    SnapshotDirectoryTaxonomyWriter taxoWriter = new SnapshotDirectoryTaxonomyWriter(taxoDir);
    // should fail when there are no commits to snapshot
    expectThrows(IllegalStateException.class, () -> {
        new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
    });
    indexWriter.close();
    IOUtils.close(taxoWriter, taxoDir, indexDir);
}
Also used : SnapshotDirectoryTaxonomyWriter(org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter) IndexWriter(org.apache.lucene.index.IndexWriter) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Test(org.junit.Test)

Aggregations

IndexWriter (org.apache.lucene.index.IndexWriter)5 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)5 SnapshotDeletionPolicy (org.apache.lucene.index.SnapshotDeletionPolicy)5 SnapshotDirectoryTaxonomyWriter (org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter)5 Directory (org.apache.lucene.store.Directory)4 Test (org.junit.Test)4 List (java.util.List)2 InputStream (java.io.InputStream)1 FacetsConfig (org.apache.lucene.facet.FacetsConfig)1 IndexInput (org.apache.lucene.store.IndexInput)1 Before (org.junit.Before)1