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

add is-write-index flag to aliases #30942

Merged
merged 29 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5838717
add is-write-index flag to aliases
talevy May 29, 2018
7baf86b
cleanup
talevy May 31, 2018
19315ff
fix unit tests
talevy Jun 1, 2018
440fed4
update docs and tests
talevy Jun 1, 2018
135d7c1
change to validate at MetaData.build
talevy Jun 4, 2018
5bb7217
Merge branch 'master' into is-write-index-setting
talevy Jun 5, 2018
847bbe6
Merge branch 'master' into is-write-index-setting
talevy Jun 5, 2018
32ca015
add writeIndex to ToAndFromJsonMetaDataTests
talevy Jun 5, 2018
07188f3
Merge branch 'master' into is-write-index-setting
talevy Jun 12, 2018
01fab60
refactor as to not re-build aliasAndIndexLookup
talevy Jun 12, 2018
c7a3a96
migrate validation tests and setonce writeIndex
talevy Jun 12, 2018
8df9bc8
Merge branch 'master' into is-write-index-setting
talevy Jun 12, 2018
4e898c1
fix SharedClusterSnapshotRestoreIT#testRenameOnRestore
talevy Jun 12, 2018
1aac672
Merge branch 'master' into is-write-index-setting
talevy Jun 12, 2018
5ea9725
fix rest spec tests
talevy Jun 12, 2018
1c9e28f
change validation strategy and no defaulting to indexmetadata
talevy Jun 12, 2018
4755a10
update to reflect no defaulting values
talevy Jun 12, 2018
ae2b0c9
fix unit tests
talevy Jun 12, 2018
545c801
fix doc tests
talevy Jun 12, 2018
a614010
add version guard for 7.0 in IndicesAliasesRequest
talevy Jun 13, 2018
ee4142d
Merge branch 'master' into is-write-index-setting
talevy Jun 13, 2018
8c33d23
Merge branch 'master' into is-write-index-setting
talevy Jun 13, 2018
0025a51
further cleanup
talevy Jun 13, 2018
373c1e5
add randomization to AliasMetaDataTests.assertEqualInstances
talevy Jun 13, 2018
ba1162c
Merge branch 'master' into is-write-index-setting
talevy Jun 13, 2018
a1391b2
split out is_write_index check in yaml test and skip if run before 7.0
talevy Jun 13, 2018
91deba4
add test for write index swapping
talevy Jun 13, 2018
1629aef
Merge branch 'master' into is-write-index-setting
talevy Jun 14, 2018
f8dba0c
remove unused imports
talevy Jun 14, 2018
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
Prev Previous commit
Next Next commit
update to reflect no defaulting values
  • Loading branch information
talevy committed Jun 12, 2018
commit 4755a10b6fbd0e0cec84925a9f8a566f10573a98
5 changes: 4 additions & 1 deletion docs/reference/indices/aliases.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ POST /_aliases

[IMPORTANT]
=====================================
`is_write_index` will default to `true` for an index that only has one alias which did not explicitly specify a value.
Aliases that do not explicitly set `is_write_index: true` for an index, and
only reference one index, will have that referenced index behave as if it is the write index
until an additional index is referenced. At that point, there will be no write index and
writes will be rejected.
=====================================

[float]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- is_false: test_index.aliases.test_alias.is_write_index
- match: {test_index.aliases.test_blias.search_routing: b}
- match: {test_index.aliases.test_blias.index_routing: b}
- is_false: test_index.aliases.test_blias.filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ setup:
- do:
indices.get_alias: {}

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_blias: { is_write_index: true }}
- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index_2.aliases.test_blias: { is_write_index: false }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index.aliases.test_blias: {}}
- match: {test_index_2.aliases.test_alias: {}}
- match: {test_index_2.aliases.test_blias: {}}
- match: {test_index_3.aliases: {}}

---
Expand All @@ -44,10 +44,10 @@ setup:
indices.get_alias:
name: _all

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_blias: { is_write_index: true }}
- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index_2.aliases.test_blias: { is_write_index: false }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index.aliases.test_blias: {}}
- match: {test_index_2.aliases.test_alias: {}}
- match: {test_index_2.aliases.test_blias: {}}
- is_false: test_index_3

---
Expand All @@ -61,10 +61,10 @@ setup:
indices.get_alias:
name: _all

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_blias: { is_write_index: true }}
- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index_2.aliases.test_blias: { is_write_index: false }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index.aliases.test_blias: {}}
- match: {test_index_2.aliases.test_alias: {}}
- match: {test_index_2.aliases.test_blias: {}}
- is_false: test_index_3

---
Expand All @@ -74,8 +74,8 @@ setup:
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_blias: { is_write_index: true }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index.aliases.test_blias: {}}
- is_false: test_index_2

---
Expand All @@ -88,10 +88,10 @@ setup:
indices.get_alias:
index: _all

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_blias: { is_write_index: true }}
- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index_2.aliases.test_blias: { is_write_index: false }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index.aliases.test_blias: {}}
- match: {test_index_2.aliases.test_alias: {}}
- match: {test_index_2.aliases.test_blias: {}}
- match: {myindex.aliases: {}}

