mirror of https://github.com/apache/lucene.git
LUCENE-3760: clean up DirectoryReader/SegmentInfos methods
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1242903 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
590741dcfe
commit
c74d48b857
|
@ -748,6 +748,11 @@ Changes in backwards compatibility policy
|
||||||
* LUCENE-3672: Deprecate Directory.fileModified and
|
* LUCENE-3672: Deprecate Directory.fileModified and
|
||||||
IndexCommit.getTimestamp and .getVersion. (Andrzej Bialecki, Robert
|
IndexCommit.getTimestamp and .getVersion. (Andrzej Bialecki, Robert
|
||||||
Muir, Mike McCandless)
|
Muir, Mike McCandless)
|
||||||
|
|
||||||
|
* LUCENE-3760: In IndexReader/DirectoryReader, deprecate static
|
||||||
|
methods getCurrentVersion and getCommitUserData, and non-static
|
||||||
|
method getCommitUserData (use getIndexCommit().getUserData()
|
||||||
|
instead). (Ryan McKinley, Robert Muir, Mike McCandless)
|
||||||
|
|
||||||
Security fixes
|
Security fixes
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,7 @@ public class CheckIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
final int numSegments = sis.size();
|
final int numSegments = sis.size();
|
||||||
final String segmentsFileName = sis.getCurrentSegmentFileName();
|
final String segmentsFileName = sis.getSegmentsFileName();
|
||||||
// note: we only read the format byte (required preamble) here!
|
// note: we only read the format byte (required preamble) here!
|
||||||
IndexInput input = null;
|
IndexInput input = null;
|
||||||
try {
|
try {
|
||||||
|
@ -1773,7 +1773,7 @@ public class CheckIndex {
|
||||||
System.out.println("Writing...");
|
System.out.println("Writing...");
|
||||||
checker.fixIndex(result, codec);
|
checker.fixIndex(result, codec);
|
||||||
System.out.println("OK");
|
System.out.println("OK");
|
||||||
System.out.println("Wrote new segments file \"" + result.newSegments.getCurrentSegmentFileName() + "\"");
|
System.out.println("Wrote new segments file \"" + result.newSegments.getSegmentsFileName() + "\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
|
|
|
@ -313,38 +313,6 @@ public abstract class DirectoryReader extends BaseMultiReader<AtomicReader> {
|
||||||
return commits;
|
return commits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* segments file. This will return null if {@link
|
|
||||||
* IndexWriter#commit(Map)} has never been called for
|
|
||||||
* this index.
|
|
||||||
*
|
|
||||||
* @param directory where the index resides.
|
|
||||||
* @return commit userData.
|
|
||||||
* @throws CorruptIndexException if the index is corrupt
|
|
||||||
* @throws IOException if there is a low-level IO error
|
|
||||||
*
|
|
||||||
* @see #getCommitUserData()
|
|
||||||
*/
|
|
||||||
public static Map<String, String> getCommitUserData(Directory directory) throws CorruptIndexException, IOException {
|
|
||||||
return SegmentInfos.readCurrentUserData(directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if an index exists at the specified directory.
|
* Returns <code>true</code> if an index exists at the specified directory.
|
||||||
* @param directory the directory to check for an index
|
* @param directory the directory to check for an index
|
||||||
|
@ -414,14 +382,6 @@ public abstract class DirectoryReader extends BaseMultiReader<AtomicReader> {
|
||||||
*/
|
*/
|
||||||
public abstract long getVersion();
|
public abstract long getVersion();
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the String userData optionally passed to
|
|
||||||
* IndexWriter#commit. This will return null if {@link
|
|
||||||
* IndexWriter#commit(Map)} has never been called for
|
|
||||||
* this index.
|
|
||||||
*/
|
|
||||||
public abstract Map<String,String> getCommitUserData();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether any new changes have occurred to the
|
* Check whether any new changes have occurred to the
|
||||||
* index since this reader was opened.
|
* index since this reader was opened.
|
||||||
|
|
|
@ -126,7 +126,7 @@ final class IndexFileDeleter {
|
||||||
this.infoStream = infoStream;
|
this.infoStream = infoStream;
|
||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
|
|
||||||
final String currentSegmentsFile = segmentInfos.getCurrentSegmentFileName();
|
final String currentSegmentsFile = segmentInfos.getSegmentsFileName();
|
||||||
|
|
||||||
if (infoStream.isEnabled("IFD")) {
|
if (infoStream.isEnabled("IFD")) {
|
||||||
infoStream.message("IFD", "init: current segments file is \"" + currentSegmentsFile + "\"; deletionPolicy=" + policy);
|
infoStream.message("IFD", "init: current segments file is \"" + currentSegmentsFile + "\"; deletionPolicy=" + policy);
|
||||||
|
@ -243,7 +243,7 @@ final class IndexFileDeleter {
|
||||||
throw new CorruptIndexException("failed to locate current segments_N file");
|
throw new CorruptIndexException("failed to locate current segments_N file");
|
||||||
}
|
}
|
||||||
if (infoStream.isEnabled("IFD")) {
|
if (infoStream.isEnabled("IFD")) {
|
||||||
infoStream.message("IFD", "forced open of current segments file " + segmentInfos.getCurrentSegmentFileName());
|
infoStream.message("IFD", "forced open of current segments file " + segmentInfos.getSegmentsFileName());
|
||||||
}
|
}
|
||||||
currentCommitPoint = new CommitPoint(commitsToDelete, directory, sis);
|
currentCommitPoint = new CommitPoint(commitsToDelete, directory, sis);
|
||||||
commits.add(currentCommitPoint);
|
commits.add(currentCommitPoint);
|
||||||
|
@ -663,7 +663,7 @@ final class IndexFileDeleter {
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
this.commitsToDelete = commitsToDelete;
|
this.commitsToDelete = commitsToDelete;
|
||||||
userData = segmentInfos.getUserData();
|
userData = segmentInfos.getUserData();
|
||||||
segmentsFileName = segmentInfos.getCurrentSegmentFileName();
|
segmentsFileName = segmentInfos.getSegmentsFileName();
|
||||||
generation = segmentInfos.getGeneration();
|
generation = segmentInfos.getGeneration();
|
||||||
files = Collections.unmodifiableCollection(segmentInfos.files(directory, true));
|
files = Collections.unmodifiableCollection(segmentInfos.files(directory, true));
|
||||||
segmentCount = segmentInfos.size();
|
segmentCount = segmentInfos.size();
|
||||||
|
|
|
@ -2630,7 +2630,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
||||||
* @param commitUserData Opaque Map (String->String)
|
* @param commitUserData Opaque Map (String->String)
|
||||||
* that's recorded into the segments file in the index,
|
* that's recorded into the segments file in the index,
|
||||||
* and retrievable by {@link
|
* and retrievable by {@link
|
||||||
* DirectoryReader#getCommitUserData}. Note that when
|
* IndexCommit#getUserData}. Note that when
|
||||||
* IndexWriter commits itself during {@link #close}, the
|
* IndexWriter commits itself during {@link #close}, the
|
||||||
* commitUserData is unchanged (just carried over from
|
* commitUserData is unchanged (just carried over from
|
||||||
* the prior commit). If this is null then the previous
|
* the prior commit). If this is null then the previous
|
||||||
|
@ -2821,7 +2821,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
||||||
}
|
}
|
||||||
pendingCommit.finishCommit(directory, codec);
|
pendingCommit.finishCommit(directory, codec);
|
||||||
if (infoStream.isEnabled("IW")) {
|
if (infoStream.isEnabled("IW")) {
|
||||||
infoStream.message("IW", "commit: wrote segments file \"" + pendingCommit.getCurrentSegmentFileName() + "\"");
|
infoStream.message("IW", "commit: wrote segments file \"" + pendingCommit.getSegmentsFileName() + "\"");
|
||||||
}
|
}
|
||||||
lastCommitChangeCount = pendingCommitChangeCount;
|
lastCommitChangeCount = pendingCommitChangeCount;
|
||||||
segmentInfos.updateGeneration(pendingCommit);
|
segmentInfos.updateGeneration(pendingCommit);
|
||||||
|
|
|
@ -138,12 +138,12 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the generation (N) of the current segments_N file
|
* Get the generation of the most recent commit to the
|
||||||
* from a list of files.
|
* list of index files (N in the segments_N file).
|
||||||
*
|
*
|
||||||
* @param files -- array of file names to check
|
* @param files -- array of file names to check
|
||||||
*/
|
*/
|
||||||
public static long getCurrentSegmentGeneration(String[] files) {
|
public static long getLastCommitGeneration(String[] files) {
|
||||||
if (files == null) {
|
if (files == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -160,48 +160,48 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the generation (N) of the current segments_N file
|
* Get the generation of the most recent commit to the
|
||||||
* in the directory.
|
* index in this directory (N in the segments_N file).
|
||||||
*
|
*
|
||||||
* @param directory -- directory to search for the latest segments_N file
|
* @param directory -- directory to search for the latest segments_N file
|
||||||
*/
|
*/
|
||||||
public static long getCurrentSegmentGeneration(Directory directory) throws IOException {
|
public static long getLastCommitGeneration(Directory directory) throws IOException {
|
||||||
try {
|
try {
|
||||||
return getCurrentSegmentGeneration(directory.listAll());
|
return getLastCommitGeneration(directory.listAll());
|
||||||
} catch (NoSuchDirectoryException nsde) {
|
} catch (NoSuchDirectoryException nsde) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the filename of the current segments_N file
|
* Get the filename of the segments_N file for the most
|
||||||
* from a list of files.
|
* recent commit in the list of index files.
|
||||||
*
|
*
|
||||||
* @param files -- array of file names to check
|
* @param files -- array of file names to check
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static String getCurrentSegmentFileName(String[] files) throws IOException {
|
public static String getLastCommitSegmentsFileName(String[] files) throws IOException {
|
||||||
return IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
return IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
||||||
"",
|
"",
|
||||||
getCurrentSegmentGeneration(files));
|
getLastCommitGeneration(files));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the filename of the current segments_N file
|
* Get the filename of the segments_N file for the most
|
||||||
* in the directory.
|
* recent commit to the index in this Directory.
|
||||||
*
|
*
|
||||||
* @param directory -- directory to search for the latest segments_N file
|
* @param directory -- directory to search for the latest segments_N file
|
||||||
*/
|
*/
|
||||||
public static String getCurrentSegmentFileName(Directory directory) throws IOException {
|
public static String getLastCommitSegmentsFileName(Directory directory) throws IOException {
|
||||||
return IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
return IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
||||||
"",
|
"",
|
||||||
getCurrentSegmentGeneration(directory));
|
getLastCommitGeneration(directory));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the segments_N filename in use by this segment infos.
|
* Get the segments_N filename in use by this segment infos.
|
||||||
*/
|
*/
|
||||||
public String getCurrentSegmentFileName() {
|
public String getSegmentsFileName() {
|
||||||
return IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
return IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
||||||
"",
|
"",
|
||||||
lastGeneration);
|
lastGeneration);
|
||||||
|
@ -407,36 +407,6 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
return lastGeneration;
|
return lastGeneration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Current version number from segments file.
|
|
||||||
* @throws CorruptIndexException if the index is corrupt
|
|
||||||
* @throws IOException if there is a low-level IO error
|
|
||||||
*/
|
|
||||||
public static long readCurrentVersion(Directory directory)
|
|
||||||
throws CorruptIndexException, IOException {
|
|
||||||
|
|
||||||
// Fully read the segments file: this ensures that it's
|
|
||||||
// completely written so that if
|
|
||||||
// IndexWriter.prepareCommit has been called (but not
|
|
||||||
// yet commit), then the reader will still see itself as
|
|
||||||
// current:
|
|
||||||
SegmentInfos sis = new SegmentInfos();
|
|
||||||
sis.read(directory);
|
|
||||||
return sis.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns userData from latest segments file
|
|
||||||
* @throws CorruptIndexException if the index is corrupt
|
|
||||||
* @throws IOException if there is a low-level IO error
|
|
||||||
*/
|
|
||||||
public static Map<String,String> readCurrentUserData(Directory directory)
|
|
||||||
throws CorruptIndexException, IOException {
|
|
||||||
SegmentInfos sis = new SegmentInfos();
|
|
||||||
sis.read(directory);
|
|
||||||
return sis.getUserData();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** If non-null, information about retries when loading
|
/** If non-null, information about retries when loading
|
||||||
* the segments file will be printed to this.
|
* the segments file will be printed to this.
|
||||||
*/
|
*/
|
||||||
|
@ -555,7 +525,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
files = directory.listAll();
|
files = directory.listAll();
|
||||||
|
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
genA = getCurrentSegmentGeneration(files);
|
genA = getLastCommitGeneration(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infoStream != null) {
|
if (infoStream != null) {
|
||||||
|
@ -770,7 +740,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
public Collection<String> files(Directory dir, boolean includeSegmentsFile) throws IOException {
|
public Collection<String> files(Directory dir, boolean includeSegmentsFile) throws IOException {
|
||||||
HashSet<String> files = new HashSet<String>();
|
HashSet<String> files = new HashSet<String>();
|
||||||
if (includeSegmentsFile) {
|
if (includeSegmentsFile) {
|
||||||
final String segmentFileName = getCurrentSegmentFileName();
|
final String segmentFileName = getSegmentsFileName();
|
||||||
if (segmentFileName != null) {
|
if (segmentFileName != null) {
|
||||||
/*
|
/*
|
||||||
* TODO: if lastGen == -1 we get might get null here it seems wrong to
|
* TODO: if lastGen == -1 we get might get null here it seems wrong to
|
||||||
|
@ -869,7 +839,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
|
|
||||||
public String toString(Directory directory) {
|
public String toString(Directory directory) {
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
buffer.append(getCurrentSegmentFileName()).append(": ");
|
buffer.append(getSegmentsFileName()).append(": ");
|
||||||
final int count = size();
|
final int count = size();
|
||||||
for(int i = 0; i < count; i++) {
|
for(int i = 0; i < count; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
|
|
@ -203,7 +203,7 @@ final class StandardDirectoryReader extends DirectoryReader {
|
||||||
final StringBuilder buffer = new StringBuilder();
|
final StringBuilder buffer = new StringBuilder();
|
||||||
buffer.append(getClass().getSimpleName());
|
buffer.append(getClass().getSimpleName());
|
||||||
buffer.append('(');
|
buffer.append('(');
|
||||||
final String segmentsFile = segmentInfos.getCurrentSegmentFileName();
|
final String segmentsFile = segmentInfos.getSegmentsFileName();
|
||||||
if (segmentsFile != null) {
|
if (segmentsFile != null) {
|
||||||
buffer.append(segmentsFile).append(":").append(segmentInfos.getVersion());
|
buffer.append(segmentsFile).append(":").append(segmentInfos.getVersion());
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,7 @@ final class StandardDirectoryReader extends DirectoryReader {
|
||||||
if (directory != commit.getDirectory()) {
|
if (directory != commit.getDirectory()) {
|
||||||
throw new IOException("the specified commit does not match the specified Directory");
|
throw new IOException("the specified commit does not match the specified Directory");
|
||||||
}
|
}
|
||||||
if (segmentInfos != null && commit.getSegmentsFileName().equals(segmentInfos.getCurrentSegmentFileName())) {
|
if (segmentInfos != null && commit.getSegmentsFileName().equals(segmentInfos.getSegmentsFileName())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,18 +301,20 @@ final class StandardDirectoryReader extends DirectoryReader {
|
||||||
return segmentInfos.getVersion();
|
return segmentInfos.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String,String> getCommitUserData() {
|
|
||||||
ensureOpen();
|
|
||||||
return segmentInfos.getUserData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCurrent() throws CorruptIndexException, IOException {
|
public boolean isCurrent() throws CorruptIndexException, IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
if (writer == null || writer.isClosed()) {
|
if (writer == null || writer.isClosed()) {
|
||||||
|
// Fully read the segments file: this ensures that it's
|
||||||
|
// completely written so that if
|
||||||
|
// IndexWriter.prepareCommit has been called (but not
|
||||||
|
// yet commit), then the reader will still see itself as
|
||||||
|
// current:
|
||||||
|
SegmentInfos sis = new SegmentInfos();
|
||||||
|
sis.read(directory);
|
||||||
|
|
||||||
// we loaded SegmentInfos from the directory
|
// we loaded SegmentInfos from the directory
|
||||||
return SegmentInfos.readCurrentVersion(directory) == segmentInfos.getVersion();
|
return sis.getVersion() == segmentInfos.getVersion();
|
||||||
} else {
|
} else {
|
||||||
return writer.nrtIsCurrent(segmentInfos);
|
return writer.nrtIsCurrent(segmentInfos);
|
||||||
}
|
}
|
||||||
|
@ -355,7 +357,7 @@ final class StandardDirectoryReader extends DirectoryReader {
|
||||||
private final int segmentCount;
|
private final int segmentCount;
|
||||||
|
|
||||||
ReaderCommit(SegmentInfos infos, Directory dir) throws IOException {
|
ReaderCommit(SegmentInfos infos, Directory dir) throws IOException {
|
||||||
segmentsFileName = infos.getCurrentSegmentFileName();
|
segmentsFileName = infos.getSegmentsFileName();
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
userData = infos.getUserData();
|
userData = infos.getUserData();
|
||||||
files = Collections.unmodifiableCollection(infos.files(dir, true));
|
files = Collections.unmodifiableCollection(infos.files(dir, true));
|
||||||
|
|
|
@ -252,7 +252,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
|
||||||
// segments_N's that still exist are in fact within SECONDS
|
// segments_N's that still exist are in fact within SECONDS
|
||||||
// seconds of the last one's mod time, and, that I can
|
// seconds of the last one's mod time, and, that I can
|
||||||
// open a reader on each:
|
// open a reader on each:
|
||||||
long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
|
long gen = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
|
|
||||||
String fileName = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
String fileName = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
||||||
"",
|
"",
|
||||||
|
@ -364,7 +364,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
|
||||||
// Simplistic check: just verify all segments_N's still
|
// Simplistic check: just verify all segments_N's still
|
||||||
// exist, and, I can open a reader on each:
|
// exist, and, I can open a reader on each:
|
||||||
dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
|
dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
|
||||||
long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
|
long gen = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
while(gen > 0) {
|
while(gen > 0) {
|
||||||
IndexReader reader = IndexReader.open(dir);
|
IndexReader reader = IndexReader.open(dir);
|
||||||
reader.close();
|
reader.close();
|
||||||
|
@ -586,7 +586,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
|
||||||
// Simplistic check: just verify only the past N segments_N's still
|
// Simplistic check: just verify only the past N segments_N's still
|
||||||
// exist, and, I can open a reader on each:
|
// exist, and, I can open a reader on each:
|
||||||
dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
|
dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
|
||||||
long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
|
long gen = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
for(int i=0;i<N+1;i++) {
|
for(int i=0;i<N+1;i++) {
|
||||||
try {
|
try {
|
||||||
IndexReader reader = IndexReader.open(dir);
|
IndexReader reader = IndexReader.open(dir);
|
||||||
|
@ -684,7 +684,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
|
||||||
|
|
||||||
// Simplistic check: just verify only the past N segments_N's still
|
// Simplistic check: just verify only the past N segments_N's still
|
||||||
// exist, and, I can open a reader on each:
|
// exist, and, I can open a reader on each:
|
||||||
long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
|
long gen = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
|
|
||||||
dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
|
dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
|
||||||
int expectedCount = 0;
|
int expectedCount = 0;
|
||||||
|
|
|
@ -582,7 +582,7 @@ public class TestIndexReader extends LuceneTestCase {
|
||||||
DirectoryReader r = DirectoryReader.open(d);
|
DirectoryReader r = DirectoryReader.open(d);
|
||||||
IndexCommit c = r.getIndexCommit();
|
IndexCommit c = r.getIndexCommit();
|
||||||
|
|
||||||
assertEquals(sis.getCurrentSegmentFileName(), c.getSegmentsFileName());
|
assertEquals(sis.getSegmentsFileName(), c.getSegmentsFileName());
|
||||||
|
|
||||||
assertTrue(c.equals(r.getIndexCommit()));
|
assertTrue(c.equals(r.getIndexCommit()));
|
||||||
|
|
||||||
|
|
|
@ -620,11 +620,9 @@ public class TestIndexWriterCommit extends LuceneTestCase {
|
||||||
TestIndexWriter.addDoc(w);
|
TestIndexWriter.addDoc(w);
|
||||||
w.close();
|
w.close();
|
||||||
|
|
||||||
assertEquals(0, DirectoryReader.getCommitUserData(dir).size());
|
|
||||||
|
|
||||||
DirectoryReader r = IndexReader.open(dir);
|
DirectoryReader r = IndexReader.open(dir);
|
||||||
// commit(Map) never called for this index
|
// commit(Map) never called for this index
|
||||||
assertEquals(0, r.getCommitUserData().size());
|
assertEquals(0, r.getIndexCommit().getUserData().size());
|
||||||
r.close();
|
r.close();
|
||||||
|
|
||||||
w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)).setMaxBufferedDocs(2));
|
w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)).setMaxBufferedDocs(2));
|
||||||
|
@ -635,18 +633,14 @@ public class TestIndexWriterCommit extends LuceneTestCase {
|
||||||
w.commit(data);
|
w.commit(data);
|
||||||
w.close();
|
w.close();
|
||||||
|
|
||||||
assertEquals("test1", DirectoryReader.getCommitUserData(dir).get("label"));
|
|
||||||
|
|
||||||
r = IndexReader.open(dir);
|
r = IndexReader.open(dir);
|
||||||
assertEquals("test1", r.getCommitUserData().get("label"));
|
assertEquals("test1", r.getIndexCommit().getUserData().get("label"));
|
||||||
r.close();
|
r.close();
|
||||||
|
|
||||||
w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)));
|
w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)));
|
||||||
w.forceMerge(1);
|
w.forceMerge(1);
|
||||||
w.close();
|
w.close();
|
||||||
|
|
||||||
assertEquals("test1", DirectoryReader.getCommitUserData(dir).get("label"));
|
|
||||||
|
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1045,10 +1045,10 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
// close
|
// close
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
|
long gen = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
|
assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
|
||||||
|
|
||||||
final String segmentsFileName = SegmentInfos.getCurrentSegmentFileName(dir);
|
final String segmentsFileName = SegmentInfos.getLastCommitSegmentsFileName(dir);
|
||||||
IndexInput in = dir.openInput(segmentsFileName, newIOContext(random));
|
IndexInput in = dir.openInput(segmentsFileName, newIOContext(random));
|
||||||
IndexOutput out = dir.createOutput(IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1+gen), newIOContext(random));
|
IndexOutput out = dir.createOutput(IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1+gen), newIOContext(random));
|
||||||
out.copyBytes(in, in.length()-1);
|
out.copyBytes(in, in.length()-1);
|
||||||
|
@ -1087,10 +1087,10 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
// close
|
// close
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
|
long gen = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
|
assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
|
||||||
|
|
||||||
String fileNameIn = SegmentInfos.getCurrentSegmentFileName(dir);
|
String fileNameIn = SegmentInfos.getLastCommitSegmentsFileName(dir);
|
||||||
String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
||||||
"",
|
"",
|
||||||
1+gen);
|
1+gen);
|
||||||
|
@ -1139,7 +1139,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
// close
|
// close
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
|
long gen = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
|
assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
|
||||||
|
|
||||||
String[] files = dir.listAll();
|
String[] files = dir.listAll();
|
||||||
|
@ -1185,13 +1185,13 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
// close
|
// close
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
|
long gen = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
|
assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
|
||||||
|
|
||||||
// Make the next segments file, with last byte
|
// Make the next segments file, with last byte
|
||||||
// missing, to simulate a writer that crashed while
|
// missing, to simulate a writer that crashed while
|
||||||
// writing segments file:
|
// writing segments file:
|
||||||
String fileNameIn = SegmentInfos.getCurrentSegmentFileName(dir);
|
String fileNameIn = SegmentInfos.getLastCommitSegmentsFileName(dir);
|
||||||
String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
|
||||||
"",
|
"",
|
||||||
1+gen);
|
1+gen);
|
||||||
|
|
|
@ -242,7 +242,7 @@ public interface TaxonomyReader extends Closeable {
|
||||||
* Retrieve user committed data.
|
* Retrieve user committed data.
|
||||||
* @see TaxonomyWriter#commit(Map)
|
* @see TaxonomyWriter#commit(Map)
|
||||||
*/
|
*/
|
||||||
public Map<String, String> getCommitUserData();
|
public Map<String, String> getCommitUserData() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expert: increments the refCount of this TaxonomyReader instance.
|
* Expert: increments the refCount of this TaxonomyReader instance.
|
||||||
|
|
|
@ -361,8 +361,8 @@ public class DirectoryTaxonomyReader implements TaxonomyReader {
|
||||||
|
|
||||||
// validate that a refresh is valid at this point, i.e. that the taxonomy
|
// validate that a refresh is valid at this point, i.e. that the taxonomy
|
||||||
// was not recreated since this reader was last opened or refresshed.
|
// was not recreated since this reader was last opened or refresshed.
|
||||||
String t1 = indexReader.getCommitUserData().get(DirectoryTaxonomyWriter.INDEX_CREATE_TIME);
|
String t1 = indexReader.getIndexCommit().getUserData().get(DirectoryTaxonomyWriter.INDEX_CREATE_TIME);
|
||||||
String t2 = r2.getCommitUserData().get(DirectoryTaxonomyWriter.INDEX_CREATE_TIME);
|
String t2 = r2.getIndexCommit().getUserData().get(DirectoryTaxonomyWriter.INDEX_CREATE_TIME);
|
||||||
if (t1==null) {
|
if (t1==null) {
|
||||||
if (t2!=null) {
|
if (t2!=null) {
|
||||||
r2.close();
|
r2.close();
|
||||||
|
@ -450,9 +450,9 @@ public class DirectoryTaxonomyReader implements TaxonomyReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getCommitUserData() {
|
public Map<String, String> getCommitUserData() throws IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
return indexReader.getCommitUserData();
|
return indexReader.getIndexCommit().getUserData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChildrenArrays childrenArrays;
|
private ChildrenArrays childrenArrays;
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class TestDirectoryTaxonomyWriter extends LuceneTestCase {
|
||||||
ltw.close();
|
ltw.close();
|
||||||
DirectoryReader r = IndexReader.open(dir);
|
DirectoryReader r = IndexReader.open(dir);
|
||||||
assertEquals("2 categories plus root should have been committed to the underlying directory", 3, r.numDocs());
|
assertEquals("2 categories plus root should have been committed to the underlying directory", 3, r.numDocs());
|
||||||
Map <String, String> readUserCommitData = r.getCommitUserData();
|
Map <String, String> readUserCommitData = r.getIndexCommit().getUserData();
|
||||||
assertTrue("wrong value extracted from commit data",
|
assertTrue("wrong value extracted from commit data",
|
||||||
"1 2 3".equals(readUserCommitData.get("testing")));
|
"1 2 3".equals(readUserCommitData.get("testing")));
|
||||||
r.close();
|
r.close();
|
||||||
|
|
Loading…
Reference in New Issue