use of org.apache.lucene.index.IndexCommit in project lucene-solr by apache.
the class SolrSnapshotManager method deleteNonSnapshotIndexFiles.
/**
* This method deletes index files not associated with the specified <code>snapshots</code>.
*
* @param core The Solr core
* @param dir The index directory storing the snapshot.
* @param snapshots The snapshots to be preserved.
* @throws IOException in case of I/O errors.
*/
public static void deleteNonSnapshotIndexFiles(SolrCore core, Directory dir, Collection<SnapshotMetaData> snapshots) throws IOException {
final Set<Long> genNumbers = new HashSet<>();
for (SnapshotMetaData m : snapshots) {
genNumbers.add(m.getGenerationNumber());
}
deleteSnapshotIndexFiles(core, dir, new IndexDeletionPolicy() {
@Override
public void onInit(List<? extends IndexCommit> commits) throws IOException {
for (IndexCommit ic : commits) {
if (!genNumbers.contains(ic.getGeneration())) {
log.info("Deleting non-snapshotted index commit with generation {}", ic.getGeneration());
ic.delete();
}
}
}
@Override
public void onCommit(List<? extends IndexCommit> commits) throws IOException {
}
});
}
use of org.apache.lucene.index.IndexCommit in project lucene-solr by apache.
the class SolrSnapshotMetaDataManager method getIndexCommitByName.
/**
* This method returns the {@linkplain IndexCommit} associated with the specified
* <code>commitName</code>. A snapshot with specified <code>commitName</code> must
* be created before invoking this method.
*
* @param commitName The name of persisted commit
* @return the {@linkplain IndexCommit}
* @throws IOException in case of I/O error.
*/
public Optional<IndexCommit> getIndexCommitByName(String commitName) throws IOException {
Optional<IndexCommit> result = Optional.empty();
Optional<SnapshotMetaData> metaData = getSnapshotMetaData(commitName);
if (metaData.isPresent()) {
String indexDirPath = metaData.get().getIndexDirPath();
long gen = metaData.get().getGenerationNumber();
Directory d = solrCore.getDirectoryFactory().get(indexDirPath, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_NONE);
try {
result = DirectoryReader.listCommits(d).stream().filter(ic -> ic.getGeneration() == gen).findAny();
if (!result.isPresent()) {
log.warn("Unable to find commit with generation {} in the directory {}", gen, indexDirPath);
}
} finally {
solrCore.getDirectoryFactory().release(d);
}
} else {
log.warn("Commit with name {} is not persisted for core {}", commitName, solrCore.getName());
}
return result;
}
use of org.apache.lucene.index.IndexCommit in project lucene-solr by apache.
the class LukeRequestHandler method getIndexInfo.
// This method just gets the top-most level of information. This was conflated with getting detailed info
// for *all* the fields, called from CoreAdminHandler etc.
public static SimpleOrderedMap<Object> getIndexInfo(DirectoryReader reader) throws IOException {
Directory dir = reader.directory();
SimpleOrderedMap<Object> indexInfo = new SimpleOrderedMap<>();
indexInfo.add("numDocs", reader.numDocs());
indexInfo.add("maxDoc", reader.maxDoc());
indexInfo.add("deletedDocs", reader.maxDoc() - reader.numDocs());
indexInfo.add("indexHeapUsageBytes", getIndexHeapUsed(reader));
// TODO? Is this different then: IndexReader.getCurrentVersion( dir )?
indexInfo.add("version", reader.getVersion());
indexInfo.add("segmentCount", reader.leaves().size());
indexInfo.add("current", closeSafe(reader::isCurrent));
indexInfo.add("hasDeletions", reader.hasDeletions());
indexInfo.add("directory", dir);
IndexCommit indexCommit = reader.getIndexCommit();
String segmentsFileName = indexCommit.getSegmentsFileName();
indexInfo.add("segmentsFile", segmentsFileName);
indexInfo.add("segmentsFileSizeInBytes", getFileLength(indexCommit.getDirectory(), segmentsFileName));
Map<String, String> userData = indexCommit.getUserData();
indexInfo.add("userData", userData);
String s = userData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
if (s != null) {
indexInfo.add("lastModified", new Date(Long.parseLong(s)));
}
return indexInfo;
}
use of org.apache.lucene.index.IndexCommit in project lucene-solr by apache.
the class OpenIndexTask method doLogic.
@Override
public int doLogic() throws IOException {
PerfRunData runData = getRunData();
Config config = runData.getConfig();
final IndexCommit ic;
if (commitUserData != null) {
ic = OpenReaderTask.findIndexCommit(runData.getDirectory(), commitUserData);
} else {
ic = null;
}
final IndexWriter writer = CreateIndexTask.configureWriter(config, runData, OpenMode.APPEND, ic);
runData.setIndexWriter(writer);
return 1;
}
use of org.apache.lucene.index.IndexCommit in project lucene-solr by apache.
the class OpenReaderTask method findIndexCommit.
public static IndexCommit findIndexCommit(Directory dir, String userData) throws IOException {
Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
for (final IndexCommit ic : commits) {
Map<String, String> map = ic.getUserData();
String ud = null;
if (map != null) {
ud = map.get(USER_DATA);
}
if (ud != null && ud.equals(userData)) {
return ic;
}
}
throw new IOException("index does not contain commit with userData: " + userData);
}
Aggregations