Java Code Examples for org.apache.lucene.index.IndexWriterConfig.OpenMode#APPEND
The following examples show how to use
org.apache.lucene.index.IndexWriterConfig.OpenMode#APPEND .
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 File: PersistentSnapshotDeletionPolicy.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * {@link PersistentSnapshotDeletionPolicy} wraps another * {@link IndexDeletionPolicy} to enable flexible snapshotting. * * @param primary * the {@link IndexDeletionPolicy} that is used on non-snapshotted * commits. Snapshotted commits, by definition, are not deleted until * explicitly released via {@link #release}. * @param dir * the {@link Directory} which will be used to persist the snapshots * information. * @param mode * specifies whether a new index should be created, deleting all * existing snapshots information (immediately), or open an existing * index, initializing the class with the snapshots information. */ public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, OpenMode mode) throws IOException { super(primary); this.dir = dir; if (mode == OpenMode.CREATE) { clearPriorSnapshots(); } loadPriorSnapshots(); if (mode == OpenMode.APPEND && nextWriteGen == 0) { throw new IllegalStateException("no snapshots stored in this directory"); } }
Example 2
Source File: TestPersistentSnapshotDeletionPolicy.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testSnapshotRelease() throws Exception { Directory dir = newDirectory(); IndexWriter writer = new IndexWriter(dir, getConfig(random(), getDeletionPolicy(dir))); PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy(); prepareIndexAndSnapshots(psdp, writer, 1); writer.close(); psdp.release(snapshots.get(0)); psdp = new PersistentSnapshotDeletionPolicy( new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND); assertEquals("Should have no snapshots !", 0, psdp.getSnapshotCount()); dir.close(); }
Example 3
Source File: TestPersistentSnapshotDeletionPolicy.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testSnapshotReleaseByGeneration() throws Exception { Directory dir = newDirectory(); IndexWriter writer = new IndexWriter(dir, getConfig(random(), getDeletionPolicy(dir))); PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy(); prepareIndexAndSnapshots(psdp, writer, 1); writer.close(); psdp.release(snapshots.get(0).getGeneration()); psdp = new PersistentSnapshotDeletionPolicy( new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND); assertEquals("Should have no snapshots !", 0, psdp.getSnapshotCount()); dir.close(); }
Example 4
Source File: SolrSnapshotMetaDataManager.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * A constructor. * * @param dir The directory where the snapshot meta-data is stored. * @param mode CREATE If previous meta-data should be erased. * APPEND If previous meta-data should be read and updated. * CREATE_OR_APPEND Creates a new meta-data structure if one does not exist * Updates the existing structure if one exists. * @throws IOException in case of errors. */ public SolrSnapshotMetaDataManager(SolrCore solrCore, Directory dir, OpenMode mode) throws IOException { this.solrCore = solrCore; this.dir = dir; if (mode == OpenMode.CREATE) { deleteSnapshotMetadataFiles(); } loadFromSnapshotMetadataFile(); if (mode == OpenMode.APPEND && nextWriteGen == 0) { throw new IllegalStateException("no snapshots stored in this directory"); } }
Example 5
Source File: TestPersistentSnapshotDeletionPolicy.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testExistingSnapshots() throws Exception { int numSnapshots = 3; MockDirectoryWrapper dir = newMockDirectory(); IndexWriter writer = new IndexWriter(dir, getConfig(random(), getDeletionPolicy(dir))); PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy(); assertNull(psdp.getLastSaveFile()); prepareIndexAndSnapshots(psdp, writer, numSnapshots); assertNotNull(psdp.getLastSaveFile()); writer.close(); // Make sure only 1 save file exists: int count = 0; for(String file : dir.listAll()) { if (file.startsWith(PersistentSnapshotDeletionPolicy.SNAPSHOTS_PREFIX)) { count++; } } assertEquals(1, count); // Make sure we fsync: dir.crash(); dir.clearCrash(); // Re-initialize and verify snapshots were persisted psdp = new PersistentSnapshotDeletionPolicy( new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND); writer = new IndexWriter(dir, getConfig(random(), psdp)); psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy(); assertEquals(numSnapshots, psdp.getSnapshots().size()); assertEquals(numSnapshots, psdp.getSnapshotCount()); assertSnapshotExists(dir, psdp, numSnapshots, false); writer.addDocument(new Document()); writer.commit(); snapshots.add(psdp.snapshot()); assertEquals(numSnapshots+1, psdp.getSnapshots().size()); assertEquals(numSnapshots+1, psdp.getSnapshotCount()); assertSnapshotExists(dir, psdp, numSnapshots+1, false); writer.close(); dir.close(); }