diff --git a/docs/formats/logmessage-cn.md b/docs/formats/logmessage-cn.md index 590f52fbfeb657da984c6616cf252edb33f26671..6c2a2cc964bad8c0ccedb91396ce27d6d9a0508b 100644 --- a/docs/formats/logmessage-cn.md +++ b/docs/formats/logmessage-cn.md @@ -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; diff --git a/docs/formats/logmessage.md b/docs/formats/logmessage.md index 34b6d0cc7a2cd924bfc62ee88e16295e005d86c0..506bcdbf6d3297b4b9027f299c7d2758f8eb6890 100644 --- a/docs/formats/logmessage.md +++ b/docs/formats/logmessage.md @@ -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;