Hadoop loadBalance source code analysis

Source: Internet
Author: User

The project hbase database encountered a strange assignment. The src and dest of the region Mobile Server are the same regionserver. However, the time stamp is different and only one regionserver is started.

Analyze the source code to solve the problem

Loadbalance only has one implementation org. apache. hadoop. hbase. master. defaultLoadBalancer starts a thread org In HMaster. apache. hadoop. hbase. chore, according to the set hbase. balancer. period (300000 ms by default, five minutes). it traverses all tables and performs balance based on the number of region of each table in regionserver. There is a balance Coefficient hbase. regions. slop (0.2 by default), calculate the average region value based on the total number of region, avg × 0. 8. Take the integer as the minimum value, avg × 1. 2. Take the integer as the maximum value. If the value of regionserver exceeds the maximum value, it must be removed. If the value is smaller than the minimum value, it must move the region. Otherwise, the current balance status is printed. According to the RegionPlan generated by assignmentManager according to the preceding steps, moving region from src to desc src and desc is a ServerName object. When the HMaster is started, it will wait for region servers to register with serverManager.
// Wait for region servers to report in.this.serverManager.waitForRegionServers(status);// Check zk for regionservers that are up but didn't registerfor (ServerName sn: this.regionServerTracker.getOnlineServers()) {    if (!this.serverManager.isServerOnline(sn)) {    // Not registered; add it.       LOG.info("Registering server found up in zk but who has not yet " +    "reported in: " + sn);    this.serverManager.recordNewServer(sn, HServerLoad.EMPTY_HSERVERLOAD);  }}

The serverManager thread sleep for a certain period of time, waiting for HRegionServer Registration

HRegionServer. java:

      // Try and register with the Master; tell it we are here.  Break if      // server is stopped or the clusterup flag is down or hdfs went wacky.      while (keepLooping()) {        MapWritable w = reportForDuty();        if (w == null) {          LOG.warn("reportForDuty failed; sleeping and then retrying.");          this.sleeper.sleep();        } else {          handleReportForDutyResponse(w);          break;        }      }

After the HRegionServer is registered, it enters the mainloop

 // The main run loop. while (!this.stopped && isHealthy()) {
  long now = System.currentTimeMillis();

If (now-lastMsg)> = msgInterval ){
DoMetrics ();
TryRegionServerReport ();
LastMsg = System. currentTimeMillis ();
}

}

Register every hbase. regionserver. msginterval (3 seconds by default). If the server ip address and port are not in the registered list, add ServerName to map

ServerManager. java

 void regionServerReport(ServerName sn, HServerLoad hsl)  throws YouAreDeadException, PleaseHoldException {    checkIsDead(sn, "REPORT");    if (!this.onlineServers.containsKey(sn)) {      // Already have this host+port combo and its just different start code?      checkAlreadySameHostPort(sn);      // Just let the server in. Presume master joining a running cluster.      // recordNewServer is what happens at the end of reportServerStartup.      // The only thing we are skipping is passing back to the regionserver      // the ServerName to use. Here we presume a master has already done      // that so we'll press on with whatever it gave us for ServerName.      recordNewServer(sn, hsl);    } else {      this.onlineServers.put(sn, hsl);    }  }

RecordNewServer prints the ip port and timestamp information of the ServerName object.

The ServerName object registered with the same region server has the same timestamp.

this.startcode = System.currentTimeMillis();...result = this.hbaseMaster.regionServerStartup(port, this.startcode, now);...this.serverNameFromMasterPOV = new ServerName(hostnameFromMasterPOV,this.isa.getPort(), this.startcode);...this.hbaseMaster.regionServerReport(this.serverNameFromMasterPOV.getVersionedBytes(), hsl);

 

When the region server is started, the startCode is fixed. According to this process, the same IP address and port are not displayed, but the region server with different timestamps runs online.

If two region servers are started on one machine, the server removes the timestamp from the server.

The problem we encountered was that regionserver with different timestamps was registered on the master and region move was performed between them.

 

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.