# Greptime 双周精选 （7.3-7.16）｜提升分布式 DDL 操作的可靠性

Source: https://greptime.cn/blogs/2023-07-19-biweekly

## 内容概述

作为一个成长中的开源项目，GreptimeDB 的进展离不开来自全球的社区贡献者们，感谢各位！

过去两周，我们所有项目中共有 **121** 个 PR 被合并，以下是这段时间较为重要的 PR 总结：

- 基于 Procedure 框架实现了 Create/Alter/Drop Table 等分布式操作

- 解决了在 CentOS 7 环境中不能编译的问题

- 支持 TWCS 压缩策略

- 支持 Google Cloud Storage

- Vector 增加 GreptimeDB metrics 的输出支持

## 社区贡献者名单

在过去的两周里，共有 **5 位贡献者**，累计 **11 个 PR 被成功合并**，还有很多待合并的 PR。

祝贺以下各位在过去 2 周内成为我们活跃的贡献者：

- [@ccjeff](https://github.com/ccjeff) ([db#1864](https://github.com/GreptimeTeam/greptimedb/pull/1864))

- [@DevilExileSu](https://github.com/DevilExileSu) ([db#1932](https://github.com/GreptimeTeam/greptimedb/pull/1932))

- [@etolbakov](https://github.com/etolbakov) ([db#1860](https://github.com/GreptimeTeam/greptimedb/pull/1860) [db#1896](https://github.com/GreptimeTeam/greptimedb/pull/1896) [db#1931](https://github.com/GreptimeTeam/greptimedb/pull/1931) [dashboard#287](https://github.com/GreptimeTeam/dashboard/pull/287))

- [@Gump9](https://github.com/Gump9) ([db#1895](https://github.com/GreptimeTeam/greptimedb/pull/1895) [db#1946](https://github.com/GreptimeTeam/greptimedb/pull/1946))

- [@NiwakaDev](https://github.com/NiwakaDev) ([db#1781](https://github.com/GreptimeTeam/greptimedb/pull/1781) [db#1829](https://github.com/GreptimeTeam/greptimedb/pull/1829) [db#1911](https://github.com/GreptimeTeam/greptimedb/pull/1911))

👏 欢迎 [@ccjeff](https://github.com/ccjeff) 和 [@Gump9](https://github.com/Gump9) 作为新的贡献者加入到我们的社区，并都成功合并了首个 PR！

同时衷心感谢我们所有的成员和贡献者！是你们的付出让我们的项目得以成功，也是你们让 GreptimeDB 成为一个更优质的产品。让我们一起努力，建立一个更棒的社区！

## PR 亮点

### [db#1845](https://github.com/GreptimeTeam/greptimedb/pull/1845) 基于 Procedure 框架实现了 Create/Alter/Drop Table 等分布式操作

我们基于 Procedure 框架实现了 Create/Alter/Drop Table 等几个分布式操作，以确保分布式多步操作的正确执行。同时我们也引入了 DDL Manager，并提升了分布式 DDL 操作的可靠性。

### [db#1863](https://github.com/GreptimeTeam/greptimedb/pull/1863) 解决了在 CentOS 7 中不能编译的问题

此 PR 添加了一个 dockerfile 以编译出能够在仅支持 glibc 2.17 的 CentOS 7 系统上运行的可执行文件。

- `docker buildx build -f ./docker/Dockerfile-centos7 -t greptime-centos7-builder .`  以构建生成器镜像

- `docker run --rm -v .:/greptimedb greptime-centos7-builder` 使用该生成器镜像来生成 binary 文件

<figure>
<img src="/zh/blogs/2023-07-19-biweekly/image1.png" alt="（图 1：编译适配 CentOS 7 的可执行文件）" style="width: 80%; margin: 0 auto"/>
<figcaption>（图 1：编译适配 CentOS 7 的可执行文件）</figcaption>
</figure>

GreptimeDB 要求 Python >= 3.8。对于 CentOS 7 平台，我们需要安装额外的依赖，例如：

```rust
$ yum install -y centos-release-scl rh-python38 rh-python38-python-devel
$ source /opt/rh/rh-python38/enable
```

之后，使用 PyO3 后端构建的 GreptimeDB 就可以工作了。

### [db#1851](https://github.com/GreptimeTeam/greptimedb/pull/1851) 支持 TWCS 压缩策略

受到 Cassandra 的启发，我们增加了对 TWCS 压缩策略的支持。在之前的分级时间窗口压缩策略中，SST 文件被严格分割并与时间窗口对齐。这可能会导致在执行 compaction 时跨多个时间窗口的 SST 会被多次读取从而导致读放大，尤其是在乱序写入的场景下。

TWCS 通过最大时间戳计算 SST 文件的时间窗口，因为乱序的时序数据主要是历史数据，它只影响最小时间戳。通过 TWCS，我们可以更加高效地合并 SST 从而提高查询的效率。

将文件分配到时间窗口后，TWCS 遍历每个窗口以确保：

- 对于当前活跃写入的窗口，我们允许其包含多个 SST 文件，以减轻写放大。

- 对于其他非活跃窗口，每个窗口最多只允许一个 SST 文件，以减轻读放大，从而提高读取性能。

TWCS 可以通过建表时指定 `compaction` 选项启用：

```rust
CREATE TABLE IF NOT EXISTS cpu_metrics (
    hostname STRING,
    environment STRING,
    usage_user DOUBLE,
    usage_system DOUBLE,
    usage_idle DOUBLE,
    ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    TIME INDEX(ts),
    PRIMARY KEY(hostname, environment)

) WITH ('compaction'='twcs', 'compaction.twcs.max_active_window_files'=12, 'compaction.twcs.max_inactive_window_files'=3);
```

### [db#1839](https://github.com/GreptimeTeam/greptimedb/pull/1839) 支持 Google Cloud Storage

借助于 OpenDAL 强大的扩展能力，GreptimeDB 支持了 GCS(Google Cloud Storage)，在此前 GreptimeDB 已经支持将数据写入 S3, OSS, Azblob 等对象存储。

### [db#17198](https://github.com/GreptimeTeam/greptimedb/pull/17198) Vector 增加 GreptimeDB metrics 的输出支持

增加 GreptimeDB metrics 的输出支持。目前，我们使用 GreptimeDB 的 git 仓库添加其客户端，我们最终会将其从 repo 中拆分并发布到 crates.io。

## 新鲜事

Dashboard 即将发布 [v0.3.0](https://github.com/GreptimeTeam/dashboard/releases/tag/v0.3.0) 版本，这次的更新带来了一些新特性和改进。首先，随着两个 PR 被合并进来，新的 status 页面将和大家见面，感谢 Dashboard 新的 contributor @etolbakov 在 [db#283](https://github.com/GreptimeTeam/dashboard/pull/283) 和 [db#287](https://github.com/GreptimeTeam/dashboard/pull/287) 的贡献。其次，我们在 [db#295](https://github.com/GreptimeTeam/dashboard/pull/295) 中，增加了chart 支持自定义配置的功能，用户现在可以根据自己的需求进行更深度的定制。最后，playground 现在已经可以支持 gist，这一改进在 [db#268](https://github.com/GreptimeTeam/dashboard/pull/268) 中提出并实现。这次的更新让 Dashboard 的使用体验有了更大的提升，欢迎大家试用并为我们提出宝贵的意见。

7 月 22 日在杭州，EMQ「云边数据智能」系列主题沙龙将拉开帷幕，该系列活动是由 EMQ 与多家合作伙伴联合举办的线下技术沙龙，将邀请行业领袖、专家学者和技术爱好者共同深入探讨**云边数据智能的相关技术趋势**，**Greptime 创始人庄晓丹**将参与此次杭州站的技术沙龙，并分享**大规模监控场景下的存储实践**相关议题。

欢迎感兴趣的朋友在此报名，现场将准备精美礼品！


## 关于 Greptime

[Greptime 格睿科技](https://greptime.cn/)专注于为可观测、物联网及车联网等领域提供实时、高效的数据存储和分析服务，帮助客户挖掘数据的深层价值。目前基于云原生的时序数据库 [GreptimeDB](https://github.com/GreptimeTeam/greptimedb) 已经衍生出多款适合不同用户的解决方案，更多信息或 demo 展示请联系下方小助手（微信号：greptime）。

欢迎对开源感兴趣的朋友们参与贡献和讨论，从带有 good first issue 标签的 issue 开始你的开源之旅吧～期待在开源社群里遇见你！添加小助手微信即可加入“技术交流群”与志同道合的朋友们面对面交流哦~

Star us on GitHub Now: https://github.com/GreptimeTeam/greptimedb

官网：https://greptime.cn/

文档：https://docs.greptime.cn/

Twitter: https://twitter.com/Greptime

Slack: https://greptime.com/slack

LinkedIn: https://www.linkedin.com/company/greptime/