---
Expand All @@ -104,10 +104,10 @@ setup:
indices.get_alias:
index: "*"

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_blias: { is_write_index: true }}
- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index_2.aliases.test_blias: { is_write_index: false }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index.aliases.test_blias: {}}
- match: {test_index_2.aliases.test_alias: {}}
- match: {test_index_2.aliases.test_blias: {}}
- match: {myindex.aliases: {}}

---
Expand All @@ -130,7 +130,7 @@ setup:
index: test_index
name: test_alias

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_alias: {}}
- is_false: test_index.aliases.test_blias
- is_false: test_index_2

Expand All @@ -142,8 +142,8 @@ setup:
index: test_index
name: _all

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_blias: { is_write_index: true }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index.aliases.test_blias: {}}
- is_false: test_index_2

---
Expand All @@ -154,8 +154,8 @@ setup:
index: test_index
name: '*'

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_blias: { is_write_index: true }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index.aliases.test_blias: {}}
- is_false: test_index_2

---
Expand All @@ -165,7 +165,7 @@ setup:
index: test_index
name: 'test_a*'

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_alias: {}}
- is_false: test_index.aliases.test_blias
- is_false: test_index_2

Expand All @@ -177,8 +177,8 @@ setup:
index: test_index
name: 'test_alias,test_blias'

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_blias: { is_write_index: true }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index.aliases.test_blias: {}}
- is_false: test_index_2

---
Expand All @@ -188,8 +188,8 @@ setup:
indices.get_alias:
name: test_alias

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index_2.aliases.test_alias: {}}
- is_false: test_index.aliases.test_blias
- is_false: test_index_2.aliases.test_blias

Expand All @@ -201,8 +201,8 @@ setup:
index: _all
name: test_alias

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index_2.aliases.test_alias: {}}
- is_false: test_index.aliases.test_blias
- is_false: test_index_2.aliases.test_blias

Expand All @@ -214,8 +214,8 @@ setup:
index: '*'
name: test_alias

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index_2.aliases.test_alias: {}}
- is_false: test_index.aliases.test_blias
- is_false: test_index_2.aliases.test_blias

Expand All @@ -227,7 +227,7 @@ setup:
index: '*2'
name: test_alias

- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index_2.aliases.test_alias: {}}
- is_false: test_index.aliases.test_alias
- is_false: test_index.aliases.test_blias
- is_false: test_index_2.aliases.test_blias
Expand All @@ -240,8 +240,8 @@ setup:
index: test_index,test_index_2
name: test_alias

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index_2.aliases.test_alias: { is_write_index: false }}
- match: {test_index.aliases.test_alias: {}}
- match: {test_index_2.aliases.test_alias: {}}
- is_false: test_index.aliases.test_blias
- is_false: test_index_2.aliases.test_blias

Expand All @@ -267,7 +267,7 @@ setup:

- match: { 'status': 404 }
- match: { 'error': 'alias [non-existent] missing' }
- match: { test_index.aliases.test_alias: { is_write_index: true } }
- match: { test_index.aliases.test_alias: { } }

---
"Existent and non-existent aliases returns 404 and the existing alias":
Expand All @@ -279,7 +279,7 @@ setup:

- match: { 'status': 404 }
- match: { 'error': 'aliases [another-non-existent,non-existent] missing' }
- match: { test_index.aliases.test_alias: { is_write_index: true } }
- match: { test_index.aliases.test_alias: { } }

---
"Getting alias on an non-existent index should return 404":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
indices.get_alias:
name: test_alias

- match: {test_index.aliases.test_alias: { is_write_index: true }}
- match: {test_index.aliases.test_alias: {}}

---
"Can't create alias with invalid characters":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ setup:
indices.get_alias:
name: alias

- match: {test_index1.aliases.alias: { is_write_index: true }}
- match: {test_index1.aliases.alias: {}}

- match: {test_index2.aliases.alias: { is_write_index: false }}
- match: {test_index2.aliases.alias: {}}

- is_false: foo

Expand All @@ -45,9 +45,9 @@ setup:
indices.get_alias:
name: alias

- match: {test_index1.aliases.alias: { is_write_index: false }}
- match: {test_index2.aliases.alias: { is_write_index: false }}
- match: {foo.aliases.alias: { is_write_index: false }}
- match: {test_index1.aliases.alias: {}}
- match: {test_index2.aliases.alias: {}}
- match: {foo.aliases.alias: {}}

---
"put alias in * index":

This comment was marked as resolved.

Expand All @@ -62,9 +62,9 @@ setup:
indices.get_alias:
name: alias

- match: {test_index1.aliases.alias: { is_write_index: false }}
- match: {test_index2.aliases.alias: { is_write_index: false }}
- match: {foo.aliases.alias: { is_write_index: false }}
- match: {test_index1.aliases.alias: {}}
- match: {test_index2.aliases.alias: {}}
- match: {foo.aliases.alias: {}}

