fescar分布式源码

Fescar - RM实现原理介绍

2019-02-12  本文已影响76人  晴天哥_王志

开篇

 这个系列开始介绍Fescar当中的RM(Resource Manager),RM负责控制分支事务,负责分支注册、状态汇报,并接收事务协调器的指令,驱动分支(本地)事务的提交和回滚。

Fescar RM介绍


说明:
    public void demoByLowLevelAPI() throws Throwable {
        // 0. init
        init();

        // 1. get or create a transaction
        GlobalTransaction tx = GlobalTransactionContext.getCurrentOrCreate();

        // 2. begin transaction
        try {
            tx.begin(30000, "my_tx_instance");

        } catch (TransactionException txe) {
            // TODO: Handle the transaction begin failure.

        }

        Object rs = null;
        try {

            // Do Your BusinessService
            businessCall1();
            businessCall2();
            businessCall3();

        } catch (Throwable ex) {

            // 3. any business exception, rollback.
            try {
                tx.rollback();

                // 3.1 throw the business exception out.
                throw ex;

            } catch (TransactionException txe) {
                // TODO: Handle the transaction rollback failure.

            }

        }

        // 4. everything is fine, commit.
        try {
            tx.commit();

        } catch (TransactionException txe) {
            // TODO: Handle the transaction rollback failure.

        }
    }

说明:

Fescar基本原理

Fescar的RM使用JDBC 数据源代理,作为拦截的核心实现

说明:



说明:




说明:




说明:

Fescar RM代理源码

说明:

期待

 真正的核心在于对DataSourceProxy、ConnectionProxy、StatementProxy的解析。

上一篇 下一篇

猜你喜欢

热点阅读