jemalloc 深入分析 之Region size 设计以及和 index 对应关系

为了更好的阅读效果,推荐下载pdf文档:
详细文章请参考:《jemalloc 深入分析》
https://github.com/everschen/tools/blob/master/DOC/Jemalloc.pdf
https://download.youkuaiyun.com/download/ip5108/10941278

  1. Region size 设计以及和 index 对应关系
    6.1. Region size步长的设计
    下图是对于从reg_size=64开始的增加规则,可以看出步长增加规则是每次在相邻幂次数位加1,得到下一个reg_size值。
    在这里插入图片描述

6.2. Region相关的参数定义(anrdoid 64bits)
以下配置是对应于如下的系统参数: (LG_SIZEOF_PTR == 3 && LG_TINY_MIN == 3 && LG_QUANTUM == 4 && LG_PAGE == 12)
#define NTBINS 1
#define NLBINS 29
#define NBINS 36
#define NSIZES 232
#define NPSIZES 199
#define LG_TINY_MAXCLASS 3
#define LOOKUP_MAXCLASS ((((size_t)1) << 11) + (((size_t)4) << 9))
#define SMALL_MAXCLASS ((((size_t)1) << 13) + (((size_t)3) << 11))
#define LG_LARGE_MINCLASS 14
#define HUGE_MAXCLASS ((((size_t)1) << 62) + (((size_t)3) << 60))
6.3. SIZE_CLASSES 定义
#define SIZE_CLASSES
/* index, lg_grp, lg_delta, ndelta, psz, bin, lg_delta_lookup /
SC( 0, 3, 3, 0, no, yes, 3)

SC( 1, 3, 3, 1, no, yes, 3)
SC( 2, 4, 4, 1, no, yes, 4)
SC( 3, 4, 4, 2, no, yes, 4)
SC( 4, 4, 4, 3, no, yes, 4)

SC( 5, 6, 4, 1, no, yes, 4)
SC( 6, 6, 4, 2, no, yes, 4)
SC( 7, 6, 4, 3, no, yes, 4)
SC( 8, 6, 4, 4, no, yes, 4)

SC( 9, 7, 5, 1, no, yes, 5)
SC( 10, 7, 5, 2, no, yes, 5)
SC( 11, 7, 5, 3, no, yes, 5)
SC( 12, 7, 5, 4, no, yes, 5)

SC( 13, 8, 6, 1, no, yes, 6)
SC( 14, 8, 6, 2, no, yes, 6)
SC( 15, 8, 6, 3, no, yes, 6)
SC( 16, 8, 6, 4, no, yes, 6)

SC( 17, 9, 7, 1, no, yes, 7)
SC( 18, 9, 7, 2, no, yes, 7)
SC( 19, 9, 7, 3, no, yes, 7)
SC( 20, 9, 7, 4, no, yes, 7)

SC( 21, 10, 8, 1, no, yes, 8)
SC( 22, 10, 8, 2, no, yes, 8)
SC( 23, 10, 8, 3, no, yes, 8)
SC( 24, 10, 8, 4, no, yes, 8)

SC( 25, 11, 9, 1, no, yes, 9)
SC( 26, 11, 9, 2, no, yes, 9)
SC( 27, 11, 9, 3, no, yes, 9)
SC( 28, 11, 9, 4, yes, yes, 9)

SC( 29, 12, 10, 1, no, yes, no)
SC( 30, 12, 10, 2, no, yes, no)
SC( 31, 12, 10, 3, no, yes, no)
SC( 32, 12, 10, 4, yes, yes, no)

SC( 33, 13, 11, 1, no, yes, no)
SC( 34, 13, 11, 2, yes, yes, no) \
SC( 35, 13, 11, 3, no, yes, no) \ //small max
SC( 36, 13, 11, 4, yes, no, no) \ //large start = 2^14

SC( 37, 14, 12, 1, yes, no, no)
SC( 38, 14, 12, 2, yes, no, no)
SC( 39, 14, 12, 3, yes, no, no)
SC( 40, 14, 12, 4, yes, no, no)

SC( 41, 15, 13, 1, yes, no, no)
SC( 42, 15, 13, 2, yes, no, no)
SC( 43, 15, 13, 3, yes, no, no)
SC( 44, 15, 13, 4, yes, no, no)

SC( 45, 16, 14, 1, yes, no, no)
SC( 46, 16, 14, 2, yes, no, no)
SC( 47, 16, 14, 3, yes, no, no)
SC( 48, 16, 14, 4, yes, no, no)

SC( 49, 17, 15, 1, yes, no, no)
SC( 50, 17, 15, 2, yes, no, no)
SC( 51, 17, 15, 3, yes, no, no)
SC( 52, 17, 15, 4, yes, no, no)

SC( 53, 18, 16, 1, yes, no, no)
SC( 54, 18, 16, 2, yes, no, no)
SC( 55, 18, 16, 3, yes, no, no)
SC( 56, 18, 16, 4, yes, no, no)

SC( 57, 19, 17, 1, yes, no, no)
SC( 58, 19, 17, 2, yes, no, no)
SC( 59, 19, 17, 3, yes, no, no)
SC( 60, 19, 17, 4, yes, no, no)

SC( 61, 20, 18, 1, yes, no, no)
SC( 62, 20, 18, 2, yes, no, no)
SC( 63, 20, 18, 3, yes, no, no)
SC( 64, 20, 18, 4, yes, no, no)

SC( 65, 21, 19, 1, yes, no, no)
SC( 66, 21, 19, 2, yes, no, no)
SC( 67, 21, 19, 3, yes, no, no)
SC( 68, 21, 19, 4, yes, no, no)

SC( 69, 22, 20, 1, yes, no, no)
SC( 70, 22, 20, 2, yes, no, no)
SC( 71, 22, 20, 3, yes, no, no)
SC( 72, 22, 20, 4, yes, no, no)

SC( 73, 23, 21, 1, yes, no, no)
SC( 74, 23, 21, 2, yes, no, no)
SC( 75, 23, 21, 3, yes, no, no)
SC( 76, 23, 21, 4, yes, no, no)

SC( 77, 24, 22, 1, yes, no, no)
SC( 78, 24, 22, 2, yes, no, no)
SC( 79, 24, 22, 3, yes, no, no)
SC( 80, 24, 22, 4, yes, no, no)

SC( 81, 25, 23, 1, yes, no, no)
SC( 82, 25, 23, 2, yes, no, no)
SC( 83, 25, 23, 3, yes, no, no)
SC( 84, 25, 23, 4, yes, no, no)

### HBase架构中Master Server、Region Server与Meta数据之间的关系详解 在HBase的分布式架构中,**Master Server**(HMaster)、**Region Server** 以及 **Meta数据** 是构成其核心运行机制的重要组成部分。它们各自承担不同的职责,并通过紧密协作来实现系统的高可用性、可扩展性高效的数据管理。 #### Master Server的角色与功能 HMaster是HBase集群中的主控节点,主要负责管理协调整个集群的元数据操作负载均衡。它不直接处理客户端的读写请求,而是专注于维护集群的状态信息。具体来说,HMaster的功能包括: - 管理Region的分配与迁移:当一个新的表被创建或者一个Region发生分裂时,HMaster会决定将这些新的Region分配给哪个Region Server进行托管。 - 监控Region Server的状态:HMaster通过ZooKeeper监控各个Region Server的心跳信号,一旦某个Region Server宕机,HMaster会迅速将该服务器上的所有Region重新分配到其他健康的Region Server上。 - 维护系统级别的配置参数:如表的schema定义、访问控制策略等。 #### Region Server的作用与职责 Region Server是HBase集群中的工作节点,负责实际的数据存储处理客户端的读写请求。每个Region Server可以管理多个Region,而每个Region又包含若干个Store(对应列族)。Region Server的主要任务有: - 处理来自客户端的Put、Get、Scan等操作。 - 将数据写入MemStore并定期将其持久化到HFile中。 - 提供对WAL(Write-Ahead Log)文件的支持以确保数据的一致性可靠性。 - 在必要时触发Region的Split或Merge操作。 #### Meta数据的重要性及其作用 `hbase:meta` 表是HBase内部用来存储所有用户Region位置信息的关键元数据表。它记录了每个Region的详细属性,包括但不限于以下内容: - `Rowkey`:由`tableName`, `regionStartKey`, `regionId`, `replicaId` 组成,用于唯一标识一个Region。 - `info` 列族:此列族下包含三个重要的列: - `info:regioninfo`:描述Region的基本信息,例如`regionId`、`tableName`、`startKey`、`endKey`、是否离线(`offline`)、是否已拆分(`split`)以及副本ID(`replicaId`)。 - `info:server`:指出托管该RegionRegion Server地址,格式为`server:port`。 - `info:serverstartcode`:表示托管该RegionRegion Server启动的时间戳,这对于判断Region Server的有效性非常重要。 #### Master Server、Region Server与Meta数据之间的交互 HMaster、Region Server以及`hbase:meta`表之间存在着密切的互动关系: - 当一个新的Region被创建出来后,无论是因为初始建表还是由于现有Region的Split,HMaster都会更新`hbase:meta`表中的相关信息,确保客户端能够正确地定位到这个新Region的位置。 - 如果某个Region Server出现故障,HMaster会从`hbase:meta`表中获取该Server所持有的所有Region列表,并尝试将这些Region重新分配给其他的Region Server。同时,HMaster还会检查WAL文件的内容,以便恢复那些尚未提交的操作。 - 客户端在执行读写操作之前通常需要查询`hbase:meta`表来确定目标Region所在的Region Server。这一过程可能涉及多次网络通信,因此为了提高效率,客户端往往会缓存最近访问过的Region位置信息。 - 此外,HMaster还会周期性地扫描`hbase:meta`表,以发现任何未被妥善处理的异常情况,比如孤立的Region或者是处于非预期状态的Region Server。 综上所述,HMaster、Region Server`hbase:meta`构成了HBase架构的核心框架。HMaster作为指挥中心掌控全局;Region Server则是执行层面的实际工作者;而`hbase:meta`则充当着桥梁的角色,连接着两者之间的信息流,确保整个系统的稳定运行服务连续性。 ```java // 示例代码:如何使用Java API获取指定表的所有Region信息 import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.util.Bytes; public class HBaseMetaReader { public static void main(String[] args) throws Exception { Configuration config = HBaseConfiguration.create(); config.set("hbase.zookeeper.quorum", "zk_host:2181"); try (Connection connection = ConnectionFactory.createConnection(config); Table table = connection.getTable(TableName.valueOf(Bytes.toBytes("your_table")))) { // 获取表的所有Region信息 List<HRegionLocation> regions = connection.getAdmin().getTableRegions(table.getName()).get(); for (HRegionLocation region : regions) { System.out.println("Region Name: " + region.getRegionNameAsString()); System.out.println("Start Key: " + Bytes.toString(region.getStartKey())); System.out.println("End Key: " + Bytes.toString(region.getEndKey())); System.out.println("Server: " + region.getServerName()); System.out.println("-----------------------------"); } } } } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值