incubator-seata icon indicating copy to clipboard operation
incubator-seata copied to clipboard

Refactor SpringFenceHandler to Improve Code Structure and Reduce Complexity

Open YvCeung opened this issue 5 months ago • 3 comments

Check Ahead

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

  • [x] I am willing to try to implement this feature myself.

Why you need it?

I've been seata TCC model to research on, when I saw the org. Apache. Seata. Rm. Fence. SpringFenceHandler this code when I found the following questions, I wonder whether if necessary I can try to refactor the code

  1. The class is a bit large and the logic is too complex. handler should serve as a processing entry point instead of integrating all the logic within it.

  2. Database operations, transaction processing, and asynchronous cleaning are all piled up together. It will be very painful to make changes later

我最近在研究seata的TCC模式的实现,当我看到org.apache.seata.rm.fence.SpringFenceHandler这块代码的时候我发现有以下几个问题,我在想如果有必要的话我是否可以尝试重构这块的代码

1、类稍微有点大,逻辑太杂,handler应该作为一个处理入口,而不是柔和所有的逻辑在里面,

2、数据库操作、事务处理、异步清理这些东西全堆一块了,后面改起来会很痛苦

How it could be?

No response

Other related information

No response

YvCeung avatar Jul 01 '25 13:07 YvCeung

You can submit your initial refactoring proposal for community review. For example, you can describe how many classes you would split it into, the responsibilities of each class, which design patterns you would use, and so on.

funky-eyes avatar Jul 01 '25 14:07 funky-eyes

Also, I believe that test code is essential when performing refactoring.

Could you please check whether there are existing tests that cover the part you’re planning to refactor? If not, I think we should add those tests first before proceeding with the refactoring.

YongGoose avatar Jul 02 '25 01:07 YongGoose

Also, I believe that test code is essential when performing refactoring.

Could you please check whether there are existing tests that cover the part you’re planning to refactor? If not, I think we should add those tests first before proceeding with the refactoring.

Image
The relevant test coverage is 0. I will first submit a pr to supplement these test cases

YvCeung avatar Jul 02 '25 01:07 YvCeung