Apache Omid TSO 组件源码实现原理
Apache Omid TSO 组件实现原理
作用
独立进程,处理全局事务之间的并发冲突。
流程
TSOChannelHandler#channelRead -> AbstractRequestProcessor -> PersistenceProcessorHandler
总体流程
thread1
TSOChannelHandler#channelRead
AbstractRequestProcessor#timestampRequest 接收 client 请求,创建 RequestEvent 并 publish
thread2
AbstractRequestProcessor#onEvent 处理 RequestEvent 请求
AbstractRequestProcessor#handleRequest
PersistenceProcessorImpl#addTimestampToBatch 创建 PersistEvent,当 batch 满了发送事件
thread3
PersistenceProcessorHandler#onEvent 持久化事件处理
类
TSOChannelHandler
继承自 Netty 的 ChannelInboundHandlerAdapter,用于处理 TSO 的入站请求。
channelRead
委托 requestProcessor 创建 timestampRequest 和 commitRequest 请求事件。
AbstractRequestProcessor
处理 timestamp 和 commit 事件。
onEvent
处理 RequestEvent 事件,按照事件类型派发给 handleTimestamp 和 handleCommit 方法进行处理。
handleTimestamp
1.通过 timestampOracle 获取下一个时间戳;
2.PersistenceProcessorImpl#addBatch 事件添加到 batch,但是后续对 timestamp 请求不会额外处理。
handleCommit
主要通过 hasConflictsWithCommittedTransactions 判断 writeSet 和 CommitHashMap 里是否有事务写冲突,如果没有则可以提交事务,分配 commitTimestamp。
private void handleCommit(RequestEvent event) throws Exception {
long startTimestamp = event.getStartTimestamp(); // startTimestamp
Iterable<Long> writeSet = event.writeSet(); // 写入集,存储的是 cellIds
Collection<Long> tableIdSet = event.getTableIdSet();
boolean isCommitRetry = event.isCommitRetry();
boolean nonEmptyWriteSet = writeSet.
浙公网安备 33010602011771号