Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 36 ยท Architecture and Data Model

The Master and RegionServers

Learn the HBase architecture: what the HMaster and the RegionServers do, how clients talk to them directly, how failover works and which services run where.

An HBase cluster has two kinds of HBase processes. The HMaster is the administrator: it decides which server serves which part of a table. The RegionServers are the workers: they actually read and write your data. A third helper, ZooKeeper, keeps them in agreement, and HDFS keeps the files. If you remember one sentence, remember this: clients talk to RegionServers for data, and to the Master only for administration.

This lesson walks through each role and then simulates the control flow in Java.

flowchart TD
  C["Client"] -->|"1. where is the meta table?"| Z["ZooKeeper"]
  C -->|"2. data reads and writes"| R1["RegionServer 1"]
  C -->|"2. data reads and writes"| R2["RegionServer 2"]
  M["HMaster (active)"] -->|"assigns regions"| R1
  M -->|"assigns regions"| R2
  M -.->|"liveness, election"| Z
  R1 -->|"HFiles and WAL"| H["HDFS"]
  R2 -->|"HFiles and WAL"| H

The Master is not on the data path: stopping it for a short time does not stop reads and writes.

The HMaster

The Master is responsible for cluster-wide decisions:

  • Assigning regions to RegionServers when tables are created, when servers join or leave, and when regions split.
  • Failure handling. When ZooKeeper reports that a RegionServer's ephemeral znode vanished, the Master splits that server's WAL files and reassigns its regions.
  • Load balancing. A background balancer moves regions so each server holds a similar number.
  • Schema operations (create, alter, disable, drop) and namespace management.
  • Snapshots, replication peers and quotas coordination.

You can run several Masters. One is active and the others are on standby, waiting on the master znode in ZooKeeper. If the active one dies, a standby takes over within seconds. Since clients do not need the Master for ordinary reads and writes, a Master outage mostly blocks administration and failover handling, not normal traffic.

In HBase 2.x the Master keeps its own state (what assignments are in progress) in a durable store called the MasterProcWAL, so a restarted Master can resume half-finished operations such as a table creation.

The RegionServer

A RegionServer hosts a set of regions: contiguous row ranges of tables (next lesson: Regions, Splits and the Meta Table). It handles reading and writing for those regions, and inside it live these parts:

  • WAL (write-ahead log): one shared log per server (the default provider); every change is appended here before it is acknowledged.
  • BlockCache: a shared in-memory cache of recently read HFile blocks.
  • For each region, one Store per column family. Each Store has a MemStore (sorted in-memory buffer of recent writes) and zero or more HFiles on HDFS.
  • Background threads that flush memstores, compact files, split regions and renew leases.

A typical server hosts 50 to a few hundred regions. The server process is a JVM, so memory sizing (heap for memstores and block cache) is a major tuning topic, covered in the Administration and Tuning chapter of the HBase track.

flowchart LR
  subgraph RS["RegionServer"]
    W["WAL"]
    B["BlockCache"]
    subgraph Reg["Region (rows a..m)"]
      S1["Store: family info"] --> MS["MemStore"]
      S1 --> HF["HFiles"]
    end
  end
  Reg --> W

What a client really does

  1. The client asks ZooKeeper where the hbase:meta table is hosted (the Master address is not needed for this).
  2. It reads hbase:meta to learn which region and RegionServer serve its row key.
  3. It sends the Get/Put directly to that RegionServer and caches the location.
  4. If a region moves, the server answers with an error such as NotServingRegionException; the client clears its cache entry, looks the region up again and retries.

Because locations are cached, the lookup cost is paid once per region, not once per request.

Failure scenarios

  • A RegionServer dies. Its ZooKeeper session expires, the Master notices, the server's WAL is split per region and replayed on the new owners, and the regions come online elsewhere. Typical unavailability for those regions is seconds to a couple of minutes.
  • The active Master dies. A standby wins the election. Data traffic continues meanwhile.
  • A ZooKeeper node dies. The quorum continues as long as a majority is up.
  • A DataNode dies. HDFS serves blocks from other replicas.

Modeling the roles in Java

The stand-in below uses real object boundaries: a Master that only assigns, RegionServers that hold the data, and a Client that asks a catalog (like meta) and then talks to the server. Notice that data reads never call the Master.

Java Stand-in: Master assigns, clients talk to RegionServers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Failover in a few lines

Next, a stand-in for what the Master does when a server disappears: it reassigns the orphaned regions and replays what was in that server's log. Here the "WAL" is simply a list of edits.

Java Stand-in: replaying a dead server's WAL

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Who serves client reads and writes of table data?

    Clients send data requests directly to the RegionServer that hosts the row's region.
  2. 2. What happens to normal reads and writes if the active Master is down for a short time?

    The Master is not on the data path. Cached region locations keep serving requests.
  3. 3. How does the Master learn that a RegionServer died?

    ZooKeeper sessions expire when a server stops responding, deleting its ephemeral node.
  4. 4. What does a client do first when it needs to find where a row lives?

    ZooKeeper points to hbase:meta, which maps row ranges to servers; the client caches the answer.
  5. 5. Which of these lives inside a RegionServer?

    MemStores, the block cache and the WAL are RegionServer components; election and balancing are Master/ZooKeeper tasks.

Summary

  • The HMaster administers: region assignment, failover, balancing, schema changes. It is not on the data path.
  • RegionServers hold regions, each with a MemStore and HFiles per family, plus a WAL and a shared BlockCache.
  • Clients find the meta table via ZooKeeper, then talk straight to RegionServers and cache locations.
  • Failures are handled by ZooKeeper detection, WAL splitting and reassignment of regions.
  • Standby Masters make the administrative role highly available.

Next: Regions, Splits and the Meta Table