Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SegmentInfos replace doesn't update userData #948

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/Lucene.Net.Tests/Index/TestIndexWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,65 @@ public virtual void TestMaxThreadPriority()
}
}

private Dictionary<String, String> GetCommitData(IndexWriter writer)
{
Dictionary<String, String> data = new Dictionary<String, String>();
foreach (var ent in writer.CommitData)
{
data.Put(ent.Key, ent.Value);
}
return data;
}

[Test]
public void testGetCommitDataFromOldSnapshot()
{
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy());
conf.SetIndexDeletionPolicy(new SnapshotDeletionPolicy(NoDeletionPolicy.INSTANCE));
IndexWriter writer = new IndexWriter(dir, conf);
writer.SetCommitData(
new Dictionary<String, String>()
{
{ "key", "value" },
});
assertEquals("value", GetCommitData(writer).GetValueOrDefault("key"));
writer.Commit();
// Snapshot this commit to open later
IndexCommit indexCommit =
((SnapshotDeletionPolicy)writer.Config.IndexDeletionPolicy).Snapshot();
writer.Dispose();

// Modify the commit data and commit on close so the most recent commit data is different
conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy());
conf.SetIndexDeletionPolicy(new SnapshotDeletionPolicy(NoDeletionPolicy.INSTANCE));
writer = new IndexWriter(dir, conf);
writer.SetCommitData(
new Dictionary<String, String>()
{
{"key", "value2" },
});

assertEquals("value2", GetCommitData(writer).GetValueOrDefault("key"));
writer.Dispose();

// validate that when opening writer from older snapshotted index commit, the old commit data is
// visible
conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy());
conf.SetIndexDeletionPolicy(new SnapshotDeletionPolicy(NoDeletionPolicy.INSTANCE));
writer =
new IndexWriter(
dir,
conf
.SetOpenMode(OpenMode.APPEND)
.SetIndexCommit(indexCommit));
assertEquals("value", GetCommitData(writer).GetValueOrDefault("key"));
writer.Dispose();

dir.Dispose();
}


[Test]
public virtual void TestVariableSchema()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Lucene.Net/Index/SegmentInfos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@ internal void Replace(SegmentInfos other)
{
RollbackSegmentInfos(other.AsList());
lastGeneration = other.lastGeneration;
userData = other.userData;
}

/// <summary>
Expand Down Expand Up @@ -1632,4 +1633,4 @@ internal int IndexOf(SegmentCommitInfo si)
return segments.IndexOf(si);
}
}
}
}