未验证 提交 583f6a53 编写于 作者: H He Wang 提交者: GitHub

[doc] update description about safe checkpoint (#67)

上级 da3b90aa
......@@ -118,13 +118,17 @@
### 安全位点
LogMessage 提供了 `safeTimestamp` 来表示数据接收的安全位点,也就是说早于该秒级时间戳提交的 LogMessage 均已被客户端接收。
LogMessage 提供了 `safeTimestamp` 来表示当前数据对应的安全位点,它是一个秒级的时间戳,含义为:早于该时间戳提交的 LogMessage 均已被客户端接收。
业务应用在进行数据消费时,一般还要维护一个数据处理的安全位点。在 LogMessage 中,该安全位点需要借助心跳的 `timestamp` 来实现。 LogMessage 在时间存储上有两套逻辑:
```java
long checkpoint = Long.parseLong(message.getSafeTimestamp());
```
对于 OceanBase 而言,该安全位点是借助心跳的 `timestamp` 来实现的。 OceanBase 的 LogMessage 在时间存储上有两套逻辑:
- 心跳类型:`timestamp` 字段值为安全位点对应的秒级时间戳。
- 其他类型:`timestamp` 字段值为数据变动的提交时间,而 `fileNameOffset` 字段对应最近一次心跳信息的 `timestamp`。由于 libobcdc 并不保证拉取到的数据变动是严格按照时间顺序的,因此对于 DDL、DML 类型的 LogMessage,应当使用 `fileNameOffset` 而非 `timestamp` 作为安全位点。
获取当前数据对应安全位点可以使用如下代码:
因此,OceanBase LogMessage 的安全位点也可以借助以下代码获取:
```java
long checkpoint;
......
......@@ -118,13 +118,17 @@ Please refer to [LogProxyClientTest.java](../../oblogclient-logproxy/src/test/ja
### Safe Checkpoint
LogMessage provides `safeTimestamp` to indicate the safe checkpoint for data reception, that is to say, LogMessage committed earlier than this timestamp has been received by the client.
LogMessage provides `safeTimestamp` to indicate the safe checkpoint, it is a timestamp in seconds, which means all the log messages committed earlier than this timestamp have been received by the client.
When a application consumes data, it generally maintains a safe checkpoint for data processing. For LogMessage, we should use HEARTBEAT `timestamp` as the safe checkpoint. LogMessage contains two kinds of timestamp:
```java
long checkpoint = Long.parseLong(message.getSafeTimestamp());
```
For LogMessage of OceanBase, there are two kinds of timestamp:
- HEARTBEAT type: the value of the `timestamp` field is the timestamp corresponding to the safe checkpoint.
- Other types: the value of the `timestamp` field is the execution time of the data change, and the `fileNameOffset` field corresponds to the latest HEARTBEAT timestamp. Since `libobcdc` does not guarantee that the fetched data changes are in timestamp order, so for DDL and DML types of LogMessage, `fileNameOffset` should be used as safe checkpoint instead of `timestamp`.
The following code can be used to obtain the safe checkpoint corresponding to the current data:
So you can also get the safe checkpoint of OceanBase LogMessage by the following code:
```java
long checkpoint;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册