bookkeeper table service调研

 

1.Motivacation

1.1.Distributed Metadata Storage

目前大量的开源系统(Pulsar,Kafka,DistributedLog)都依赖zookeeper进行metadata存储,在这些项目里面zookeeper都是元数据扩展性的瓶颈,受限制于zookeeper的jvm内存大小。
所以需要一个分布式的table service去解决 scalable metadata storage.

2.1.Stream Computing

  1. Storing state for fault-tolerance and achieving various processing guarantees (such as effectively-once processing)
  2. Serving the state for results querying. A key/value table service is the most common state storage representation.
e.g. bookkeeper可以作为streaming data的底层存储,也可以存储流式作业packages/topologies,所以用bookkeeper存储streaming state 和 streaming result可以减少外部依赖

2.Interface

2.1.Public Data Model

PTable

  • Ptable在table service 中代表表格的意思,是一组key/value的集合
  • Ptable中的key/value中的key由两部分组成,pkey和lkey。pkey是routing key, skey是local key
  • Ptable中按照pkey划分成多个table range
  • 每个key/value都有两个version号。Rversion和version。
  • key/value支持CAS modify操作,同时属于同一个pkey下的lkey/value支持在一个txn下进行操作

NameSpace

Namespace是管理table的基本单位,由多个table组成

Table Api

The PTable API includes:
- Put: U​pdate the key/value pair: {pKey, lKey, value}
- Range:
- Retrieve a single key : {pKey, lKey}
- Scanning all the lKeys within same PKey.
- Delete
- Delete a single key : {pKey, lKey}
- Deleting a range of lKeys within same PKey.
- Increment
- Increment the value of a single key : {pKey, lKey}
- Txn
- Allow atomic modification on the lKeys within same pKey.

Example Use Cases

  • Distributed Counter:The proposed `Increment` API can be used for distributed counting, which is a very common use case in ETL.
  • Metadata Storage:The proposed `Compare` and `Txn` API can be used for supporting conditional updates (aka CAS), which is a very common operation that bookkeeper, distributedlog and pulsar uses to ensure metadata operation consistency.
  • Membership Storage:The proposed PTable module `PKey-LKey` can be used for storing memberships.(topic, segmentid) or (consumergroup, clientid)

3.Design

Pkey/Lkey的设计模式的系统设计中的好处和一些用法:
  1. Pkey 可以作为log stream的名字,Lkey可以作为log segment的id和log segment metadata
  2. 在pulsar中, (topic, partition), (partition, ledgers), (partition, cursor)都可以用到这种设计模式
  3. Consumer group membership管理,pkey -> consumer group, lkey -> member id
  4. 同一个pkey下的不同lkey可以通过txn实现cas操作,在管理metadata十分有用
 
Table service中namespace下有许多table,table中又根据pkey划分成了不同的range,下面介绍下table range是如何工作的

3.1.Range Location

  • Root Range 存储了 namespace和table之间的对应关系和Meta Range的location
  • Meta Range 存储了各个Range的location
  • 在Root Range和Meta Range中存储的location 信息都是virtual location information(虚拟节点信息)

3.2.Range Assignment

Table Range -> Storage Container

  • Table ranges 会被分配给指定的storage container。一旦分配结果确定则再也不会改变
  • Root range分配在storage container-0。Meta range 会按照负载进行分配

Storage Container -> Server

  • Storage container 通过zookeeper Helix分配给physical server
  • 这种路由设计使得系统中需要频繁变更的元数据信息和不会变更的元数据信息分离,改善了客户端和服务端的缓存过期和更新不及时的case,减少因为缓存丢失或缓存失效而引入的重试。同时为系统提供了很好的扩展性。

Storage Container

Storage Container 在分配给physical server的时候,会assign给多个physical server。并且从其中选一个出来,master负责读写操作,slave负责读操作

Table Range Store

Table range 是一个存储单元,每个table range的操作都是又三部分组成
  • WAL
  • Rocks db instance for indexing key/value pair
  • Rocks db 定期同步增量数据到bookkeeper中
持久化table service的数据是依赖bookkeeper的,rocksdb在其中扮演的角色更像是key/value pair的缓存

Updates

所有的写入操作是先记录到WAL中的。然后再将key/value写入到rocksdb中
All the table range updates are first written into a WAL. After all the updates are persisted in the WAL, they will then be applied in the rocksdb instance for indexing all these key/value pairs.

Checkpoint

后台线程会定期会copy sst 文件到bookkeeper中。等到对应的checkpoint中的sst文件都copy完了,会truncate wal文件。如果server宕机,新的负责这个table range的server会从bookkeeper中恢复全量数据。
因为rocksdb 是LSM-tree结构的。在存储checkpoint的时候,不需要每次都dump最新的key/value paris。只需要copy 两个checkpoint之间的增加sst file。

Restore

Restore操作从bookkeeper copy sst files 到新的server用来初始化rocksdb。然后将上次记录的checkpoint文件到最新的WAL的数据写入到rocksdb中。WAL和sst files都是存储在bookkeeper中的。

Scaling

1.Scale Table

  1. 将 table range 分裂成两个新的table range,每个新的table range有一半原来table range的key
  2. 可以从现有的table range中将key/value回写到新的两个table range中
  3. 等到两个新的table range恢复了全量的数据。更新table range的信息到meta range中。然后关闭并且删除old table range

2.Scale Cluster

  1. 增加机器到集群中,并且增加storage containers
  2. 因为不能改变table range -> storage containers的路由,所以可以通过scale table的方式去将table range扩容到新的storage containers中

4.Table service used in Pulsar

4.1.Pulsar function

从pulsar 2.1 realse开始,pulsar使用bookkeeper table service 存储pulsar function state。For example,
a WordCount function 可以存储 counter state 在bk table service中。可以用于临时状态查看和故障恢复。

4.2.Metadata Storage

  1. Pulsar对元数据层做了抽象,目前正在对元数据存储etcd做支持。table service 最后会作为 bookkeeper / pullsar 的一个元数据方案,解决元数据 scalablity 的问题。
  2. pulsar想通过将元数据交给table service做管理,支持 > 10 millions 甚至 100 millions 级别的 topics
posted @ 2021-10-29 17:38  鲁仕林  阅读(298)  评论(0编辑  收藏  举报