In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to use elasticsearch cluster cluster". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use elasticsearch cluster cluster" can help you solve the problem.
Node DiscoveryNode
The first is the node (DiscoveryNode), where the node is different from the node mentioned earlier, it is only a logical node in the cluster, and it is only the description information of an actual node. It implements Streamable interface and serializable interface, which can be transmitted on physical nodes. The following figure shows its field:
You can see that it is just an information description of a node. Each node in the cluster is abstracted into a DiscoveryNode, and these DiscoveryNode are encapsulated in DiscoveryNodes, while providing operations such as finding, connecting, and so on. In this way, the cluster maintains the information of all nodes, and the nodes can operate according to the state of the cluster.
Cluster blocking
The cluster also needs to have a mechanism for cluster blocking, because clusters in different states can perform different operations. For example, when there is no master node, all master operations must be stopped. The current task is to elect master, and a block will be raised to notify all nodes in the cluster. Different from the synchronization in the same jvm, different nodes are in different jvm, so the synchronization mechanism of jvm can not be used, so we can only use this blocking mechanism to coordinate between nodes. Part of its code is as follows:
Public class ClusterBlock implements Serializable, Streamable, ToXContent {private int id; private String description; private EnumSet levels; private boolean retryable; private boolean disableStatePersistence = false; private RestStatus status; ClusterBlock () {} public ClusterBlock (int id, String description, boolean retryable, boolean disableStatePersistence, RestStatus status, EnumSet levels) {this.id = id; this.description = description; this.retryable = retryable; this.disableStatePersistence = disableStatePersistence This.status = status; this.levels = levels;}}
Blocking consists of three parts, description (description), blocking level (READ (0), WRITE (1), METADATA (2)), and restful status code RestStatus. Blocking level is mainly used to block the operation of index between nodes. For example, when an index is in the recovery process, its state is MATEDATA level, so it can not be read or written at this time. RestStatus is mainly used for blocking restful requests. Finally, I would like to talk about the ack mechanism, many operations of the cluster require the response of nodes. So cluster defines the request and response interfaces for ack. All requests that require ack can be implemented by implementing this ack interface. In addition, the cluster also involves matedata and routing, which are actually aimed at data (index). For example, matedata is mainly mapping,index and alias-related metadata, so these two parts will analyze the data functions.
ClusterService interface
After talking about DiscoveryNode and block, then through the clusterService interface, its main function is to provide external calls. This API mainly provides add and remove of Listener,block and update submission of cluster status. Cluster is only a theoretical entity, in fact, it does not exist, all the functions are accomplished by each node. Therefore, the main method of the clusterService interface is the operation of the cluster status listener. Its class diagram:
Here we focus on the implementation of submitStateUpdateTask. For a node, if it detects an update to the cluster status, if it is a master, it needs to be released to other nodes. The code is as follows:
Public void submitStateUpdateTask (final String source, Priority priority, final ClusterStateUpdateTask updateTask) {if (! lifecycle.started ()) {return;} try {/ / encapsulated as updateTask final UpdateTask task = new UpdateTask (source, priority, updateTask); / / tasks that will time out if (updateTask instanceof TimeoutClusterStateUpdateTask) {final TimeoutClusterStateUpdateTask timeoutUpdateTask = (TimeoutClusterStateUpdateTask) updateTask UpdateTasksExecutor.execute (task, threadPool.scheduler (), timeoutUpdateTask.timeout () New Runnable () {@ Override public void run () {threadPool.generic () .execute (new Runnable () {@ Override public void run () {timeoutUpdateTask.onFailure (task.source (), new ProcessClusterEventTimeoutException (timeoutUpdateTask.timeout ()) Task.source ()) }});}});} else {updateTasksExecutor.execute (task) }} catch (EsRejectedExecutionException e) {/ / ignore cases where we are shutting down..., there is really nothing interesting / / to be done here... If (! lifecycle.stoppedOrClosed ()) {throw e;}
The above code logic is simple, encapsulating and running the submitted task. What is running here is ClusterStateUpdateTask, which has many implementations and cannot be explained one by one. But its method speaks for itself, and its class diagram is as follows:
The main logical implementation of the subclass is in the execute method, such as the implementation in handleMasterGone in ZenDiscovery. If the master is lost, there will be a master election or an attempt to join a newly formed cluster. These can be seen in the later analysis.
This is the end of the content about "how to use elasticsearch Cluster cluster". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.