[Source code analysis] The startup process of elastic search 8.0.0 (4)

This article continues to analyze the startup process

1、ShardLimitValidator

The maximum number of shards on each node in the cluster is 1000 by default

2、MetadataCreateIndexService

Mainly responsible for handling index creation

3、ActionModule

There is an input parameter IndexScopedSettings

Indicates some built-in parameter values ​​at the index level, a total of 120, many of which are frequently touched.

We choose a few typical ones. such as

index.search.slowlog.threshold.fetch.trace -> {Setting@12155} "{
  "key" : "index.search.slowlog.threshold.fetch.trace",
  "properties" : [
    "Dynamic",
    "IndexScope"
  ],
  "is_group_setting" : false,
  "default" : "-1"
}"
index.number_of_shards -> {Setting@12205} "{
  "key" : "index.number_of_shards",
  "properties" : [
    "Final",
    "IndexScope"
  ],
  "is_group_setting" : false,
  "default" : "1"
}"

The default shard is 1

The built-in Action of the system will be placed in the ActionRegistry, and Action is to encapsulate various es operations into this object.

public abstract class TransportAction<Request extends ActionRequest, Response extends ActionResponse> 

The declaration of the top-level abstract class, its 2 generics, request and return, is the abstraction of each api that we often use as the caller of es. such as

public class TransportCreateIndexAction extends TransportMasterNodeAction<CreateIndexRequest, CreateIndexResponse> 
public abstract class HandledTransportAction<Request extends ActionRequest, Response extends ActionResponse>
        extends TransportAction<Request, Response> 
public class TransportBulkAction extends HandledTransportAction<BulkRequest, BulkResponse>
public class TransportSearchAction extends HandledTransportAction<SearchRequest, SearchResponse> 

In addition to the above, there will be two configurations added to the cluster configuration, one of which is the default automatic index creation is true. Can't imagine what circumstances do not allow creation?

The verification of the mapping request, the verification of the alias request. Both of these items are obtained from the plugin.

It will also create a RestController object whose core purpose is Dispatches HTTP requests, and find a suitable handler for processing. How to find it, mainly based on the uri params method in the request. Finally, the RestHandler is found. This class is an interface, the core method inside

@Override
    public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
        // execute the action
        action.accept(channel);
}

4、NetworkModule

Analyze the loaded NetworkPlugin. 4 related

Finally obtained

final Transport transport = networkModule.getTransportSupplier().get();

The final instantiated object types of transport are as follows

What does transport do?

It is used to handle the connections between nodes within the cluster. For example, query request, request from one node to another node is completed through transport. And it is done in an asynchronous way, which will not cause thread blocking. Its transmission is based on tcp,

5、UpgradeService

MetadataIndexUpgradeService is mainly responsible for upgrading the metadata of the remaining indexes to the latest version of the current cluster. The typical usage scenario is when the cluster is upgraded or when the dangling index is imported into the cluster

TemplateUpgradeService describes template-related, and I personally use less templates. However, it is said that some companies have dedicated es maintenance teams, and there are many template related APIs in frequently operated APIs. The service describes that when a node is about to join the cluster, the template will be upgraded when the plugin is installed halfway through.

6、RepositoriesModule+SnapshotsService

The RepositoriesModule module is created to prepare for snapshot and restore. Snapshots are incrementally stored. You can store different snapshots of an index or different snapshots of a cluster. Where is it stored? It can be stored locally or anywhere on the cloud disk. Type as shown

When the SnapshotsService is created, a handler for the snapshot state change is registered with the transportservice

A shard-level snapshot service is also created, which is responsible for managing the start and stop of snapshot operations on shards

Then create the restore service RestoreService, which mainly deals with the restoration of snapshots

7、DiscoveryModule

This module means that nodes will find each other to form a cluster. The main scenario is when es is started or the new master node has just been elected. The discover process is divided into 2 steps. The first step is to provide a seed host list in the setting. Then each node will try to connect to the machines in the list and see if it is a node or a node that has the potential to become a master. . The second step, if the first step is successful, node will share the master candidate node information it has obtained with the successfully connected node. The successfully connected nodes will also return the addresses of their partners one by one. Then node will try to connect with these newly returned addresses

8. NodeClient initialization

Clients that perform various operations on the current node

Finally, initialize the HTTP handler 

By default, almost all actions of es are processed through HTTP. This screenshot is only partial

public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
        List<AbstractCatAction> catActions = new ArrayList<>();
        Consumer<RestHandler> registerHandler = handler -> {
            if (handler instanceof AbstractCatAction) {
                catActions.add((AbstractCatAction) handler);
            }
            restController.registerHandler(handler);
        };
        registerHandler.accept(new RestAddVotingConfigExclusionAction());
        registerHandler.accept(new RestClearVotingConfigExclusionsAction());
        registerHandler.accept(new RestMainAction());
        registerHandler.accept(new RestNodesInfoAction(settingsFilter));
        registerHandler.accept(new RestRemoteClusterInfoAction());
        registerHandler.accept(new RestNodesStatsAction());
        registerHandler.accept(new RestNodesUsageAction());
        registerHandler.accept(new RestNodesHotThreadsAction());
        registerHandler.accept(new RestClusterAllocationExplainAction());
        registerHandler.accept(new RestClusterStatsAction());
        registerHandler.accept(new RestClusterStateAction(settingsFilter));
        registerHandler.accept(new RestClusterHealthAction());
        registerHandler.accept(new RestClusterUpdateSettingsAction());
        registerHandler.accept(new RestClusterGetSettingsAction(settings, clusterSettings, settingsFilter));
        registerHandler.accept(new RestClusterRerouteAction(settingsFilter));
        registerHandler.accept(new RestClusterSearchShardsAction());
        registerHandler.accept(new RestPendingClusterTasksAction());
        registerHandler.accept(new RestPutRepositoryAction());
        registerHandler.accept(new RestGetRepositoriesAction(settingsFilter));
        registerHandler.accept(new RestDeleteRepositoryAction());
        registerHandler.accept(new RestVerifyRepositoryAction());
}

Finally node instance is up! ! ! ! !

 

9. Summary

In the process of creating node, I saw a lot of dependency injection-related objects, such as ending with Module, bind method, etc. Yes, es uses Guice dependency injection framework to complete the dependency between various objects.

For the detailed use of Guice, additional information is needed.

Friends who like the source code search: red ladder, make progress together

Guess you like

Origin blog.csdn.net/weixin_39394909/article/details/108438968