Master-slave replication protocol analysis of Tokyo tyrant (ttserver)

Source: Internet
Author: User

Master-slave replication protocol analysis of Tokyo tyrant (ttserver)
The replication protocol of Tokyo tyrant (ttserver)
[ArticleAuthor: Sun Li link: http://www.cnblogs.com/sunli/ updated by: 2010-06-26]

Purpose

Ttserver already comes with the master-slave replication function, which runs very stably and efficiently, so that we can use ttserver to achieve high reliability. Why should I analyze its replication protocol?

1. data needs to be synchronized from ttserver to a heterogeneous database in real time. For example, MySQL and other nosql databases.

2. seamless data migration. If you need to seamlessly switch from the ttserver database to other databases, you can use this replication protocol.

3. for high-performance asynchronous processing queues, you can set the primary database to the mem type and use the synchronization protocol to obtain data. This is actually a queue and a persistent queue service. 4. Write a service for other storage, and use ttserver as the slave. Protocol Structure Analysis Let's start with the data flow process:
  1. Connect the client (slave) to the server (master)
  2. After the slave connection is successful, the Server Load balancer sends it to the master.
    + -------------------------------------- +
    | 0xc8 | 0xa0 | slave RTS | slave Sid |
    | 1 byte | 1 byte | 8 bytes | 4 bytes |
    + -------------------------------------- +

  3. After receiving the message, the master wants the client to send the message:
    + --------- +
    | Mid |
    | 4 bytes |
    + --------- +
  4. After the Server Load balancer receives the message, it can obtain the master SID of the server.
  5. Replication starts here. The master continues to want the client to repeatedly send the copied data object.
    + ------ +
    | 0xca | no operation
    | 1 byte |
    + ------ +
    Send an operation item:
    + -------------------------------------------------- +
    | 0xc9 | RTS | rsid | rsize | data |
    | 1 byte | 8 bytes | 4 bytes | 4 bytes | rsize bytes |
    + -------------------------------------------------- +

    Data structure:
    + ----------------------------------- +
    | Magic | cmd | [data] |
    | 1 bytes | 1 bytes | key-value data |
    + ----------------------------------- +
    CMD indicates various operation types, such as put putkeep.

  6. Slave cyclically accepts the data for OK data.


Protocol Implementation
The replication protocol of ttserver is very simple, because the copy protocol is not officially written to the document, and other operations have documentation. You need to analyze its cCodeStructure analysis is very simple. I will make some implementations available.Www.cnblogs.com/sunli/announcement

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.