diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index daea07f6dd7..81ba363025d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -748,6 +748,10 @@ Changes in backwards compatibility policy
* LUCENE-3712: Removed unused and untested ReaderUtil#subReader methods.
(Uwe Schindler)
+
+* LUCENE-3672: Deprecate Directory.fileModified and
+ IndexCommit.getTimestamp and .getVersion. (Andrzej Bialecki, Robert
+ Muir, Mike McCandless)
Security fixes
diff --git a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
index a39e9039dd0..3a733532a0f 100644
--- a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
+++ b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
@@ -425,7 +425,6 @@ final class DirectoryReader extends BaseMultiReader {
Collection files;
Directory dir;
long generation;
- long version;
final Map userData;
private final int segmentCount;
@@ -434,7 +433,6 @@ final class DirectoryReader extends BaseMultiReader {
this.dir = dir;
userData = infos.getUserData();
files = Collections.unmodifiableCollection(infos.files(dir, true));
- version = infos.getVersion();
generation = infos.getGeneration();
segmentCount = infos.size();
}
@@ -464,11 +462,6 @@ final class DirectoryReader extends BaseMultiReader {
return dir;
}
- @Override
- public long getVersion() {
- return version;
- }
-
@Override
public long getGeneration() {
return generation;
diff --git a/lucene/src/java/org/apache/lucene/index/IndexCommit.java b/lucene/src/java/org/apache/lucene/index/IndexCommit.java
index 79de850390b..752abb24cdc 100644
--- a/lucene/src/java/org/apache/lucene/index/IndexCommit.java
+++ b/lucene/src/java/org/apache/lucene/index/IndexCommit.java
@@ -83,39 +83,31 @@ public abstract class IndexCommit implements Comparable {
public boolean equals(Object other) {
if (other instanceof IndexCommit) {
IndexCommit otherCommit = (IndexCommit) other;
- return otherCommit.getDirectory().equals(getDirectory()) && otherCommit.getVersion() == getVersion();
- } else
+ return otherCommit.getDirectory().equals(getDirectory()) && otherCommit.getGeneration() == getGeneration();
+ } else {
return false;
+ }
}
@Override
public int hashCode() {
- return (int) (getDirectory().hashCode() + getVersion());
+ return getDirectory().hashCode() + Long.valueOf(getGeneration()).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 abstract long getVersion();
-
/** Returns the generation (the _N in segments_N) for this
* IndexCommit */
public abstract long getGeneration();
- /** Convenience method that returns the last modified time
- * of the segments_N file corresponding to this index
- * commit, equivalent to
- * getDirectory().fileModified(getSegmentsFileName()). */
- public long getTimestamp() throws IOException {
- return getDirectory().fileModified(getSegmentsFileName());
- }
-
/** Returns userData, previously passed to {@link
* IndexWriter#commit(Map)} for this commit. Map is
* String -> String. */
public abstract Map getUserData() throws IOException;
public int compareTo(IndexCommit commit) {
+ if (getDirectory() != commit.getDirectory()) {
+ throw new UnsupportedOperationException("cannot compare IndexCommits from different Directory instances");
+ }
+
long gen = getGeneration();
long comgen = commit.getGeneration();
if (gen < comgen) {
@@ -126,5 +118,4 @@ public abstract class IndexCommit implements Comparable {
return 0;
}
}
-
}
diff --git a/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java b/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java
index 05069de2d8f..ef8c2ae1678 100644
--- a/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java
+++ b/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java
@@ -655,7 +655,6 @@ final class IndexFileDeleter {
boolean deleted;
Directory directory;
Collection commitsToDelete;
- long version;
long generation;
final Map userData;
private final int segmentCount;
@@ -665,7 +664,6 @@ final class IndexFileDeleter {
this.commitsToDelete = commitsToDelete;
userData = segmentInfos.getUserData();
segmentsFileName = segmentInfos.getCurrentSegmentFileName();
- version = segmentInfos.getVersion();
generation = segmentInfos.getGeneration();
files = Collections.unmodifiableCollection(segmentInfos.files(directory, true));
segmentCount = segmentInfos.size();
@@ -696,11 +694,6 @@ final class IndexFileDeleter {
return directory;
}
- @Override
- public long getVersion() {
- return version;
- }
-
@Override
public long getGeneration() {
return generation;
diff --git a/lucene/src/java/org/apache/lucene/index/IndexReader.java b/lucene/src/java/org/apache/lucene/index/IndexReader.java
index ae4037d22b2..5e83092cd9f 100644
--- a/lucene/src/java/org/apache/lucene/index/IndexReader.java
+++ b/lucene/src/java/org/apache/lucene/index/IndexReader.java
@@ -468,36 +468,6 @@ public abstract class IndexReader implements Closeable {
throw new UnsupportedOperationException("This reader does not support this method.");
}
- /**
- * Returns the time the index in the named directory was last modified.
- * Do not use this to check whether the reader is still up-to-date, use
- * {@link #isCurrent()} instead.
- * @throws CorruptIndexException if the index is corrupt
- * @throws IOException if there is a low-level IO error
- */
- public static long lastModified(final Directory directory2) throws CorruptIndexException, IOException {
- return ((Long) new SegmentInfos.FindSegmentsFile(directory2) {
- @Override
- public Object doBody(String segmentFileName) throws IOException {
- return Long.valueOf(directory2.fileModified(segmentFileName));
- }
- }.run()).longValue();
- }
-
- /**
- * Reads version number from segments files. The version number is
- * initialized with a timestamp and then increased by one for each change of
- * the index.
- *
- * @param directory where the index resides.
- * @return version number.
- * @throws CorruptIndexException if the index is corrupt
- * @throws IOException if there is a low-level IO error
- */
- public static long getCurrentVersion(Directory directory) throws CorruptIndexException, IOException {
- return SegmentInfos.readCurrentVersion(directory);
- }
-
/**
* Reads commitUserData, previously passed to {@link
* IndexWriter#commit(Map)}, from current index
@@ -525,18 +495,7 @@ public abstract class IndexReader implements Closeable {
* a reader based on a Directory), then this method
* returns the version recorded in the commit that the
* reader opened. This version is advanced every time
- * {@link IndexWriter#commit} is called.
- *
- *
If instead this reader is a near real-time reader
- * (ie, obtained by a call to {@link
- * IndexWriter#getReader}, or by calling {@link #openIfChanged}
- * on a near real-time reader), then this method returns
- * the version of the last commit done by the writer.
- * Note that even as further changes are made with the
- * writer, the version will not changed until a commit is
- * completed. Thus, you should not rely on this method to
- * determine when a near real-time reader should be
- * opened. Use {@link #isCurrent} instead.
+ * a change is made with {@link IndexWriter}.
*
* @throws UnsupportedOperationException unless overridden in subclass
*/
diff --git a/lucene/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/src/java/org/apache/lucene/index/SegmentInfos.java
index 4855f5d6e68..9b7b70c12b4 100644
--- a/lucene/src/java/org/apache/lucene/index/SegmentInfos.java
+++ b/lucene/src/java/org/apache/lucene/index/SegmentInfos.java
@@ -94,16 +94,15 @@ public final class SegmentInfos implements Cloneable, Iterable {
* Whenever you add a new format, make it 1 smaller (negative version logic)! */
public static final int FORMAT_SEGMENTS_GEN_CURRENT = -2;
- public int counter = 0; // used to name new segments
+ public int counter; // used to name new segments
/**
- * counts how often the index has been changed by adding or deleting docs.
- * starting with the current time in milliseconds forces to create unique version numbers.
+ * counts how often the index has been changed
*/
- public long version = System.currentTimeMillis();
+ public long version;
- private long generation = 0; // generation of the "segments_N" for the next commit
- private long lastGeneration = 0; // generation of the "segments_N" file we last successfully read
+ private long generation; // generation of the "segments_N" for the next commit
+ private long lastGeneration; // generation of the "segments_N" file we last successfully read
// or wrote; this is normally the same as generation except if
// there was an IOException that had interrupted a commit
diff --git a/lucene/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java b/lucene/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
index 23137ba3bc3..1bf50cc90b6 100644
--- a/lucene/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
+++ b/lucene/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
@@ -125,11 +125,6 @@ public class SnapshotDeletionPolicy implements IndexDeletionPolicy {
return cp.getUserData();
}
- @Override
- public long getVersion() {
- return cp.getVersion();
- }
-
@Override
public boolean isDeleted() {
return cp.isDeleted();
diff --git a/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java b/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
index c0304b58bb6..260c2fa38bc 100644
--- a/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
+++ b/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
@@ -249,14 +249,6 @@ public final class CompoundFileDirectory extends Directory {
return entries.containsKey(IndexFileNames.stripSegmentName(name));
}
-
- /** Returns the time the compound file was last modified. */
- @Override
- public long fileModified(String name) throws IOException {
- ensureOpen();
- return directory.fileModified(fileName);
- }
-
/** Not implemented
* @throws UnsupportedOperationException */
@Override
diff --git a/lucene/src/java/org/apache/lucene/store/Directory.java b/lucene/src/java/org/apache/lucene/store/Directory.java
index 8dd98264709..350b0044335 100644
--- a/lucene/src/java/org/apache/lucene/store/Directory.java
+++ b/lucene/src/java/org/apache/lucene/store/Directory.java
@@ -62,10 +62,6 @@ public abstract class Directory implements Closeable {
public abstract boolean fileExists(String name)
throws IOException;
- /** Returns the time the named file was last modified. */
- public abstract long fileModified(String name)
- throws IOException;
-
/** Removes an existing file in the directory. */
public abstract void deleteFile(String name)
throws IOException;
diff --git a/lucene/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/src/java/org/apache/lucene/store/FSDirectory.java
index 5bd5e7e2291..c9944263a54 100644
--- a/lucene/src/java/org/apache/lucene/store/FSDirectory.java
+++ b/lucene/src/java/org/apache/lucene/store/FSDirectory.java
@@ -250,14 +250,6 @@ public abstract class FSDirectory extends Directory {
return file.exists();
}
- /** Returns the time the named file was last modified. */
- @Override
- public long fileModified(String name) {
- ensureOpen();
- File file = new File(directory, name);
- return file.lastModified();
- }
-
/** Returns the time the named file was last modified. */
public static long fileModified(File directory, String name) {
File file = new File(directory, name);
diff --git a/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java b/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java
index 2abf48c28af..201d0ce2ff9 100644
--- a/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java
+++ b/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java
@@ -137,11 +137,6 @@ public class FileSwitchDirectory extends Directory {
return getDirectory(name).fileExists(name);
}
- @Override
- public long fileModified(String name) throws IOException {
- return getDirectory(name).fileModified(name);
- }
-
@Override
public void deleteFile(String name) throws IOException {
getDirectory(name).deleteFile(name);
diff --git a/lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java b/lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java
index cfc1e0b1d15..337c0f84fdd 100644
--- a/lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java
+++ b/lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java
@@ -152,15 +152,6 @@ public class NRTCachingDirectory extends Directory {
return cache.fileExists(name) || delegate.fileExists(name);
}
- @Override
- public synchronized long fileModified(String name) throws IOException {
- if (cache.fileExists(name)) {
- return cache.fileModified(name);
- } else {
- return delegate.fileModified(name);
- }
- }
-
@Override
public synchronized void deleteFile(String name) throws IOException {
if (VERBOSE) {
diff --git a/lucene/src/java/org/apache/lucene/store/RAMDirectory.java b/lucene/src/java/org/apache/lucene/store/RAMDirectory.java
index 81b815ea763..2c9ddc5b5ec 100644
--- a/lucene/src/java/org/apache/lucene/store/RAMDirectory.java
+++ b/lucene/src/java/org/apache/lucene/store/RAMDirectory.java
@@ -98,19 +98,6 @@ public class RAMDirectory extends Directory {
return fileMap.containsKey(name);
}
- /** Returns the time the named file was last modified.
- * @throws IOException if the file does not exist
- */
- @Override
- public final long fileModified(String name) throws IOException {
- ensureOpen();
- RAMFile file = fileMap.get(name);
- if (file == null) {
- throw new FileNotFoundException(name);
- }
- return file.getLastModified();
- }
-
/** Returns the length in bytes of a file in the directory.
* @throws IOException if the file does not exist
*/
diff --git a/lucene/src/java/org/apache/lucene/store/RAMFile.java b/lucene/src/java/org/apache/lucene/store/RAMFile.java
index bd946cd7843..88f6c83d64f 100644
--- a/lucene/src/java/org/apache/lucene/store/RAMFile.java
+++ b/lucene/src/java/org/apache/lucene/store/RAMFile.java
@@ -26,8 +26,6 @@ public class RAMFile {
RAMDirectory directory;
protected long sizeInBytes;
- private long lastModified = System.currentTimeMillis();
-
// File used as buffer, in no RAMDirectory
public RAMFile() {}
@@ -44,15 +42,6 @@ public class RAMFile {
this.length = length;
}
- // For non-stream access from thread that might be concurrent with writing
- public synchronized long getLastModified() {
- return lastModified;
- }
-
- protected synchronized void setLastModified(long lastModified) {
- this.lastModified = lastModified;
- }
-
protected final byte[] addBuffer(int size) {
byte[] buffer = newBuffer(size);
synchronized(this) {
diff --git a/lucene/src/java/org/apache/lucene/store/RAMOutputStream.java b/lucene/src/java/org/apache/lucene/store/RAMOutputStream.java
index 62a3848c408..66a44b61f9d 100644
--- a/lucene/src/java/org/apache/lucene/store/RAMOutputStream.java
+++ b/lucene/src/java/org/apache/lucene/store/RAMOutputStream.java
@@ -167,7 +167,6 @@ public class RAMOutputStream extends IndexOutput {
@Override
public void flush() throws IOException {
- file.setLastModified(System.currentTimeMillis());
setFileLength();
}
diff --git a/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java
index 205ef5b4a95..cff2f9640ec 100644
--- a/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java
+++ b/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java
@@ -702,12 +702,6 @@ public class MockDirectoryWrapper extends Directory {
return delegate.fileExists(name);
}
- @Override
- public synchronized long fileModified(String name) throws IOException {
- maybeYield();
- return delegate.fileModified(name);
- }
-
@Override
public synchronized long fileLength(String name) throws IOException {
maybeYield();
diff --git a/lucene/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java b/lucene/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
index 396ebc75a6f..c95f446dcb6 100644
--- a/lucene/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
+++ b/lucene/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
@@ -224,14 +224,6 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase {
return realDirectory.fileLength(name);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public long fileModified(String name) throws IOException {
- return realDirectory.fileModified(name);
- }
-
/**
* {@inheritDoc}
*/
diff --git a/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java b/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java
index 76e150322d5..a936f36c296 100644
--- a/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java
+++ b/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java
@@ -18,10 +18,12 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
-import java.util.Collection;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@@ -32,7 +34,6 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
@@ -47,20 +48,12 @@ public class TestDeletionPolicy extends LuceneTestCase {
final IndexCommit firstCommit = commits.get(0);
long last = SegmentInfos.generationFromSegmentsFileName(firstCommit.getSegmentsFileName());
assertEquals(last, firstCommit.getGeneration());
- long lastVersion = firstCommit.getVersion();
- long lastTimestamp = firstCommit.getTimestamp();
for(int i=1;i last);
- assertTrue("SegmentInfos versions are out-of-order", nowVersion > lastVersion);
- assertTrue("SegmentInfos timestamps are out-of-order: now=" + nowTimestamp + " vs last=" + lastTimestamp, nowTimestamp >= lastTimestamp);
assertEquals(now, commit.getGeneration());
last = now;
- lastVersion = nowVersion;
- lastTimestamp = nowTimestamp;
}
}
@@ -158,6 +151,10 @@ public class TestDeletionPolicy extends LuceneTestCase {
}
}
+ static long getCommitTime(IndexCommit commit) throws IOException {
+ return Long.parseLong(commit.getUserData().get("commitTime"));
+ }
+
/*
* Delete a commit only when it has been obsoleted by N
* seconds.
@@ -184,10 +181,10 @@ public class TestDeletionPolicy extends LuceneTestCase {
IndexCommit lastCommit = commits.get(commits.size()-1);
// Any commit older than expireTime should be deleted:
- double expireTime = dir.fileModified(lastCommit.getSegmentsFileName())/1000.0 - expirationTimeSeconds;
+ double expireTime = getCommitTime(lastCommit)/1000.0 - expirationTimeSeconds;
for (final IndexCommit commit : commits) {
- double modTime = dir.fileModified(commit.getSegmentsFileName())/1000.0;
+ double modTime = getCommitTime(commit)/1000.0;
if (commit != lastCommit && modTime < expireTime) {
commit.delete();
numDelete += 1;
@@ -213,6 +210,9 @@ public class TestDeletionPolicy extends LuceneTestCase {
((LogMergePolicy) mp).setUseCompoundFile(true);
}
IndexWriter writer = new IndexWriter(dir, conf);
+ Map commitData = new HashMap();
+ commitData.put("commitTime", String.valueOf(System.currentTimeMillis()));
+ writer.commit(commitData);
writer.close();
final int ITER = 9;
@@ -233,6 +233,9 @@ public class TestDeletionPolicy extends LuceneTestCase {
for(int j=0;j<17;j++) {
addDoc(writer);
}
+ commitData = new HashMap();
+ commitData.put("commitTime", String.valueOf(System.currentTimeMillis()));
+ writer.commit(commitData);
writer.close();
if (i < ITER-1) {
@@ -269,7 +272,9 @@ public class TestDeletionPolicy extends LuceneTestCase {
// if we are on a filesystem that seems to have only
// 1 second resolution, allow +1 second in commit
// age tolerance:
- long modTime = dir.fileModified(fileName);
+ SegmentInfos sis = new SegmentInfos();
+ sis.read(dir, fileName);
+ long modTime = Long.parseLong(sis.getUserData().get("commitTime"));
oneSecondResolution &= (modTime % 1000) == 0;
final long leeway = (long) ((SECONDS + (oneSecondResolution ? 1.0:0.0))*1000);
diff --git a/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java b/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java
index 3bb525f53d9..3430c0399f5 100644
--- a/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java
+++ b/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java
@@ -126,10 +126,6 @@ public class TestFieldsReader extends LuceneTestCase {
return fsDir.fileExists(name);
}
@Override
- public long fileModified(String name) throws IOException {
- return fsDir.fileModified(name);
- }
- @Override
public void deleteFile(String name) throws IOException {
fsDir.deleteFile(name);
}
diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexCommit.java b/lucene/src/test/org/apache/lucene/index/TestIndexCommit.java
index d56d62d1bd2..a877b71f22b 100644
--- a/lucene/src/test/org/apache/lucene/index/TestIndexCommit.java
+++ b/lucene/src/test/org/apache/lucene/index/TestIndexCommit.java
@@ -34,12 +34,10 @@ public class TestIndexCommit extends LuceneTestCase {
IndexCommit ic1 = new IndexCommit() {
@Override public String getSegmentsFileName() { return "a"; }
- @Override public long getVersion() { return 12; }
@Override public Directory getDirectory() { return dir; }
@Override public Collection getFileNames() throws IOException { return null; }
@Override public void delete() {}
@Override public long getGeneration() { return 0; }
- @Override public long getTimestamp() throws IOException { return 1;}
@Override public Map getUserData() throws IOException { return null; }
@Override public boolean isDeleted() { return false; }
@Override public int getSegmentCount() { return 2; }
@@ -47,12 +45,10 @@ public class TestIndexCommit extends LuceneTestCase {
IndexCommit ic2 = new IndexCommit() {
@Override public String getSegmentsFileName() { return "b"; }
- @Override public long getVersion() { return 12; }
@Override public Directory getDirectory() { return dir; }
@Override public Collection getFileNames() throws IOException { return null; }
@Override public void delete() {}
@Override public long getGeneration() { return 0; }
- @Override public long getTimestamp() throws IOException { return 1;}
@Override public Map getUserData() throws IOException { return null; }
@Override public boolean isDeleted() { return false; }
@Override public int getSegmentCount() { return 2; }
diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReader.java b/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
index 7ce6e7dd769..2082b790dcb 100644
--- a/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
+++ b/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
@@ -381,60 +381,6 @@ public class TestIndexReader extends LuceneTestCase {
_TestUtil.rmDir(dirFile);
}
- public void testLastModified() throws Exception {
- for(int i=0;i<2;i++) {
- final Directory dir = newDirectory();
- assertFalse(IndexReader.indexExists(dir));
- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE));
- addDocumentWithFields(writer);
- assertTrue(IndexWriter.isLocked(dir)); // writer open, so dir is locked
- writer.close();
- assertTrue(IndexReader.indexExists(dir));
- IndexReader reader = IndexReader.open(dir);
- assertFalse(IndexWriter.isLocked(dir)); // reader only, no lock
- long version = IndexReader.lastModified(dir);
- if (i == 1) {
- long version2 = IndexReader.lastModified(dir);
- assertEquals(version, version2);
- }
- reader.close();
- // modify index and check version has been
- // incremented:
- Thread.sleep(1000);
-
- writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE));
- addDocumentWithFields(writer);
- writer.close();
- reader = IndexReader.open(dir);
- assertTrue("old lastModified is " + version + "; new lastModified is " + IndexReader.lastModified(dir), version <= IndexReader.lastModified(dir));
- reader.close();
- dir.close();
- }
- }
-
- public void testVersion() throws IOException {
- Directory dir = newDirectory();
- assertFalse(IndexReader.indexExists(dir));
- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
- addDocumentWithFields(writer);
- assertTrue(IndexWriter.isLocked(dir)); // writer open, so dir is locked
- writer.close();
- assertTrue(IndexReader.indexExists(dir));
- IndexReader reader = IndexReader.open(dir);
- assertFalse(IndexWriter.isLocked(dir)); // reader only, no lock
- long version = IndexReader.getCurrentVersion(dir);
- reader.close();
- // modify index and check version has been
- // incremented:
- writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE));
- addDocumentWithFields(writer);
- writer.close();
- reader = IndexReader.open(dir);
- assertTrue("old version is " + version + "; new version is " + IndexReader.getCurrentVersion(dir), version < IndexReader.getCurrentVersion(dir));
- reader.close();
- dir.close();
- }
-
public void testOpenReaderAfterDelete() throws IOException {
File dirFile = _TestUtil.getTempDir("deletetest");
Directory dir = newFSDirectory(dirFile);
diff --git a/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java b/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
index 2622e9332e9..7b9ba7e3fd2 100755
--- a/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
+++ b/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
@@ -348,12 +348,6 @@ public class TestBufferedIndexInput extends LuceneTestCase {
dir.deleteFile(name);
}
@Override
- public long fileModified(String name)
- throws IOException
- {
- return dir.fileModified(name);
- }
- @Override
public boolean fileExists(String name)
throws IOException
{
diff --git a/solr/core/src/java/org/apache/solr/core/IndexDeletionPolicyWrapper.java b/solr/core/src/java/org/apache/solr/core/IndexDeletionPolicyWrapper.java
index d11129277d4..6b33e9cf672 100644
--- a/solr/core/src/java/org/apache/solr/core/IndexDeletionPolicyWrapper.java
+++ b/solr/core/src/java/org/apache/solr/core/IndexDeletionPolicyWrapper.java
@@ -19,6 +19,7 @@ package org.apache.solr.core;
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.index.IndexDeletionPolicy;
import org.apache.lucene.store.Directory;
+import org.apache.solr.update.SolrIndexWriter;
import java.io.IOException;
import java.util.*;
@@ -65,13 +66,13 @@ public class IndexDeletionPolicyWrapper implements IndexDeletionPolicy {
/**
* Set the duration for which commit point is to be reserved by the deletion policy.
*
- * @param indexVersion version of the commit point to be reserved
+ * @param indexGen gen of the commit point to be reserved
* @param reserveTime time in milliseconds for which the commit point is to be reserved
*/
- public void setReserveDuration(Long indexVersion, long reserveTime) {
+ public void setReserveDuration(Long indexGen, long reserveTime) {
long timeToSet = System.currentTimeMillis() + reserveTime;
for(;;) {
- Long previousTime = reserves.put(indexVersion, timeToSet);
+ Long previousTime = reserves.put(indexGen, timeToSet);
// this is the common success case: the older time didn't exist, or
// came before the new time.
@@ -103,19 +104,19 @@ public class IndexDeletionPolicyWrapper implements IndexDeletionPolicy {
/** Permanently prevent this commit point from being deleted.
* A counter is used to allow a commit point to be correctly saved and released
* multiple times. */
- public synchronized void saveCommitPoint(Long indexCommitVersion) {
- AtomicInteger reserveCount = savedCommits.get(indexCommitVersion);
+ public synchronized void saveCommitPoint(Long indexCommitGen) {
+ AtomicInteger reserveCount = savedCommits.get(indexCommitGen);
if (reserveCount == null) reserveCount = new AtomicInteger();
reserveCount.incrementAndGet();
- savedCommits.put(indexCommitVersion, reserveCount);
+ savedCommits.put(indexCommitGen, reserveCount);
}
/** Release a previously saved commit point */
- public synchronized void releaseCommitPoint(Long indexCommitVersion) {
- AtomicInteger reserveCount = savedCommits.get(indexCommitVersion);
+ public synchronized void releaseCommitPoint(Long indexCommitGen) {
+ AtomicInteger reserveCount = savedCommits.get(indexCommitGen);
if (reserveCount == null) return;// this should not happen
if (reserveCount.decrementAndGet() <= 0) {
- savedCommits.remove(indexCommitVersion);
+ savedCommits.remove(indexCommitGen);
}
}
@@ -165,10 +166,10 @@ public class IndexDeletionPolicyWrapper implements IndexDeletionPolicy {
@Override
public void delete() {
- Long version = delegate.getVersion();
- Long reserve = reserves.get(version);
+ Long gen = delegate.getGeneration();
+ Long reserve = reserves.get(gen);
if (reserve != null && System.currentTimeMillis() < reserve) return;
- if(savedCommits.containsKey(version)) return;
+ if(savedCommits.containsKey(gen)) return;
delegate.delete();
}
@@ -187,11 +188,6 @@ public class IndexDeletionPolicyWrapper implements IndexDeletionPolicy {
return delegate.hashCode();
}
- @Override
- public long getVersion() {
- return delegate.getVersion();
- }
-
@Override
public long getGeneration() {
return delegate.getGeneration();
@@ -202,11 +198,6 @@ public class IndexDeletionPolicyWrapper implements IndexDeletionPolicy {
return delegate.isDeleted();
}
- @Override
- public long getTimestamp() throws IOException {
- return delegate.getTimestamp();
- }
-
@Override
public Map getUserData() throws IOException {
return delegate.getUserData();
@@ -214,11 +205,11 @@ public class IndexDeletionPolicyWrapper implements IndexDeletionPolicy {
}
/**
- * @param version the version of the commit point
+ * @param gen the gen of the commit point
* @return a commit point corresponding to the given version
*/
- public IndexCommit getCommitPoint(Long version) {
- return solrVersionVsCommits.get(version);
+ public IndexCommit getCommitPoint(Long gen) {
+ return solrVersionVsCommits.get(gen);
}
/**
@@ -236,10 +227,20 @@ public class IndexDeletionPolicyWrapper implements IndexDeletionPolicy {
Map map = new ConcurrentHashMap();
for (IndexCommitWrapper wrapper : list) {
if (!wrapper.isDeleted())
- map.put(wrapper.getVersion(), wrapper.delegate);
+ map.put(wrapper.delegate.getGeneration(), wrapper.delegate);
}
solrVersionVsCommits = map;
latestCommit = ((list.get(list.size() - 1)).delegate);
}
+
+ public static long getCommitTimestamp(IndexCommit commit) throws IOException {
+ final Map commitData = commit.getUserData();
+ String commitTime = commitData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
+ if (commitTime != null) {
+ return Long.parseLong(commitTime);
+ } else {
+ return 0;
+ }
+ }
}
diff --git a/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java b/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java
index 9f119b0f5c6..d8035e48718 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java
@@ -87,7 +87,6 @@ public class SolrDeletionPolicy implements IndexDeletionPolicy, NamedListInitial
}
sb.append(",segFN=").append(commit.getSegmentsFileName());
- sb.append(",version=").append(commit.getVersion());
sb.append(",generation=").append(commit.getGeneration());
sb.append(",filenames=").append(commit.getFileNames());
} catch (Exception e) {
@@ -133,7 +132,7 @@ public class SolrDeletionPolicy implements IndexDeletionPolicy, NamedListInitial
synchronized (this) {
long maxCommitAgeTimeStamp = -1L;
IndexCommit newest = commits.get(commits.size() - 1);
- log.info("newest commit = " + newest.getVersion());
+ log.info("newest commit = " + newest.getGeneration());
int singleSegKept = (newest.getSegmentCount() == 1) ? 1 : 0;
int totalKept = 1;
@@ -149,7 +148,7 @@ public class SolrDeletionPolicy implements IndexDeletionPolicy, NamedListInitial
DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.US);
maxCommitAgeTimeStamp = dmp.parseMath(maxCommitAge).getTime();
}
- if (commit.getTimestamp() < maxCommitAgeTimeStamp) {
+ if (IndexDeletionPolicyWrapper.getCommitTimestamp(commit) < maxCommitAgeTimeStamp) {
commit.delete();
continue;
}
@@ -191,8 +190,6 @@ public class SolrDeletionPolicy implements IndexDeletionPolicy, NamedListInitial
sb.append('/');
sb.append(commit.getGeneration());
- sb.append('_');
- sb.append(commit.getVersion());
return sb.toString();
}
diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
index bae9c78232c..9557f035c23 100644
--- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
@@ -60,6 +60,7 @@ import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.BinaryQueryResponseWriter;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.update.SolrIndexWriter;
import org.apache.solr.util.NumberUtils;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.plugin.SolrCoreAware;
@@ -139,8 +140,8 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
// in a catastrophic failure, but will result in the client getting an empty file list for
// the CMD_GET_FILE_LIST command.
//
- core.getDeletionPolicy().setReserveDuration(commitPoint.getVersion(), reserveCommitDuration);
- rsp.add(CMD_INDEX_VERSION, commitPoint.getVersion());
+ core.getDeletionPolicy().setReserveDuration(commitPoint.getGeneration(), reserveCommitDuration);
+ rsp.add(CMD_INDEX_VERSION, core.getDeletionPolicy().getCommitTimestamp(commitPoint));
rsp.add(GENERATION, commitPoint.getGeneration());
} else {
// This happens when replication is not configured to happen after startup and no commit/optimize
@@ -219,7 +220,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
for (IndexCommit c : commits.values()) {
try {
NamedList