---
"put alias prefix* index":
Expand All @@ -77,8 +77,8 @@ setup:
indices.get_alias:
name: alias

- match: {test_index1.aliases.alias: { is_write_index: false }}
- match: {test_index2.aliases.alias: { is_write_index: false }}
- match: {test_index1.aliases.alias: {}}
- match: {test_index2.aliases.alias: {}}
- is_false: foo

---
Expand All @@ -92,8 +92,8 @@ setup:
indices.get_alias:
name: alias

- match: {test_index1.aliases.alias: { is_write_index: false }}
- match: {test_index2.aliases.alias: { is_write_index: false }}
- match: {test_index1.aliases.alias: {}}
- match: {test_index2.aliases.alias: {}}
- is_false: foo

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
index: test_index
name: test_alias

- match: {test_index.aliases.test_alias: {filter: { ids : { values: ["1", "2", "3"]}}, 'index_routing': 'routing_value', 'search_routing': 'routing_value', 'is_write_index': true }}
- match: {test_index.aliases.test_alias: {filter: { ids : { values: ["1", "2", "3"]}}, 'index_routing': 'routing_value', 'search_routing': 'routing_value'}}

---
"Basic test for multiple aliases":
Expand Down Expand Up @@ -80,8 +80,8 @@
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias1: {'index_routing': 'routing_value', 'search_routing': 'routing_value', 'is_write_index': true }}
- match: {test_index.aliases.test_alias2: {'index_routing': 'routing_value', 'search_routing': 'routing_value', 'is_write_index': true }}
- match: {test_index.aliases.test_alias1: {'index_routing': 'routing_value', 'search_routing': 'routing_value'}}
- match: {test_index.aliases.test_alias2: {'index_routing': 'routing_value', 'search_routing': 'routing_value'}}

---
"Remove alias":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ setup:
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias: {'index_routing': 'routing', 'search_routing': 'routing', 'is_write_index': true }}
- match: {test_index.aliases.test_alias: {'index_routing': 'routing', 'search_routing': 'routing'}}

---
"Index Routing":
Expand All @@ -37,7 +37,7 @@ setup:
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias: {'index_routing': 'index_routing', 'is_write_index': true }}
- match: {test_index.aliases.test_alias: {'index_routing': 'index_routing'}}

---
"Search Routing":
Expand All @@ -55,7 +55,7 @@ setup:
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias: {'search_routing': 'search_routing', 'is_write_index': true }}
- match: {test_index.aliases.test_alias: {'search_routing': 'search_routing'}}

---
"Index, Default Routing":
Expand All @@ -74,7 +74,7 @@ setup:
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias: {'index_routing': 'index_routing', 'search_routing': 'routing', 'is_write_index': true }}
- match: {test_index.aliases.test_alias: {'index_routing': 'index_routing', 'search_routing': 'routing'}}

---
"Search, Default Routing":
Expand All @@ -93,7 +93,7 @@ setup:
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias: {'index_routing': 'routing', 'search_routing': 'search_routing', 'is_write_index': true }}
- match: {test_index.aliases.test_alias: {'index_routing': 'routing', 'search_routing': 'search_routing'}}

---
"Index, Search, Default Routing":
Expand All @@ -113,7 +113,7 @@ setup:
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias: {'index_routing': 'index_routing', 'search_routing': 'search_routing', 'is_write_index': true }}
- match: {test_index.aliases.test_alias: {'index_routing': 'index_routing', 'search_routing': 'search_routing'}}

---
"Numeric Routing":
Expand All @@ -131,5 +131,5 @@ setup:
indices.get_alias:
index: test_index

- match: {test_index.aliases.test_alias: {'index_routing': '5', 'search_routing': '5', 'is_write_index': true }}
- match: {test_index.aliases.test_alias: {'index_routing': '5', 'search_routing': '5'}}

Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ void addIndex(IndexMetaData indexMetaData) {
}

public void computeAndValidateWriteIndex() {
List<IndexMetaData> writeIndices = referenceIndexMetaDatas.stream().filter(idxMeta -> Boolean.TRUE.equals(idxMeta.getAliases().get(aliasName)))
List<IndexMetaData> writeIndices = referenceIndexMetaDatas.stream()
.filter(idxMeta -> Boolean.TRUE.equals(idxMeta.getAliases().get(aliasName).writeIndex()))
.collect(Collectors.toList());
if (writeIndices.size() == 1) {
writeIndex.set(writeIndices.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ private SortedMap<String, AliasOrIndex> buildAliasAndIndexLookup() {
}
}
aliasAndIndexLookup.values().stream().filter(AliasOrIndex::isAlias)
.forEach(alias -> ((AliasOrIndex.Alias) alias).computeAndValidateWriteIndex();
.forEach(alias -> ((AliasOrIndex.Alias) alias).computeAndValidateWriteIndex());
return aliasAndIndexLookup;
}

Expand Down