Hbase-0.98.6 Source Analysis--nonce Management mechanism source code Analysis

Source: Internet
Author: User

In the "Hbase-0.98.6 source analysis--put Writing client end Process" This article, we introduced the put write operation in the client side of the operation process, in the introduction of the Submit () method, there is a strange noun--nonce mechanism, Today, we will introduce the indispensable management mechanism of the nonce.

HBase has a very strong fault-tolerant characteristics, and in the network world, the network instability is the default must be, HBase certainly has a targeted fault-tolerant processing, that is, after the client submits the RPC request, for various reasons, the server side of the response is likely to time out, there will be a service end has been processed, However, the client cannot be notified of the situation. At this point the client does not receive a response and will resend the request until the number of retries reaches the specified parameters before exiting the application logic. However, this kind of processing will also lead to a series of problems: Take the append operation as an example, the original client just want to add a keyvalue data to the database, but because the server response time-out, will cause append request repeated multiple sends, the result is that the target data on the server is added multiple times, There is a case where the append operation is redundant.

So how does hbase solve the above problem?

To prevent this from happening, HBase declares the nonce management function (through the Servernoncemanager Class), the client each application and the duplicate request uses the same nonce to describe, sends to the service end, the service side will first determine whether the nonce exists, If it does not exist, you can safely perform the operation of the nonce (such as append or increment). Otherwise, the corresponding callback should be processed according to the state of the current nonce:
1, if the nonce is in the wait state, indicating that the nonce corresponding to the operation is being executed, the current thread waits for its execution to end, in accordance with its implementation of the results of further processing;
2, if the nonce is in the proceed state, indicating that the nonce corresponding to the operation has been executed, but the execution result to fail, so here can be re-executed;
3, if the nonce is in the Dont_proceed state, indicating that the nonce corresponding to the operation has been successfully executed, there is no need to do processing.
Therefore, when the nonce enters the Dont_proceed state, all operations performed by it will be ignored, thereby preventing the operation redundancy from occurring. It is important to note that when a nonce is counted into the dont_proceed or proceed state, the time it can survive is controlled by the parameter (hbase.server.hashNonce.gracePeriod), which defaults to 30 minutes. After 30 minutes, Servernoncemanager will delete the nonce, through its Cleanupoldnonces method.

In Hregionserver, there is a member variable noncemanager of the Servernoncemanager type, which is responsible for managing the nonce on that regionserver. It is defined as follows:


Inside the Servernoncemanager class, there is an inner class operationcontext that defines the three states of the nonce:


There is a very important method in the Servernoncemanager class that is used when an operation fails to respond to the client immediately after execution of the server, and the client re-initiates the request for the same operation that carries the same noncegroup and nonce. The service side according to Noncegroup and nonce make corresponding judgment. Defined as follows:


In Hregionserver's append () approach, nonce management was used:


where the Startnonceoperation () method calls the Noncemanager Startoperation () method on Regionserver to determine whether the operation can be performed. The source code is as follows:



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.