seata的hook优化建议

mznpcxlj  于 2023-03-19  发布在  其他
关注(0)|答案(4)|浏览(171)

我们项目组使用了seata1.5.2版本,在研发seata监控的时候,用到了TM的HOOK机制,但是在使用上发现一些问题

  1. 同一个线程中出现多个@GlobalTransactional,每个@GlobalTransactional都会执行钩子方法,不论是TM的发起者还是参与者,很多时候我们只需要发起者执行钩子方法,不需要参与者执行钩子,这里根本无法进行判断区分
  2. 同一个线程的最后一个@GlobalTransactional在执行完afterCompletion后会将注册的hook对象删除(cleanUp方法),导致其他@GlobalTransactional无法成功执行hook后处理方法

优化建议:

  1. 优化钩子方法(beforeBegin、afterBegin、beforeCommit、afterCommit、beforeRollback、afterRollback、afterCompletion)
    所有钩子方法新增入参GlobalTransaction tx,这样就能判断到底是发起者还是参与者调用了
  2. 在TransactionalTemplate执行完commit/rollback之后,会进行cleanUp操作(删除hook对象),这个不太合理,这里希望能用java-spi的方式重写cleanUp方法,并且cleanUp方法新增入参GlobalTransaction tx,这样我们就能对cleanUp进行重写(spi的方式)
pb3skfrl

pb3skfrl1#

@412165137lzh I agree with your idea. Could you submit a pr to optimize it ?

hof1towb

hof1towb2#

#5073 The second point is consistent with this issue

z9smfwbn

z9smfwbn3#

#5073 The second point is consistent with this issue

get it

wvyml7n5

wvyml7n54#

@412165137lzh I agree with your idea. Could you submit a pr to optimize it ?

thx,I will submit later when I am free

相关问题