Fastdfs Study Selection Master process

Source: Internet
Author: User
Tags sorts

Overview:
(1) Each tracker service invokes the Tracker_relationship_init function at startup to start a thread relationship_thread_entrance. The thread will confirm the relationship of each tracker every few seconds, and if leader changes or goes down, the leader will be re-elected.
(2) Call flow
Main function
|-int Tracker_relationship_init ()
Creating Threads
if (Result=pthread_create (&tid, &thread_attr, \
Relationship_thread_entrance, NULL))! = 0)
Invoke the main selection process
|--static int Relationship_select_leader ()
|--Loop Traversal g_tracker_servers.servers
Tracker_mem_get_status gets the state. Protocol Request Tracker_proto_cmd_tracker_get_status




Qsort (Trackerstatus, Count, sizeof (trackerrunningstatus), \//Sort
Relationship_cmp_tracker_status);


Notice if it's yourself,
static int relationship_notify_leader_changed (ConnectionInfo *pleader)
|--relationship_notify_next_leader//loop Traversal notification send Tracker_proto_cmd_tracker_notify_next_leader 66 protocol
|--relationship_commit_next_leader//Loop Traversal commit tracker_proto_cmd_tracker_commit_next_leader 67 protocol


(3) Select the main process
Relationship_select_leader () function
A) the Tracker_mem_get_status () function is called to perform the operation of the main selection.
b) The Tracker_mem_get_status function first iterates through all the tracker server structures, initiates a TCP connection to all tracker servers, and sends
Tracker_proto_cmd_tracker_get_status command to get the status of each TRACKER server, each TRACKER server receives the command and sends its own state to the function ( Includes information about whether the tracker server is leader, which saves the information to the data structure of the tracker server.
c) The function then sorts the status of each tracker server (Qsort, which is ascending by default), sorts it by whether it is leader, followed by run time, time interval, port, etc.
D) The last member of the sorted array is leader, taking out the state of the leader.
E) If leader is itself, use the Relationship_notify_leader_changed function to notify each tracker server, if it is not their own, the value of leader set to select the value of leader.




(4) The notification process after selecting leader
The function call relationship is as follows:
Relationship_notify_leader_changed ()
->relationship_notify_next_leader
->relationship_commit_next_leader ()




If the tracker leader has changed, call the Relationship_notify_leader_changed function to notify each tracker, and the function will continue to call Relationship_notify_next_ Leader and Relationship_commit_next_leader functions, see what these two functions do, respectively.




Relationship_commit_next_leader ():
(1) Call the Do_notify_leader_changed function to send the Tracker_proto_cmd_tracker_notify_next_leader command to the TRACKER server.
After the tracker server receives the command, the Tracker_deal_notify_next_leader () function is called to process the corresponding request.




Relationship_commit_next_leader ():
(1) Call the Do_notify_leader_changed function to send the Tracker_proto_cmd_tracker_commit_next_leader command to the TRACKER server.
After the tracker server receives the command request, the Tracker_deal_commit_next_leader () function is called to process the corresponding request.

Fastdfs Study Selection Master process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.