mirror of https://github.com/apache/lucene.git
LUCENE-1288: add getVersion, getGeneration to IndexCommit
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@660904 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
df7fb0f45c
commit
d8c8c0e2c0
|
@ -71,6 +71,11 @@ API Changes
|
|||
and remove all references to these classes from the core. Also update demos
|
||||
and tutorials. (Michael Busch)
|
||||
|
||||
10. LUCENE-1288: Add getVersion() and getGeneration() to IndexCommit.
|
||||
getVersion() returns the same value that IndexReader.getVersion()
|
||||
returns when the reader is opened on the same commit. (Jason
|
||||
Rutherglen via Mike McCandless)
|
||||
|
||||
Bug fixes
|
||||
|
||||
1. LUCENE-1134: Fixed BooleanQuery.rewrite to only optimize a single
|
||||
|
|
|
@ -343,6 +343,8 @@ abstract class DirectoryIndexReader extends IndexReader {
|
|||
private String segmentsFileName;
|
||||
Collection files;
|
||||
Directory dir;
|
||||
long generation;
|
||||
long version;
|
||||
|
||||
ReaderCommit(SegmentInfos infos, Directory dir) throws IOException {
|
||||
segmentsFileName = infos.getCurrentSegmentFileName();
|
||||
|
@ -355,6 +357,8 @@ abstract class DirectoryIndexReader extends IndexReader {
|
|||
if (info.dir == dir)
|
||||
files.addAll(info.files());
|
||||
}
|
||||
version = infos.getVersion();
|
||||
generation = infos.getGeneration();
|
||||
}
|
||||
public String getSegmentsFileName() {
|
||||
return segmentsFileName;
|
||||
|
@ -365,6 +369,12 @@ abstract class DirectoryIndexReader extends IndexReader {
|
|||
public Directory getDirectory() {
|
||||
return dir;
|
||||
}
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
public long getGeneration() {
|
||||
return generation;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -89,4 +89,17 @@ public abstract class IndexCommit implements IndexCommitPoint {
|
|||
public int hashCode() {
|
||||
return getDirectory().hashCode() + getSegmentsFileName().hashCode();
|
||||
}
|
||||
|
||||
/** Returns the version for this IndexCommit. This is the
|
||||
same value that {@link IndexReader#getVersion} would
|
||||
return if it were opened on this commit. */
|
||||
public long getVersion() {
|
||||
throw new UnsupportedOperationException("This IndexCommit does not support this method.");
|
||||
}
|
||||
|
||||
/** Returns the generation (the _N in segments_N) for this
|
||||
IndexCommit */
|
||||
public long getGeneration() {
|
||||
throw new UnsupportedOperationException("This IndexCommit does not support this method.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -577,11 +577,15 @@ final class IndexFileDeleter {
|
|||
boolean deleted;
|
||||
Directory directory;
|
||||
Collection commitsToDelete;
|
||||
long version;
|
||||
long generation;
|
||||
|
||||
public CommitPoint(Collection commitsToDelete, Directory directory, SegmentInfos segmentInfos) throws IOException {
|
||||
this.directory = directory;
|
||||
this.commitsToDelete = commitsToDelete;
|
||||
segmentsFileName = segmentInfos.getCurrentSegmentFileName();
|
||||
version = segmentInfos.getVersion();
|
||||
generation = segmentInfos.getGeneration();
|
||||
int size = segmentInfos.size();
|
||||
files = new ArrayList(size);
|
||||
files.add(segmentsFileName);
|
||||
|
@ -606,6 +610,14 @@ final class IndexFileDeleter {
|
|||
return directory;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public long getGeneration() {
|
||||
return generation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called only be the deletion policy, to remove this
|
||||
* commit point from the index.
|
||||
|
|
|
@ -109,6 +109,12 @@ public class SnapshotDeletionPolicy implements IndexDeletionPolicy {
|
|||
cp.delete();
|
||||
}
|
||||
}
|
||||
public long getVersion() {
|
||||
return cp.getVersion();
|
||||
}
|
||||
public long getGeneration() {
|
||||
return cp.getGeneration();
|
||||
}
|
||||
}
|
||||
|
||||
private List wrapCommits(List commits) {
|
||||
|
|
|
@ -42,10 +42,17 @@ import org.apache.lucene.util.LuceneTestCase;
|
|||
public class TestDeletionPolicy extends LuceneTestCase
|
||||
{
|
||||
private void verifyCommitOrder(List commits) {
|
||||
long last = SegmentInfos.generationFromSegmentsFileName(((IndexCommit) commits.get(0)).getSegmentsFileName());
|
||||
final IndexCommit firstCommit = ((IndexCommit) commits.get(0));
|
||||
long last = SegmentInfos.generationFromSegmentsFileName(firstCommit.getSegmentsFileName());
|
||||
assertEquals(last, firstCommit.getGeneration());
|
||||
long lastVersion = firstCommit.getVersion();
|
||||
for(int i=1;i<commits.size();i++) {
|
||||
long now = SegmentInfos.generationFromSegmentsFileName(((IndexCommit) commits.get(i)).getSegmentsFileName());
|
||||
final IndexCommit commit = ((IndexCommit) commits.get(i));
|
||||
long now = SegmentInfos.generationFromSegmentsFileName(commit.getSegmentsFileName());
|
||||
long nowVersion = commit.getVersion();
|
||||
assertTrue("SegmentInfos commits are out-of-order", now > last);
|
||||
assertTrue("SegmentInfos versions are out-of-order", nowVersion > lastVersion);
|
||||
assertEquals(now, commit.getGeneration());
|
||||
last = now;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue