Repository navigation
Use Lucene for new and rebuilt indexes - #6035
ramonsmits wants to merge 1 commit into
Conversation
c44bed6 to
712053d
Compare
| var changes = existing == null ? IndexDefinitionCompareDifferences.None : RebuildChanges(existing, index, store); | ||
| var changed = changes != IndexDefinitionCompareDifferences.None; |
There was a problem hiding this comment.
The namings here are a bit hard to follow, I had to dive in to the code down below to understand what was happening
| // 3. A new index, or an index that RavenDB rebuilds because the definition changed, uses Lucene, the | ||
| // application default. It inherits Lucene when the database is set to Lucene. Otherwise Lucene is set on | ||
| // the index, so the index does not follow a database default of Corax. | ||
| if (existing == null || changed) | ||
| { | ||
| index.Configuration[StaticSearchEngineTypeKey] = nameof(SearchEngineType.Lucene); | ||
| Logger.LogInformation("Index {IndexName} is created with the Lucene search engine", index.IndexName); | ||
| var reason = existing == null ? "is created" : $"is rebuilt because its definition changed ({changes})"; | ||
|
|
||
| if (databaseDefaultIsLucene) | ||
| { | ||
| Logger.LogInformation("Index {IndexName} {Reason} and inherits the Lucene search engine from the database", index.IndexName, reason); | ||
| } | ||
| else | ||
| { | ||
| index.Configuration[StaticSearchEngineTypeKey] = nameof(SearchEngineType.Lucene); | ||
| Logger.LogInformation("Index {IndexName} {Reason} with the Lucene search engine set on the index, the database setting is {DatabaseDefault}", index.IndexName, reason, databaseDefault ?? "not set"); | ||
| } | ||
|
|
||
| continue; | ||
| } |
There was a problem hiding this comment.
Isn't this in conflict with step 1 above?
If the definition contains an explicit search engine type, but the index was also changed, this will override the explicit search engine type in the index defition always to Lucene
| // 3. A new index, or an index that RavenDB rebuilds because the definition changed, uses Lucene, the | ||
| // application default. It inherits Lucene when the database is set to Lucene. Otherwise Lucene is set on | ||
| // the index, so the index does not follow a database default of Corax. | ||
| if (existing == null || changed) |
There was a problem hiding this comment.
Use field to describe the expression usage
| | IndexDefinitionCompareDifferences.AdditionalSources | ||
| | IndexDefinitionCompareDifferences.AdditionalAssemblies; | ||
|
|
||
| static IndexDefinitionCompareDifferences RebuildChanges(IndexDefinition existingDefinition, AbstractIndexCreationTask index, IDocumentStore store) |
There was a problem hiding this comment.
| static IndexDefinitionCompareDifferences RebuildChanges(IndexDefinition existingDefinition, AbstractIndexCreationTask index, IDocumentStore store) | |
| static IndexDefinitionCompareDifferences GetDetectedChanges(IndexDefinition existingDefinition, AbstractIndexCreationTask index, IDocumentStore store) |
| // 1. A search engine set in our index definition always wins. It can be set through SearchEngineType or Configuration. | ||
| if (index.SearchEngineType.HasValue | ||
| || (index.Configuration.TryGetValue(StaticSearchEngineTypeKey, out var configuredSearchEngineType) && !string.IsNullOrEmpty(configuredSearchEngineType))) | ||
| if (index.SearchEngineType.HasValue) |
There was a problem hiding this comment.
@mauroservienti as discussed in our sync I'm no longer convinced we want this.
If users want to override the search engine type, they apply it and the lock the index.
Then at SC start we detect the index is locked, and log a warn, if we detect the definition is incompatible we throw and we want the user to either UNLOCK so we can apply the new definition or the user manually applies the definition changes and locks it again so next start we detect the definition is identical (except for maybe the search engine).
Since 6.21.1
IndexDeploymentkeeps a search engine that is set on an index itself. An index without a setting of its own was left alone, also when its definition changed. RavenDB then built the replacement with the database default. On every installation that ran 6.20.0 to 6.21.2 that default is Corax, so a definition change moved a Lucene index that had no setting of its own, for example after a reset under a Lucene default, back to Corax.The rules are now:
Rule 3 means a Corax index without a setting moves to Lucene at the next definition change, without an operator action, and a Lucene index never falls back to Corax.
A definition change is detected with
IndexDefinition.Compareon the maps, reduce, fields, additional sources and assemblies, the same differences for which RavenDB builds a side-by-side replacement.Tests in
IndexSetupTestscover a new index in a Lucene and in a Corax database, a changed Lucene index without a setting in a Corax database, a changed Corax index without a setting in a Lucene database, and an unchanged index without a setting that must not be rebuilt.