此外,这一段 scala code 可能有点难理解的地方就是在一个function里面定义了很多其他的function,比如“
sendTxnMarkersCallback”,但是这段callback并不是立刻被执行的,而只是在此定义而已。它真正被执行的地方是在
txnManager.appendTransactionToLog
之后,也就是当这个record被成功append并且备份之后作为callback才会被执行。其他还有好几个地方都有类似的design
pattern,可能刚开始看的时候会误解。


国璋

On Tue, Aug 9, 2022 at 10:28 AM Guozhang Wang <wangg...@gmail.com> wrote:

> commit / abort 请求收到后,coordinator除了检查状态后还是要append 一个 prepare-commit/abort
> record到transaction log,以及要等到这个append被完全备份后才会回复的。然后再广播markers。具体的code在这里:
>
>
> https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala#L595
>
> 您指出的code只是事先准备好这个append成功后的callback,并不是直接广播markers。
>
> 也就是说,commit/abort的synchronization
> barrier是这个prepare-commit/abort被成功append并且备份的时候,而不是广播markers的时候,因为只要append这个record成功,即使之后coordinator宕机了,恢复之后看到这个record还是会继续之前没有完成的广播markers。
>
> 希望能够对您理解这段code有帮助。
>
>
> 国璋
>
> On Tue, Aug 9, 2022 at 10:19 AM Guozhang Wang <wangg...@gmail.com> wrote:
>
>> Hello Zheyan,
>>
>> Sorry for the late reply.. the email was buried in my inbox for a while.
>>
>> On Thu, Jul 21, 2022 at 6:08 AM 城哲闫 <18846837...@163.com> wrote:
>>
>>> Hello, I am looking at the transaction implementation of kafka recently.
>>> I have some questions about the transaction implementation and would like
>>> to consult with you:
>>>
>>> class : TransactionCoordinator
>>>
>>>
>>>
>>> When the client sends a commit request, the server will directly reply
>>> to the client that the commit is successful after checking the status.
>>> Next, the server will broadcast Markers, and then write the log to the
>>> transaction topic. If the server is down after replying to the commit If
>>> the machine is up, is there a state inconsistency problem? I read the code
>>> comment that the log was spliced successfully before replying to the
>>> commit, but I didn't find the relevant logic, just saw a debug log printed.
>>> Is there a mistake in my understanding? ?Will there be a situation where
>>> the client thinks it has been submitted, but the server does not submit it?
>>> (中文 : 在客户端发送 commit 请求时候 , 服务端在检验状态没问题之后会直接回复客户端 commit 成功 , 接下来服务端再去广播
>>> Markers ,之后去向事务 topic 写入日志, 假如说在回复 commit
>>> 之后服务端宕机了,那么是不是会有状态不一致问题,我看代码注释说在回复 commit 之前日志拼接成功,但是我并没有找到相关逻辑,只是看到打印了一个
>>> debug 日志.请问是我的理解有错误么?是否会出现客户端认为已提交,但是服务端没提交的情况那. )
>>>
>>>
>>>
>>>
>>>
>>>
>>
>> --
>> -- Guozhang
>>
>
>
> --
> -- Guozhang
>


-- 
-- Guozhang

Reply via email to