Skip to content

Commit

Permalink
fix writeIndex evaluation for aliases (#31562)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
talevy committed Jun 26, 2018
1 parent 28d62cd commit 57a7826
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ public void computeAndValidateWriteIndex() {
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ public void testAddWriteOnlyWithNoExistingAliases() {
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)));
Expand Down

0 comments on commit 57a7826

Please sign in to comment.