mirror of https://github.com/apache/lucene.git
LUCENE-4972: DirectoryTaxonomyWriter makes a commit even if no changes were made
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1478638 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
30e43c836a
commit
e2c54ff680
|
@ -86,6 +86,9 @@ Bug Fixes
|
||||||
|
|
||||||
* LUCENE-4974: CommitIndexTask was broken if no params were set. (Shai Erera)
|
* LUCENE-4974: CommitIndexTask was broken if no params were set. (Shai Erera)
|
||||||
|
|
||||||
|
* LUCENE-4972: DirectoryTaxonomyWriter created empty commits even if no changes
|
||||||
|
were made. (Shai Erera, Michael McCandless)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
|
|
||||||
* LUCENE-4938: Don't use an unnecessarily large priority queue in IndexSearcher
|
* LUCENE-4938: Don't use an unnecessarily large priority queue in IndexSearcher
|
||||||
|
|
|
@ -225,7 +225,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
}
|
}
|
||||||
// no commit data, or no epoch in it means an old taxonomy, so set its epoch to 1, for lack
|
// no commit data, or no epoch in it means an old taxonomy, so set its epoch to 1, for lack
|
||||||
// of a better value.
|
// of a better value.
|
||||||
indexEpoch = epochStr == null ? 1 : Long.parseLong(epochStr);
|
indexEpoch = epochStr == null ? 1 : Long.parseLong(epochStr, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openMode == OpenMode.CREATE) {
|
if (openMode == OpenMode.CREATE) {
|
||||||
|
@ -354,8 +354,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() throws IOException {
|
public synchronized void close() throws IOException {
|
||||||
if (!isClosed) {
|
if (!isClosed) {
|
||||||
indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
|
commit();
|
||||||
indexWriter.commit();
|
|
||||||
doClose();
|
doClose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -616,7 +615,11 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
@Override
|
@Override
|
||||||
public synchronized void commit() throws IOException {
|
public synchronized void commit() throws IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
|
// LUCENE-4972: if we always call setCommitData, we create empty commits
|
||||||
|
String epochStr = indexWriter.getCommitData().get(INDEX_EPOCH);
|
||||||
|
if (epochStr == null || Long.parseLong(epochStr, 16) != indexEpoch) {
|
||||||
|
indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
|
||||||
|
}
|
||||||
indexWriter.commit();
|
indexWriter.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,7 +629,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
if (commitData != null) {
|
if (commitData != null) {
|
||||||
m.putAll(commitData);
|
m.putAll(commitData);
|
||||||
}
|
}
|
||||||
m.put(INDEX_EPOCH, Long.toString(indexEpoch));
|
m.put(INDEX_EPOCH, Long.toString(indexEpoch, 16));
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -647,7 +650,11 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
@Override
|
@Override
|
||||||
public synchronized void prepareCommit() throws IOException {
|
public synchronized void prepareCommit() throws IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
|
// LUCENE-4972: if we always call setCommitData, we create empty commits
|
||||||
|
String epochStr = indexWriter.getCommitData().get(INDEX_EPOCH);
|
||||||
|
if (epochStr == null || Long.parseLong(epochStr, 16) != indexEpoch) {
|
||||||
|
indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
|
||||||
|
}
|
||||||
indexWriter.prepareCommit();
|
indexWriter.prepareCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -359,5 +359,58 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {
|
||||||
taxoWriter.close();
|
taxoWriter.close();
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommitNoEmptyCommits() throws Exception {
|
||||||
|
// LUCENE-4972: DTW used to create empty commits even if no changes were made
|
||||||
|
Directory dir = newDirectory();
|
||||||
|
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
|
||||||
|
taxoWriter.addCategory(new CategoryPath("a"));
|
||||||
|
taxoWriter.commit();
|
||||||
|
|
||||||
|
long gen1 = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
|
taxoWriter.commit();
|
||||||
|
long gen2 = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
|
assertEquals("empty commit should not have changed the index", gen1, gen2);
|
||||||
|
|
||||||
|
taxoWriter.close();
|
||||||
|
dir.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCloseNoEmptyCommits() throws Exception {
|
||||||
|
// LUCENE-4972: DTW used to create empty commits even if no changes were made
|
||||||
|
Directory dir = newDirectory();
|
||||||
|
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
|
||||||
|
taxoWriter.addCategory(new CategoryPath("a"));
|
||||||
|
taxoWriter.commit();
|
||||||
|
|
||||||
|
long gen1 = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
|
taxoWriter.close();
|
||||||
|
long gen2 = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
|
assertEquals("empty commit should not have changed the index", gen1, gen2);
|
||||||
|
|
||||||
|
taxoWriter.close();
|
||||||
|
dir.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPrepareCommitNoEmptyCommits() throws Exception {
|
||||||
|
// LUCENE-4972: DTW used to create empty commits even if no changes were made
|
||||||
|
Directory dir = newDirectory();
|
||||||
|
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
|
||||||
|
taxoWriter.addCategory(new CategoryPath("a"));
|
||||||
|
taxoWriter.prepareCommit();
|
||||||
|
taxoWriter.commit();
|
||||||
|
|
||||||
|
long gen1 = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
|
taxoWriter.prepareCommit();
|
||||||
|
taxoWriter.commit();
|
||||||
|
long gen2 = SegmentInfos.getLastCommitGeneration(dir);
|
||||||
|
assertEquals("empty commit should not have changed the index", gen1, gen2);
|
||||||
|
|
||||||
|
taxoWriter.close();
|
||||||
|
dir.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue