-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Refactor AliasOrIndex abstraction. #53982
Refactor AliasOrIndex abstraction. #53982
Conversation
In order to prepare the `AliasOrIndex` abstraction for the introduction of data streams, the abstraction needs to be made more flexible, because currently it really can be only an alias or an index. * Introduced a `AliasOrIndex.Type` enum to indicate what a `AliasOrIndex` instance is. * Replaced the `isAlias()`` method that returns a boolean with the `getType()`` method that returns the new Type enum. * Moved `getWriteIndex()`` up from the `AliasOrIndex.Alias` to the `AliasOrIndex` interface. * Moved `g`etAliasName()`` up from the `AliasOrIndex.Alias` to the `AliasOrIndex` interface and renamed it to `getName()``. * Removed unnecessary casting to `AliasOrIndex.Alias` by just checking the `getType()`` method. Finally `AliasOrIndex` should be renamed to reflect that it can be more than just an index or alias, since in the near future it can also be a data stream. The name AliasOrIndexOrDataStream is not appealing to me. We can rename it to `Namespace`, but that sounds to generic to me. `ResolvedIndicesExpression` sounds better to me, since it reflects more what it is (an expression from api that has been resolved to alias/index/datasteam), but the name itself is a bit on the long side. Relates to elastic#53100
Pinging @elastic/es-core-features (:Core/Features/Data streams) |
throw new IllegalArgumentException("source alias does not exist"); | ||
} | ||
if (aliasOrIndex.isAlias() == false) { | ||
if (indexSpace.getType() != IndexSpace.Type.ALIAS) { | ||
throw new IllegalArgumentException("source alias is a concrete index"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a lot of error messages such as this one that assume only alias or index types would benefit from wording changes that accommodate data streams, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I will go over these checks and messages and adjust.
if (indexOrAlias != null && indexOrAlias.isAlias()) { | ||
AliasOrIndex.Alias alias = (AliasOrIndex.Alias) indexOrAlias; | ||
indexMetaData = alias.getWriteIndex(); | ||
IndexSpace indexOrAlias = metaData.getAliasAndIndexLookup().get(indexRequest.index()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably want to rename that variable from indexOrAlias
. Can be done in a later PR, though.
* @return whether this alias/index is hidden or not | ||
* A write index is a dedicated concrete index, that accepts all the new documents that belong to an index space. | ||
* | ||
* A write index may also be a regular concrete index of a index space and may be therefor also be returned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "may be therefor also be returned" -> "may therefore also be returned"
@@ -14,7 +14,7 @@ | |||
import org.elasticsearch.action.search.SearchRequest; | |||
import org.elasticsearch.action.support.IndicesOptions; | |||
import org.elasticsearch.cluster.metadata.AliasMetaData; | |||
import org.elasticsearch.cluster.metadata.AliasOrIndex; | |||
import org.elasticsearch.cluster.metadata.IndexSpace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we want to eventually rename this class to something like IndexSpaceResolver
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I left a few comments that are minor, not actionable, and/or addressable in later PRs.
renamed `MetaData#aliasAndIndexLookup` field (and getter) to `MetaData#indexSpaceLookup`.
I wonder if we should use |
We considered a bunch of different options including |
Dan and I did came up with the following alternative:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I left a few smaller comments to consider.
@@ -130,8 +130,8 @@ public void testAuthorizeClusterAction() { | |||
|
|||
public void testAuthorizeIndexAction() { | |||
CustomAuthorizationEngine engine = new CustomAuthorizationEngine(); | |||
Map<String, AliasOrIndex> aliasOrIndexMap = new HashMap<>(); | |||
aliasOrIndexMap.put("index", new Index(IndexMetaData.builder("index") | |||
Map<String, IndexAbstraction> indexSpaceMap = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "Space" from variable name?
@@ -341,7 +341,7 @@ public void testRolloverClusterState() throws Exception { | |||
IndexMetaData rolloverIndexMetaData = rolloverMetaData.index(newIndexName); | |||
assertThat(rolloverIndexMetaData.getNumberOfShards(), equalTo(numberOfShards)); | |||
|
|||
AliasOrIndex.Alias alias = (AliasOrIndex.Alias) rolloverMetaData.getAliasAndIndexLookup().get(aliasName); | |||
IndexAbstraction alias = rolloverMetaData.getIndicesLookup().get(aliasName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: also verify type (since we no longer do the cast).
@@ -212,7 +212,7 @@ public void testValidation() { | |||
assertThat(exception.getMessage(), equalTo("source alias [" + aliasWithNoWriteIndex + "] does not point to a write index")); | |||
exception = expectThrows(IllegalArgumentException.class, () -> | |||
MetaDataRolloverService.validate(metaData, randomFrom(index1, index2))); | |||
assertThat(exception.getMessage(), equalTo("source alias is a concrete index")); | |||
assertThat(exception.getMessage(), equalTo("source alias is not an alias")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the change to the exception message is not really a big issue. But with data streams also appearing, it could be nice to stick to the old message since that would give you some information on whether it is a datastream or concrete index. I think we could easily generate such a message by adding a display name ("concrete index") to the IndexAbstract.Type enum?
Also, this does make me wonder if Type.INDEX
should be Type.CONCRETE_INDEX
for consistency with that display name? Not truly important to me, feel free to ignore this part.
} else if (aliasInfo.isAlias() == false) { | ||
logger.warn("service provider index [{}] exists as a concrete index, but it should be an alias", ALIAS_NAME); | ||
} else if (aliasInfo.getType() != IndexAbstraction.Type.ALIAS) { | ||
logger.warn("service provider index [{}] does not exist as an alias, but it should be", ALIAS_NAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment on retaining the original message here.
@@ -83,8 +83,8 @@ public void setUpTests() { | |||
ClusterSettings clusterSettings = new ClusterSettings(nodeSettings(), new HashSet<>(Collections.singletonList( | |||
MlConfigMigrationEligibilityCheck.ENABLE_CONFIG_MIGRATION))); | |||
MetaData metaData = mock(MetaData.class); | |||
SortedMap<String, AliasOrIndex> aliasOrIndexSortedMap = new TreeMap<>(); | |||
when(metaData.getAliasAndIndexLookup()).thenReturn(aliasOrIndexSortedMap); | |||
SortedMap<String, IndexAbstraction> indexSpaceSortedMap = new TreeMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "Space" from variable name?
} else if (aliasOrIndex.isAlias()) { | ||
throw new IllegalStateException("concrete index [" + concreteIndexName + "] is an alias but should not be"); | ||
} else if (indexAbstraction.getType() != IndexAbstraction.Type.INDEX) { | ||
throw new IllegalStateException("concrete index [" + concreteIndexName + "] is not an index but should be"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also include the display name of the actual type here.
In order to prepare the `AliasOrIndex` abstraction for the introduction of data streams, the abstraction needs to be made more flexible, because currently it really can be only an alias or an index. * Renamed `AliasOrIndex` to `IndexAbstraction`. * Introduced a `IndexAbstraction.Type` enum to indicate what a `IndexAbstraction` instance is. * Replaced the `isAlias()` method that returns a boolean with the `getType()` method that returns the new Type enum. * Moved `getWriteIndex()` up from the `IndexAbstraction.Alias` to the `IndexAbstraction` interface. * Moved `getAliasName()` up from the `IndexAbstraction.Alias` to the `IndexAbstraction` interface and renamed it to `getName()`. * Removed unnecessary casting to `IndexAbstraction.Alias` by just checking the `getType()` method. Relates to elastic#53100
Backport of #53982 In order to prepare the `AliasOrIndex` abstraction for the introduction of data streams, the abstraction needs to be made more flexible, because currently it really can be only an alias or an index. * Renamed `AliasOrIndex` to `IndexAbstraction`. * Introduced a `IndexAbstraction.Type` enum to indicate what a `IndexAbstraction` instance is. * Replaced the `isAlias()` method that returns a boolean with the `getType()` method that returns the new Type enum. * Moved `getWriteIndex()` up from the `IndexAbstraction.Alias` to the `IndexAbstraction` interface. * Moved `getAliasName()` up from the `IndexAbstraction.Alias` to the `IndexAbstraction` interface and renamed it to `getName()`. * Removed unnecessary casting to `IndexAbstraction.Alias` by just checking the `getType()` method. Relates to #53100
In order to prepare the
AliasOrIndex
abstraction for the introduction of data streams,the abstraction needs to be made more flexible, because currently it really can be only
an alias or an index.
The following changes were made:
AliasOrIndex
toIndexAbstraction
.IndexSpace.Type
enum to indicate what aIndexSpace
instance is.isAlias()
method that returns a boolean with thegetType()
method that returns the new Type enum.getWriteIndex()
up from theIndexSpace.Alias
to theIndexSpace
interface.getAliasName()
up from theIndexSpace.Alias
to theIndexSpace
interface and renamed it togetName()
.IndexSpace.Alias
by just checking thegetType()
method.Relates to #53100