Java Code Examples for org.apache.lucene.index.IndexCommit#getFileNames()
The following examples show how to use
org.apache.lucene.index.IndexCommit#getFileNames() .
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: FastHdfsKeyValueDirectoryTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
private void assertFiles(Set<String> expected, int run, int commit, FastHdfsKeyValueDirectory directory) throws IOException { Set<String> actual; if (DirectoryReader.indexExists(directory)) { List<IndexCommit> listCommits = DirectoryReader.listCommits(directory); // assertEquals(1, listCommits.size()); IndexCommit indexCommit = listCommits.get(0); actual = new TreeSet<String>(indexCommit.getFileNames()); } else { actual = new TreeSet<String>(); } Set<String> missing = new TreeSet<String>(expected); missing.removeAll(actual); Set<String> extra = new TreeSet<String>(actual); extra.removeAll(expected); assertEquals("Pass [" + run + "] Missing Files " + " Extra Files " + extra + "", expected, actual); }
Example 2
Source File: SnapshotIndexCommit.java From Elasticsearch with Apache License 2.0 | 5 votes |
SnapshotIndexCommit(SnapshotDeletionPolicy deletionPolicy, IndexCommit cp) throws IOException { super(cp); this.deletionPolicy = deletionPolicy; ArrayList<String> tmpFiles = new ArrayList<>(); for (String o : cp.getFileNames()) { tmpFiles.add(o); } files = tmpFiles.toArray(new String[tmpFiles.size()]); }
Example 3
Source File: IndexReplicationHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Cleans up the index directory from old index files. This method uses the * last commit found by {@link #getLastCommit(Directory)}. If it matches the * expected segmentsFile, then all files not referenced by this commit point * are deleted. * <p> * <b>NOTE:</b> this method does a best effort attempt to clean the index * directory. It suppresses any exceptions that occur, as this can be retried * the next time. */ public static void cleanupOldIndexFiles(Directory dir, String segmentsFile, InfoStream infoStream) { try { IndexCommit commit = getLastCommit(dir); // commit == null means weird IO errors occurred, ignore them // if there were any IO errors reading the expected commit point (i.e. // segments files mismatch), then ignore that commit either. if (commit != null && commit.getSegmentsFileName().equals(segmentsFile)) { Set<String> commitFiles = new HashSet<>(commit.getFileNames()); Matcher matcher = IndexFileNames.CODEC_FILE_PATTERN.matcher(""); for (String file : dir.listAll()) { if (!commitFiles.contains(file) && (matcher.reset(file).matches() || file.startsWith(IndexFileNames.SEGMENTS))) { // suppress exceptions, it's just a best effort IOUtils.deleteFilesIgnoringExceptions(dir, file); } } } } catch (Throwable t) { // ignore any errors that happen during this state and only log it. this // cleanup will have a chance to succeed the next time we get a new // revision. if (infoStream.isEnabled(INFO_STREAM_COMPONENT)) { infoStream.message(INFO_STREAM_COMPONENT, "cleanupOldIndexFiles(): failed on error " + t.getMessage()); } } }