Beware of ttserver (Tokyo tyrant) data loss during system crash or power failure

Source: Internet
Author: User

[ArticleAuthor: Sun Li link: http://www.cnblogs.com/sunli/ updated by: 2010-09-03]

In my previous article, I introduced the extremely high performance of ttserver and the possible unstable factors in the case of large data volumes, however, if the data is not very large (generally, it should not exceed the memory), it is very suitable to use ttserver. Recently, in the company's testing environment, the ttserver data was all empty. I asked the O & M department to find out that an unexpected power failure occurred. Some testing systems recorded logs that could be recovered, if some logs are not recorded, the data will be lost forever. Fortunately, the test environment is used. One ttserver has been running for more than a year, and all data is lost.

Is it a ttserver problem or a system problem??

Next let's test it in detail. Start two ttservers on the test server without logging.

 
Ttserver-port 1978-DMN-PID/data/ttserver/test1/Pid/data/ttserver/test1/casket. tch # bnum = 1000000 ttserver-port 1979-DMN-PID/data/ttserver/Test2/Pid/data/ttserver/Test2/casket. tch # bnum= 1000000

 

Write 10000 pieces of data to the two ports respectively, kill-9 PID drop process, and then start ttserver to check whether the data is lost and no loss is found. Here we can judge that the ttserver will not lose data when it crashes unexpectedly.

Next we will test the system crash and power-off tests, first use the followingCodeWrite 50000 data records to the ttserver on both ports:

  <?  PHP
$ Mem = New Memcache ();
$ Mem -> Addserver ( " 192.168.13.169 " , 1979 , False , 1 , 100 );
$ Mem -> Addserver ( " 192.168.13.169 " , 1978 , False , 1 , 100 );
$ Start = Microtime ( True );
For ( $ I = 0 ; $ I < 50000 ; $ I ++ ){
$ Mem -> Add ( " Bbs_pass _ " . $ I , " Info 127122222 a B c d {....} " );
}
Print_r ( $ Mem -> Getextendedstats ());
Echo Microtime ( True ) - $ Start ;
?>

 

Print out that each of the two ttservers has 30000 pieces of data, and immediately unplug the power of the machine. Start the machine. Start ttserver. Telnet to connect to the ttserver and find that only 10000 pieces of data are left on the ttserver on both ports.

Conclusion: If the ttserver crashes unexpectedly and the process kill-9 directly, data will not be lost. If the system loses power, data will be lost. This should be because ttserver only writes data to the file system and is not flushed to the disk.

Solution

Ttserver actually provides a synchronization command sync (the author must know the problem of data loss, so this command is available), which can flush data to the disk, but is called every time, performance will drop sharply. In order not to reduce performance and ensure data reliability, logs can be recorded to recover data from logs when an unexpected power failure occurs. You can also use master-slave replication, master data loss, and slave data (recommended by myself). You can also regularly execute the sync command.

Although the power is cut off and the system crashes unexpectedly, it should be considered if it is an online system. Otherwise, it will be too late to regret it.

 

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.