Skip to content

Set Lucene version upon index creation.#36038

Merged
jpountz merged 2 commits intoelastic:masterfrom
jpountz:fix/set_lucene_version_upon_index_creation
Dec 4, 2018
Merged

Set Lucene version upon index creation.#36038
jpountz merged 2 commits intoelastic:masterfrom
jpountz:fix/set_lucene_version_upon_index_creation

Conversation

@jpountz
Copy link
Copy Markdown
Contributor

@jpountz jpountz commented Nov 29, 2018

It is important that all shards of a given index have the same
indexCreatedVersionMajor to Lucene, or eg. merging those shards is going to
be considered illegal. At the moment, we use the latest Lucene version when
creating a shard, which could cause shards to have different created versions
eg. in case of forced allocation. This commit makes sure to reuse the
appropriate Lucene version in order to avoid such issues.

Closes #33826

It is important that all shards of a given index have the same
`indexCreatedVersionMajor` to Lucene, or eg. merging those shards is going to
be considered illegal. At the moment, we use the latest Lucene version when
creating a shard, which could cause shards to have different created versions
eg. in case of forced allocation. This commit makes sure to reuse the
appropriate Lucene version in order to avoid such issues.

Closes elastic#33826
@jpountz jpountz added >bug v7.0.0 :Distributed/Engine Anything around managing Lucene and the Translog in an open shard. labels Nov 29, 2018
@jpountz jpountz requested a review from ywelsch November 29, 2018 10:34
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-distributed

Copy link
Copy Markdown
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up @jpountz. I think I found a small bug in the snapshot restore logic and I would like to align the shrink index logic with the changes in this PR as well.

IndexWriter writer = new IndexWriter(store.directory(), new IndexWriterConfig(null)
.setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
.setOpenMode(IndexWriterConfig.OpenMode.CREATE)
.setIndexCreatedVersionMajor(version.luceneVersion.major)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not the version with which the index was created, but the version of the master node in the cluster that took the snapshot :)

I think you need to access targetShard.indexSettings().getIndexMetaData().getCreationVersion() here

}
} else {
store.createEmpty();
store.createEmpty(indexShard.indexSettings().getIndexVersionCreated().luceneVersion);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also adapt the logic in addIndices in this class so that it uses the indexmetadata created version when shrinking/splitting? We then have it uniformly everywhere

List<Version> versions = DeclaredVersionsHolder.DECLARED_VERSIONS;
Version tmp = new Version(id, org.apache.lucene.util.Version.LATEST);
int index = Collections.binarySearch(versions, tmp);
if (index < 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we ever expect to find a match in the above collection if we end up in the default case here? Could this be assert index < 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indeed, I added an assertion.

@jpountz jpountz requested a review from ywelsch November 30, 2018 13:11
@jpountz
Copy link
Copy Markdown
Contributor Author

jpountz commented Nov 30, 2018

Thanks @ywelsch, I pushed a new commit.

Copy link
Copy Markdown
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// clean target directory (if previous recovery attempt failed) and create a fresh segment file with the proper lucene version
Lucene.cleanLuceneIndex(target);
assert sources.length > 0;
final int luceneIndexCreatedVersionMajor = Lucene.readSegmentInfos(sources[0]).getIndexCreatedVersionMajor();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe for uniformity pass the lucene version as parameter to the addIndices method and use indexShard.indexSettings().getIndexVersionCreated().luceneVersion, just as in all the other places?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt like reusing the version of one index was safer, as the Lucene version is sometimes guessed via logic in o.e.Version. I don't feel strongly about it though so if you'd rather like that we use the version that comes from index settings, I'm fine with it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks for explaining your reasoning here. Let's keep as is, then.

@jpountz jpountz merged commit 0df08dd into elastic:master Dec 4, 2018
@jpountz jpountz deleted the fix/set_lucene_version_upon_index_creation branch December 4, 2018 16:53
@mfussenegger mfussenegger mentioned this pull request Jun 19, 2020
37 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Distributed/Engine Anything around managing Lucene and the Translog in an open shard. v7.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants