Methods Summary |
---|
public void | checkpoint(org.apache.lucene.index.SegmentInfos segmentInfos, boolean isCommit)For definition of "check point" see IndexWriter comments:
"Clarification: Check Points (and commits)".
Writer calls this when it has made a "consistent
change" to the index, meaning new files are written to
the index and the in-memory SegmentInfos have been
modified to point to those files.
This may or may not be a commit (segments_N may or may
not have been written).
We simply incref the files referenced by the new
SegmentInfos and decref the files we had previously
seen (if any).
If this is a commit, we also call the policy to give it
a chance to remove other commits. If any commits are
removed, we decref their files as well.
if (infoStream != null) {
message("now checkpoint \"" + segmentInfos.getCurrentSegmentFileName() + "\" [isCommit = " + isCommit + "]");
}
// Try again now to delete any previously un-deletable
// files (because they were in use, on Windows):
if (deletable != null) {
List oldDeletable = deletable;
deletable = null;
int size = oldDeletable.size();
for(int i=0;i<size;i++) {
deleteFile((String) oldDeletable.get(i));
}
}
// Incref the files:
incRef(segmentInfos, isCommit);
if (isCommit) {
// Append to our commits list:
commits.add(new CommitPoint(segmentInfos));
// Tell policy so it can remove commits:
policy.onCommit(commits);
// Decref files for commits that were deleted by the policy:
deleteCommits();
}
// DecRef old files from the last checkpoint, if any:
int size = lastFiles.size();
if (size > 0) {
for(int i=0;i<size;i++) {
decRef((List) lastFiles.get(i));
}
lastFiles.clear();
}
if (!isCommit) {
// Save files so we can decr on next checkpoint/commit:
size = segmentInfos.size();
for(int i=0;i<size;i++) {
SegmentInfo segmentInfo = segmentInfos.info(i);
if (segmentInfo.dir == directory) {
lastFiles.add(segmentInfo.files());
}
}
}
|
private void | decRef(java.lang.String fileName)
RefCount rc = getRefCount(fileName);
if (infoStream != null) {
message(" DecRef \"" + fileName + "\": pre-decr count is " + rc.count);
}
if (0 == rc.DecRef()) {
// This file is no longer referenced by any past
// commit points nor by the in-memory SegmentInfos:
deleteFile(fileName);
refCounts.remove(fileName);
}
|
void | decRef(org.apache.lucene.index.SegmentInfos segmentInfos)
final int size = segmentInfos.size();
for(int i=0;i<size;i++) {
SegmentInfo segmentInfo = segmentInfos.info(i);
if (segmentInfo.dir == directory) {
decRef(segmentInfo.files());
}
}
|
private void | decRef(java.util.List files)
int size = files.size();
for(int i=0;i<size;i++) {
decRef((String) files.get(i));
}
|
private void | deleteCommits()Remove the CommitPoints in the commitsToDelete List by
DecRef'ing all files from each SegmentInfos.
int size = commitsToDelete.size();
if (size > 0) {
// First decref all files that had been referred to by
// the now-deleted commits:
for(int i=0;i<size;i++) {
CommitPoint commit = (CommitPoint) commitsToDelete.get(i);
if (infoStream != null) {
message("deleteCommits: now remove commit \"" + commit.getSegmentsFileName() + "\"");
}
int size2 = commit.files.size();
for(int j=0;j<size2;j++) {
decRef((List) commit.files.get(j));
}
decRef(commit.getSegmentsFileName());
}
commitsToDelete.clear();
// Now compact commits to remove deleted ones (preserving the sort):
size = commits.size();
int readFrom = 0;
int writeTo = 0;
while(readFrom < size) {
CommitPoint commit = (CommitPoint) commits.get(readFrom);
if (!commit.deleted) {
if (writeTo != readFrom) {
commits.set(writeTo, commits.get(readFrom));
}
writeTo++;
}
readFrom++;
}
while(size > writeTo) {
commits.remove(size-1);
size--;
}
}
|
public void | deleteDirect(org.apache.lucene.store.Directory otherDir, java.util.List segments)Blindly delete the files used by the specific segments,
with no reference counting and no retry. This is only
currently used by writer to delete its RAM segments
from a RAMDirectory.
int size = segments.size();
for(int i=0;i<size;i++) {
List filestoDelete = ((SegmentInfo) segments.get(i)).files();
int size2 = filestoDelete.size();
for(int j=0;j<size2;j++) {
otherDir.deleteFile((String) filestoDelete.get(j));
}
}
|
private void | deleteFile(java.lang.String fileName)
try {
if (infoStream != null) {
message("delete \"" + fileName + "\"");
}
directory.deleteFile(fileName);
} catch (IOException e) { // if delete fails
if (directory.fileExists(fileName)) {
// Some operating systems (e.g. Windows) don't
// permit a file to be deleted while it is opened
// for read (e.g. by another process or thread). So
// we assume that when a delete fails it is because
// the file is open in another process, and queue
// the file for subsequent deletion.
if (infoStream != null) {
message("IndexFileDeleter: unable to remove file \"" + fileName + "\": " + e.toString() + "; Will re-try later.");
}
if (deletable == null) {
deletable = new ArrayList();
}
deletable.add(fileName); // add to deletable
}
}
|
private org.apache.lucene.index.IndexFileDeleter$RefCount | getRefCount(java.lang.String fileName)
RefCount rc;
if (!refCounts.containsKey(fileName)) {
rc = new RefCount();
refCounts.put(fileName, rc);
} else {
rc = (RefCount) refCounts.get(fileName);
}
return rc;
|
void | incRef(org.apache.lucene.index.SegmentInfos segmentInfos, boolean isCommit)
int size = segmentInfos.size();
for(int i=0;i<size;i++) {
SegmentInfo segmentInfo = segmentInfos.info(i);
if (segmentInfo.dir == directory) {
incRef(segmentInfo.files());
}
}
if (isCommit) {
// Since this is a commit point, also incref its
// segments_N file:
getRefCount(segmentInfos.getCurrentSegmentFileName()).IncRef();
}
|
private void | incRef(java.util.List files)
int size = files.size();
for(int i=0;i<size;i++) {
String fileName = (String) files.get(i);
RefCount rc = getRefCount(fileName);
if (infoStream != null) {
message(" IncRef \"" + fileName + "\": pre-incr count is " + rc.count);
}
rc.IncRef();
}
|
private void | message(java.lang.String message)
infoStream.println(this + " " + Thread.currentThread().getName() + ": " + message);
|
public void | refresh()Writer calls this when it has hit an error and had to
roll back, to tell us that there may now be
unreferenced files in the filesystem. So we re-list
the filesystem and delete such files:
String[] files = directory.list();
if (files == null)
throw new IOException("cannot read directory " + directory + ": list() returned null");
IndexFileNameFilter filter = IndexFileNameFilter.getFilter();
for(int i=0;i<files.length;i++) {
String fileName = files[i];
if (filter.accept(null, fileName) && !refCounts.containsKey(fileName) && !fileName.equals(IndexFileNames.SEGMENTS_GEN)) {
// Unreferenced file, so remove it
if (infoStream != null) {
message("refresh: removing newly created unreferenced file \"" + fileName + "\"");
}
deleteFile(fileName);
}
}
|
void | setInfoStream(java.io.PrintStream infoStream)
this.infoStream = infoStream;
|