neverchanje / notes

1 stars 0 forks source link

FoundationDB Record Layer: A Multi-Tenant Structured Datastore #19

Open neverchanje opened 5 years ago

neverchanje commented 5 years ago

想必都知道 FoundationDB 被 Apple 收购的历史。作为一个分布式 KV 存储,在 FDB 之上可以封装文档数据模型,支持 indexing,支持 schema 和更丰富的查询接口,这就是这篇论文的中心产品,所谓 FoundationDB Record Layer,它的典型案例是 Apple Cloudkit,值得一提的是 Cloudkit 在 VLDB 2018 也有一篇 paper ”CloudKit: Structured Storage for Mobile Applications“。而当前(2019.2)这篇 ”FoundationDB Record Layer: A Multi-Tenant Structured Datastore “ 还只是 preprint,尚未正式发表。

neverchanje commented 5 years ago

CloudKit 如何使用 FDB Record Layer

CloudKit 给 App 开发者提供了 container 这个资源隔离的概念,相当于数据库的 ”表“:

The containers belonging to your app cannot be accessed by apps from another developer. However, your apps can share containers. Multiple apps can share the same container, and one app can use multiple containers. (摘取自 CloudKit 文档

IOS App 和 container 之间可以理解为多对多的关系。

neverchanje commented 5 years ago

这里顺便扯一下 CloudKit。鉴于 Apple 系统的封闭性,Cloudkit 只能服务于 iOS 和 macOS 的 App,受此限制,CloudKit 的主要用户也只是 Apple 的自家 App,一定程度上还会有些 Apple 平台独占的第三方开发者,当然他们的量应当会远比之小。

Launched more than 3 years ago, CloudKit forms the foundation for more than 50 Apple apps, including many of our most important and popular applications such as Photos, iCloud Drive, Notes, Keynote, and News, as well as many third-party apps

现在凑数加起来业务不过 50 个,可见其适用范围:大厂不愿意把数据托管在Apple,小厂为了跨平台也会自己存数据,除了最大头的 Apple 官方应用,剩下的应该都是些作为 Apple 独占开发者的小用户。

neverchanje commented 5 years ago

Record Store

record store 是相比 HBase 的 region,BigTable 的 tablet,Pegasus 的 replica 更高一层的概念。比”表“的粒度更小,

neverchanje commented 5 years ago

FDB 的事务支持

为了介绍 FDB Record Layer,我们有必要先介绍 FDB。

FDB 数据模型

FDB 提供了三种不同的数据模型,这使它成为一个“非主流”的 NoSQL 系统:

neverchanje commented 5 years ago

Schema 的实现

FDB 支持 Schema,也支持 Online Schema Change,这块内容的文档在: https://github.com/FoundationDB/fdb-record-layer/blob/master/docs/SchemaEvolution.md 上可以看到。

Metadata Store

Schema 会被持久化在 Metadata Store 上。

the Record Layer allows metadata to be stored in a separate keyspace from the data, or even a separate storage system entirely

论文中提到 Metadata Store 只是一个元数据存储接口(RecordMetaDataProvider),它可以是 FDB 上的一个 "meta" 表,也可以是存在 zookeeper 甚至是 HBase 上。目前只实现了存 FDB 这种方法,用户也可以自己定制(给扩展性点赞)。

参考代码:

Schema Evolution

When the version in the database is newer, a client has usually used an out-of-date cache to obtain the current metadata. If the version in the database is older, changes need to be applied.

每条数据都是用 Protobuf 序列化成 bytes,所以在 Schema 改变后,数据后向兼容性(backward-compatibility)可以通过 Protobuf 保证。不过论文中对此的介绍并不如文档来的详细,我们这里摘取文档描述的几种操作:

Client Side

client 端会缓存 schema,并不会每次查询都去 FDB 上拉。每次有