fix writeIndex evaluation for aliases (#31562)

AliasOrIndex.Alias#writeIndex was returning a write index when
an alias was pointing to only one index, regardless whether `is_write_index` was
set to `false`. This fixes that so that there is no write index in such a case
that an alias points to only one index with `is_write_index=false`.
This commit is contained in:
Tal Levy 2018-06-25 17:17:16 -07:00 committed by GitHub
parent 237650e9c0
commit c6012ed575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -157,9 +157,13 @@ public interface AliasOrIndex {
List<IndexMetaData> writeIndices = referenceIndexMetaDatas.stream()
.filter(idxMeta -> Boolean.TRUE.equals(idxMeta.getAliases().get(aliasName).writeIndex()))
.collect(Collectors.toList());
if (referenceIndexMetaDatas.size() == 1) {
writeIndex.set(referenceIndexMetaDatas.get(0));
} else if (writeIndices.size() == 1) {
if (writeIndices.isEmpty() && referenceIndexMetaDatas.size() == 1
&& referenceIndexMetaDatas.get(0).getAliases().get(aliasName).writeIndex() == null) {
writeIndices.add(referenceIndexMetaDatas.get(0));
}
if (writeIndices.size() == 1) {
writeIndex.set(writeIndices.get(0));
} else if (writeIndices.size() > 1) {
List<String> writeIndicesStrings = writeIndices.stream()

View File

@ -136,8 +136,7 @@ public class MetaDataIndexAliasesServiceTests extends ESTestCase {
ClusterState after = service.innerExecute(before, Arrays.asList(
new AliasAction.Add("test", "alias", null, null, null, false)));
assertFalse(after.metaData().index("test").getAliases().get("alias").writeIndex());
assertThat(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex(),
equalTo(after.metaData().index("test")));
assertNull(((AliasOrIndex.Alias) after.metaData().getAliasAndIndexLookup().get("alias")).getWriteIndex());
after = service.innerExecute(before, Arrays.asList(
new AliasAction.Add("test", "alias", null, null, null, null)));