You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2008/05/28 13:00:33 UTC
svn commit: r660904 - in /lucene/java/trunk: ./
src/java/org/apache/lucene/index/ src/test/org/apache/lucene/index/
Author: mikemccand
Date: Wed May 28 04:00:33 2008
New Revision: 660904
URL: http://svn.apache.org/viewvc?rev=660904&view=rev
Log:
LUCENE-1288: add getVersion, getGeneration to IndexCommit
Modified:
lucene/java/trunk/CHANGES.txt
lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java
lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java
lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java
Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=660904&r1=660903&r2=660904&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Wed May 28 04:00:33 2008
@@ -71,6 +71,11 @@
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
Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java?rev=660904&r1=660903&r2=660904&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java Wed May 28 04:00:33 2008
@@ -343,6 +343,8 @@
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 @@
if (info.dir == dir)
files.addAll(info.files());
}
+ version = infos.getVersion();
+ generation = infos.getGeneration();
}
public String getSegmentsFileName() {
return segmentsFileName;
@@ -365,6 +369,12 @@
public Directory getDirectory() {
return dir;
}
+ public long getVersion() {
+ return version;
+ }
+ public long getGeneration() {
+ return generation;
+ }
}
/**
Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java?rev=660904&r1=660903&r2=660904&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java Wed May 28 04:00:33 2008
@@ -89,4 +89,17 @@
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.");
+ }
}
Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java?rev=660904&r1=660903&r2=660904&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java Wed May 28 04:00:33 2008
@@ -577,11 +577,15 @@
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 @@
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.
Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java?rev=660904&r1=660903&r2=660904&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java Wed May 28 04:00:33 2008
@@ -109,6 +109,12 @@
cp.delete();
}
}
+ public long getVersion() {
+ return cp.getVersion();
+ }
+ public long getGeneration() {
+ return cp.getGeneration();
+ }
}
private List wrapCommits(List commits) {
Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java?rev=660904&r1=660903&r2=660904&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java Wed May 28 04:00:33 2008
@@ -42,10 +42,17 @@
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;
}
}