Defer node environment construction #54919
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Today we construct the node environment relatively early in the node construction process, before we have even constructed the final environment, which means before the final settings are available. Rather, we should defer constructing the node environment until the final environment is available. This commit does that. This helps delay node environment construction until after the node roles are properly determined, which is important since the node environment does some checks on the basis of whether or not the node is neither a data nor a master node (such nodes should not have index metadata nor shard data on disk). Note that a consequence of this is that the initial log line that displays the node name, node ID, and cluster name does not appear until later in startup (after we have loaded plugins). This seems okay.