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 infrastructure for managing system indices #65604

Merged

Conversation

pugnascotia
Copy link
Contributor

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 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.
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Nov 30, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Copy link
Member

@jaymode jaymode left a 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()) {
Copy link
Member

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) {
Copy link
Member

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?

- 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
@pugnascotia pugnascotia requested a review from jaymode December 2, 2020 12:34
@pugnascotia
Copy link
Contributor Author

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 SystemIndexManager.

Copy link
Member

@jaymode jaymode left a 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);
Copy link
Member

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);
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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);
Copy link
Member

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

public SystemIndexDescriptor build() {
String mappings = mappingsBuilder == null ? null : Strings.toString(mappingsBuilder);

Strings.requireNonEmpty(indexPattern, "indexPattern must be supplied");
Copy link
Member

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);
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Run all upgrades at once, and use a GroupedActionListener to release the
lock once all have completed.
@pugnascotia pugnascotia requested a review from jaymode December 3, 2020 14:09
Copy link
Member

@jaymode jaymode left a 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));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
} else {
isUpgradeInProgress.set(false);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! 😅

@pugnascotia pugnascotia merged commit cbd5d12 into elastic:master Dec 4, 2020
@pugnascotia pugnascotia deleted the 61656-auto-create-system-indices-infra branch December 4, 2020 09:24
pugnascotia added a commit to pugnascotia/elasticsearch that referenced this pull request Dec 7, 2020
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.
pugnascotia added a commit that referenced this pull request Dec 9, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >enhancement Team:Core/Infra Meta label for core/infra team v7.11.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants