-
Notifications
You must be signed in to change notification settings - Fork 25k
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 infrastructure for managing system indices #65604
Add infrastructure for managing system indices #65604
Conversation
Part of elastic#61656. Add the necessary support for automatically creating and updating system indices. This works by making it possible to create a system index descriptor with all the information needed to manage the mappings, settings and aliases. Follow-up work will opt existing indices into this framework.
Pinging @elastic/es-core-infra (Team:Core/Infra) |
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 took a brief look through the PR and left a few comments.
|
||
final SystemIndexDescriptor descriptor = systemIndices.findMatchingDescriptor(indexName); | ||
|
||
if (descriptor != null && descriptor.isAutomaticallyManaged()) { |
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.
Can we simplify this method a bit? We don't really share logic between non-system index creation and system index creation as far as I can see so I think we can test for the non system case and simply return the update request there?
.waitForActiveShards(request.waitForActiveShards()); | ||
|
||
if (isSystemIndex) { |
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.
Similar to the comment in AutoCreateAction
, can we break up the system and non-system case since we don't really need to share anything between the two cases?
server/src/main/java/org/elasticsearch/indices/SystemIndexManager.java
Outdated
Show resolved
Hide resolved
- Separate logic for building create index requests into sytem-index and non-system-index versions - Use an AtomicBoolean to prevent updates to system index mappings overloading the master
…-system-indices-infra
Note to reviewers: I'm holding off creating follow-up PRs to port over existing systems indices until this is merged, so I'd appreciate any and all feedback. In particular, some guidance would be good for setting up a BWC test that exercises the mappings upgrade logic in |
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 left some more feedback. I think this is close. Regarding testing overall, I think it might be hard without an index that uses this framework. So I think once we get this PR in and migrate one to use this then we can add tests that attempt to put mappings or settings that would trigger a violation.
updateRequest.aliases(Set.of(new Alias(aliasName))); | ||
} | ||
|
||
logger.info("Auto-creating system index {}", concreteIndexName); |
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 make this a debug log like the regular message
.stream() | ||
.map(entry -> "[" + entry.getKey() + "] -> " + entry.getValue()) | ||
.collect(Collectors.joining(", ")); | ||
logger.warn(message); |
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.
On backport, we will need to make this a deprecation warning
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.
Can I clarify - in the backport, should this raise a deprecation warning but not fail the request?
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.
Correct on backport this should result in a deprecation warning and still allow the request to go through.
+ violations | ||
+ ": system indices can only use mappings from their descriptors, " | ||
+ "but the mappings in the request did not match those in the descriptors(s)"; | ||
logger.warn(message); |
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.
On backport, we will need to make this a deprecation warning
server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java
Show resolved
Hide resolved
public SystemIndexDescriptor build() { | ||
String mappings = mappingsBuilder == null ? null : Strings.toString(mappingsBuilder); | ||
|
||
Strings.requireNonEmpty(indexPattern, "indexPattern must be supplied"); |
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.
Can all validation be moved into the constructor?
originSettingClient.admin().indices().putMapping(request, new ActionListener<>() { | ||
@Override | ||
public void onResponse(AcknowledgedResponse acknowledgedResponse) { | ||
isUpgradeInProgress.set(false); |
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.
this sets to false early. There can still be in flight items and isUpgradeInProgress would be incorrect. You may want to use something like a GroupedActionListener
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'm not sure I follow. The upgradeIndexMetadata
method is called once for each index that needs upgraded, and the first thing the method does is attempt to set isUpgradeInProgress
to true
. So only one index will be upgraded, and the rest need to wait until isUpgradeInProgress
becomes false again. I wrote it that way so as to be cautious about adding load to the master.
Were you thinking that we'd dispatch all the mapping updates in one go, and use a GroupedActionListener
to release the isUpgradeInProgress
once they'd all finished?
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'm not sure I follow.
That's because I did not follow the code properly. I think it would be best to fire off all of the upgrades at once rather than sequentially since IIRC the code is computing everything that needs upgraded each time.
Were you thinking that we'd dispatch all the mapping updates in one go, and use a GroupedActionListener to release the isUpgradeInProgress once they'd all finished?
Yes that is what I was thinking. I wanted to avoid resending each one every time there was a cluster state update if other cluster state updates happened prior to the mapping updates that we had previously sent.
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've reworked the locking and upgrading to use a GroupedActionListener
.
…-system-indices-infra
Run all upgrades at once, and use a GroupedActionListener to release the lock once all have completed.
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.
Left one comment. Otherwise LGTM. Thanks for the iterations!
); | ||
|
||
descriptors.forEach(descriptor -> upgradeIndexMetadata(descriptor, listener)); | ||
} |
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.
} | |
} else { | |
isUpgradeInProgress.set(false); | |
} |
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 catch! 😅
Part of elastic#61656. Add the necessary support for automatically creating and updating system indices. This works by making it possible to create a system index descriptor with all the information needed to manage the mappings, settings and aliases. Follow-up work will opt existing indices into this framework.
Backport of #65604. Part of #61656. Add the necessary support for automatically creating and updating system indices. This works by making it possible to create a system index descriptor with all the information needed to manage the mappings, settings and aliases. Follow-up work will opt existing indices into this framework.
Part of #61656.
Add the necessary support for automatically creating and updating system
indices. This works by making it possible to create a system index
descriptor with all the information needed to manage the mappings,
settings and aliases.
Follow-up work will opt existing indices into this framework.