Phoenix Omid Timestamp Oracle 组件实现原理

Omid Timestamp Oracle 组件实现原理

作用

生成全局单调递增的时间戳,支持获取操作和崩溃恢复。

功能

1.生成全局单调递增的时间戳(支持崩溃恢复)
    api
        next
            返回下一个时间戳
        getLast
            返回最后一个分配的时间戳(当前时间戳)
    实现方式
        TimestampOracleImpl
            单调递增的时间戳
                在分配时间戳时,如果当前的最大时间戳已经用完,它会触发一个后台任务来更新最大时间戳
            next:
                分配下一个时间戳。如果当前的最大时间戳已经用完,它会等待后台任务分配新的时间戳
        WorldClockOracleImpl
            基于世界时间(System.timestamp)生成全局单调递增的时间戳
2.存储时间戳
    存储方式
        in memory
        zk
        hbase
    api
        updateMaxTimestamp
            更新最大时间戳
        getMaxTimestamp
            获取最大时间戳

TimestampStorage

存储时间戳

方法:
updateMaxTimestamp 更新最大时间戳
getMaxTimestamp 获取最大时间戳

实现类:

TimestampStorage
    InMemoryTimestampStorage in TimestampOracleImpl (org.apache.omid.tso) 使用内存存储
    ZKTimestampStorage (org.apache.omid.timestamp.storage) 使用 zk 存储
    HBaseTimestampStorage (org.apache.omid.timestamp.storage) 使用 hbase 存储
    InMemoryTimestampStorage in WorldClockOracleImpl (org.apache.omid.tso) 使用内存存储
ZKTimestampStorage

通过 zk curator DistributedAtomicLong 实现 DistributedAtomicLong timestamp

方法:
updateMaxTimestamp():
执行 timestamp.compareAndSet(previousMaxTimestamp, newMaxTimestamp)
getMaxTimestamp():
返回 timestamp.get()

TimestampOracle

TimestampOracle 提供了一个服务,用于生成单调递增的时间戳

方法:
initialize()
用于初始化时间戳服务。

next()
返回下一个时间戳。

getLast()
返回最后一个分配的时间戳(当前时间戳)

实现类
TimestampOracle (org.apache.omid.tso)
    TimestampOracleImpl (org.apache.omid.tso)
        PausableTimestampOracle (org.apache.omid.tso)
    WorldClockOracleImpl (org.apache.omid.tso)
TimestampOracleImpl
initialize()

1.从存储中获取 maxTimestamp;
2.初始化 AllocateTimestampBatchTask 用于分配时间戳,并执行一次.

next()

生成下一个时间戳。

@Override
public lon
posted on 2024-06-28 23:47  flyingzc  阅读(4)  评论(0)    收藏  举报  来源