use of org.apache.lucene.index.IndexCommit in project lucene-solr by apache.
the class SnapShooter method createSnapshot.
public NamedList createSnapshot() throws Exception {
RefCounted<SolrIndexSearcher> searcher = solrCore.getSearcher();
try {
if (commitName != null) {
SolrSnapshotMetaDataManager snapshotMgr = solrCore.getSnapshotMetaDataManager();
Optional<IndexCommit> commit = snapshotMgr.getIndexCommitByName(commitName);
if (commit.isPresent()) {
return createSnapshot(commit.get());
}
throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to find an index commit with name " + commitName + " for core " + solrCore.getName());
} else {
//TODO should we try solrCore.getDeletionPolicy().getLatestCommit() first?
IndexDeletionPolicyWrapper deletionPolicy = solrCore.getDeletionPolicy();
IndexCommit indexCommit = searcher.get().getIndexReader().getIndexCommit();
deletionPolicy.saveCommitPoint(indexCommit.getGeneration());
try {
return createSnapshot(indexCommit);
} finally {
deletionPolicy.releaseCommitPoint(indexCommit.getGeneration());
}
}
} finally {
searcher.decref();
}
}
use of org.apache.lucene.index.IndexCommit in project neo4j-mobile-android by neo4j-contrib.
the class LuceneDataSource method listStoreFiles.
@Override
public ClosableIterable<File> listStoreFiles(boolean includeLogicalLogs) throws IOException {
// Never include logical logs since they are of little importance
final Collection<File> files = new ArrayList<File>();
final Collection<SnapshotDeletionPolicy> snapshots = new ArrayList<SnapshotDeletionPolicy>();
makeSureAllIndexesAreInstantiated();
for (Map.Entry<IndexIdentifier, Pair<IndexWriter, AtomicBoolean>> writer : indexWriters.entrySet()) {
SnapshotDeletionPolicy deletionPolicy = (SnapshotDeletionPolicy) writer.getValue().first().getConfig().getIndexDeletionPolicy();
File indexDirectory = getFileDirectory(baseStorePath, writer.getKey());
try {
// Throws IllegalStateException if no commits yet
IndexCommit commit = deletionPolicy.snapshot(SNAPSHOT_ID);
for (String fileName : commit.getFileNames()) {
files.add(new File(indexDirectory, fileName));
}
snapshots.add(deletionPolicy);
} catch (IllegalStateException e) {
// TODO Review this
/*
* This is insane but happens if we try to snapshot an existing index
* that has no commits. This is a bad API design - it should return null
* or something. This is not exceptional.
*/
}
}
files.add(providerStore.getFile());
return new ClosableIterable<File>() {
public Iterator<File> iterator() {
return files.iterator();
}
public void close() {
for (SnapshotDeletionPolicy deletionPolicy : snapshots) {
try {
deletionPolicy.release(SNAPSHOT_ID);
} catch (IOException e) {
// TODO What to do?
e.printStackTrace();
}
}
}
};
}
use of org.apache.lucene.index.IndexCommit in project jackrabbit by apache.
the class IndexDeletionPolicyImpl method checkCommits.
// -------------------------------< internal >-------------------------------
private void checkCommits(List<? extends IndexCommit> commits) throws IOException {
long currentTime = System.currentTimeMillis();
for (int i = 0; i < commits.size() - 1; i++) {
IndexCommit ic = commits.get(i);
long lastModified = index.getDirectory().fileModified(ic.getSegmentsFileName());
if (currentTime - lastModified > maxAge) {
ic.delete();
} else {
// following commits are younger, no need to check
break;
}
}
}
use of org.apache.lucene.index.IndexCommit in project jackrabbit by apache.
the class IndexDeletionPolicyImpl method onCommit.
public void onCommit(List<? extends IndexCommit> commits) throws IOException {
checkCommits(commits);
// report back current generation
IndexCommit current = commits.get(commits.size() - 1);
String name = current.getSegmentsFileName();
if (name.equals(SEGMENTS)) {
index.setCurrentGeneration(0);
} else {
index.setCurrentGeneration(Long.parseLong(name.substring(SEGMENTS.length() + 1), Character.MAX_RADIX));
}
}
use of org.apache.lucene.index.IndexCommit in project OpenGrok by OpenGrok.
the class SuggesterProjectData method getCommitVersion.
private long getCommitVersion() throws IOException {
List<IndexCommit> commits = DirectoryReader.listCommits(indexDir);
if (commits.size() > 1) {
throw new IllegalStateException("IndexDeletionPolicy changed, normally only one commit should be stored");
}
IndexCommit commit = commits.get(0);
return commit.getGeneration();
}
Aggregations