Search in sources :

Example 16 with SnapshotDeletionPolicy

use of org.apache.lucene.index.SnapshotDeletionPolicy 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 17 with SnapshotDeletionPolicy

use of org.apache.lucene.index.SnapshotDeletionPolicy 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 18 with SnapshotDeletionPolicy

use of org.apache.lucene.index.SnapshotDeletionPolicy in project lucene-solr by apache.

the class HttpReplicatorTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    if (VERBOSE) {
        // sets stderr logging to DEBUG level
        System.setProperty("org.eclipse.jetty.LEVEL", "DEBUG");
    }
    clientWorkDir = createTempDir("httpReplicatorTest");
    handlerIndexDir = newDirectory();
    serverIndexDir = newDirectory();
    serverReplicator = new LocalReplicator();
    startServer();
    IndexWriterConfig conf = newIndexWriterConfig(null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    writer = new IndexWriter(serverIndexDir, conf);
    reader = DirectoryReader.open(writer);
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) LocalReplicator(org.apache.lucene.replicator.LocalReplicator) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 19 with SnapshotDeletionPolicy

use of org.apache.lucene.index.SnapshotDeletionPolicy in project lucene-solr by apache.

the class IndexRevisionTest method testSegmentsFileLast.

@Test
public void testSegmentsFileLast() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = new IndexWriterConfig(null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    IndexWriter writer = new IndexWriter(dir, conf);
    try {
        writer.addDocument(new Document());
        writer.commit();
        Revision rev = new IndexRevision(writer);
        @SuppressWarnings("unchecked") Map<String, List<RevisionFile>> sourceFiles = rev.getSourceFiles();
        assertEquals(1, sourceFiles.size());
        List<RevisionFile> files = sourceFiles.values().iterator().next();
        String lastFile = files.get(files.size() - 1).fileName;
        assertTrue(lastFile.startsWith(IndexFileNames.SEGMENTS));
        writer.close();
    } finally {
        IOUtils.close(dir);
    }
}
Also used : Document(org.apache.lucene.document.Document) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) IndexWriter(org.apache.lucene.index.IndexWriter) List(java.util.List) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Test(org.junit.Test)

Example 20 with SnapshotDeletionPolicy

use of org.apache.lucene.index.SnapshotDeletionPolicy in project lucene-solr by apache.

the class LocalReplicatorTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    sourceDir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(null);
    conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
    sourceWriter = new IndexWriter(sourceDir, conf);
    replicator = new LocalReplicator();
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Aggregations

SnapshotDeletionPolicy (org.apache.lucene.index.SnapshotDeletionPolicy)22 IndexWriter (org.apache.lucene.index.IndexWriter)17 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)16 Directory (org.apache.lucene.store.Directory)12 Test (org.junit.Test)9 IOException (java.io.IOException)7 Document (org.apache.lucene.document.Document)6 ArrayList (java.util.ArrayList)5 SnapshotDirectoryTaxonomyWriter (org.apache.lucene.replicator.IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter)5 Before (org.junit.Before)5 List (java.util.List)4 IndexCommit (org.apache.lucene.index.IndexCommit)4 File (java.io.File)3 HashMap (java.util.HashMap)3 KeepOnlyLastCommitDeletionPolicy (org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy)3 InputStream (java.io.InputStream)2 Map (java.util.Map)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 TextField (org.apache.lucene.document.TextField)2