├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ └── enhancement.md ├── PULL_REQUEST_TEMPLATE.md ├── auto-comment.yml ├── licenserc.yml └── workflows │ └── license-checker.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CONTRIBUTING.md ├── CONTRIBUTING_CN.md ├── LICENSE ├── MANIFEST.in ├── NOTICE ├── README.md ├── README_CN.md ├── flask-sample ├── .gitignore ├── README.md ├── client.yml ├── db.py ├── flask_test.py ├── flask_test2.py ├── requirements.txt ├── test_dao.py ├── test_service.py └── test_service2.py ├── requirements.txt ├── seata ├── Boostrap.py ├── __init__.py ├── boot │ ├── GlobalTransactionScanner.py │ └── __init__.py ├── config │ ├── Config.py │ ├── Configuration.py │ ├── FileConfig.py │ ├── NacosConfig.py │ └── __init__.py ├── core │ ├── ByteBuffer.py │ ├── Number.py │ ├── __init__.py │ ├── c │ │ ├── Future.py │ │ └── __init__.py │ ├── compressor │ │ ├── CompressorFactory.py │ │ ├── CompressorType.py │ │ ├── DefaultCompressor.py │ │ └── __init__.py │ ├── context │ │ ├── ContextCore.py │ │ ├── RootContext.py │ │ └── __init__.py │ ├── model │ │ ├── BranchStatus.py │ │ ├── BranchType.py │ │ ├── GlobalStatus.py │ │ └── __init__.py │ ├── protocol │ │ ├── AbstractIdentifyRequestResponseCodec.py │ │ ├── AbstractResultMessageCodec.py │ │ ├── HeartbeatMessage.py │ │ ├── MergeResultMessage.py │ │ ├── MergeResultMessageCodec.py │ │ ├── MergedWarpMessage.py │ │ ├── MergedWarpMessageCodec.py │ │ ├── MessageType.py │ │ ├── MessageTypeAware.py │ │ ├── ProtocolConstants.py │ │ ├── RegisterRMRequestResponse.py │ │ ├── RegisterRMRequestResponseCodec.py │ │ ├── RegisterTMRequestResponse.py │ │ ├── RegisterTMRequestResponseCodec.py │ │ ├── ResultCode.py │ │ ├── RpcMessage.py │ │ ├── Version.py │ │ ├── __init__.py │ │ └── transaction │ │ │ ├── AbstractBranchEndRequestResponseCodec.py │ │ │ ├── AbstractGlobalEndRequestResponseCodec.py │ │ │ ├── AbstractTransactionRequestResponseCodec.py │ │ │ ├── BranchCommitRequestResponse.py │ │ │ ├── BranchCommitRequestResponseCodec.py │ │ │ ├── BranchRegisterRequestResponse.py │ │ │ ├── BranchRegisterRequestResponseCodec.py │ │ │ ├── BranchReportRequestResponse.py │ │ │ ├── BranchReportRequestResponseCodec.py │ │ │ ├── BranchRollbackRequestResponse.py │ │ │ ├── BranchRollbackRequestResponseCodec.py │ │ │ ├── GlobalBeginRequestResponse.py │ │ │ ├── GlobalBeginRequestResponseCodec.py │ │ │ ├── GlobalCommitRequestResponse.py │ │ │ ├── GlobalCommitRequestResponseCodec.py │ │ │ ├── GlobalLockQueryRequestResponse.py │ │ │ ├── GlobalLockQueryRequestResponseCodec.py │ │ │ ├── GlobalReportRequestResponse.py │ │ │ ├── GlobalReportRequestResponseCodec.py │ │ │ ├── GlobalRollbackRequestResponse.py │ │ │ ├── GlobalRollbackRequestResponseCodec.py │ │ │ ├── GlobalStatusRequestResponse.py │ │ │ ├── GlobalStatusRequestResponseCodec.py │ │ │ ├── UndoLogDeleteRequest.py │ │ │ ├── UndoLogDeleteRequestCodec.py │ │ │ └── __init__.py │ ├── rpc │ │ ├── Address.py │ │ ├── __init__.py │ │ └── v1 │ │ │ ├── ChannelManager.py │ │ │ ├── HeadMapSerializer.py │ │ │ ├── ProtocolV1.py │ │ │ ├── RemotingClient.py │ │ │ ├── RmRemotingClient.py │ │ │ ├── TmRemotingClient.py │ │ │ └── __init__.py │ ├── serializer │ │ ├── SerializerFactory.py │ │ ├── __init__.py │ │ └── seata │ │ │ ├── MessageCodecFactory.py │ │ │ ├── SeataSerializer.py │ │ │ └── __init__.py │ └── util │ │ ├── ClassUtil.py │ │ └── __init__.py ├── exception │ ├── NotSupportYetException.py │ ├── RmTransactionException.py │ ├── ShouldNeverHappenException.py │ ├── TmTransactionException.py │ ├── TransactionException.py │ ├── TransactionExceptionCode.py │ └── __init__.py ├── log │ ├── LogConfiguration.py │ └── __init__.py ├── registry │ ├── FileRegistry.py │ ├── NacosRegistry.py │ ├── Registry.py │ └── __init__.py ├── rm │ ├── DefaultResourceManager.py │ ├── RMClient.py │ ├── RMHandlerAT.py │ ├── __init__.py │ └── datasource │ │ ├── AsyncWorker.py │ │ ├── ColumnUtils.py │ │ ├── ConnectionContext.py │ │ ├── ConnectionProxy.py │ │ ├── CursorProxy.py │ │ ├── DataCompareUtil.py │ │ ├── DataSourceProxy.py │ │ ├── DataSourceResourceManager.py │ │ ├── Types.py │ │ ├── __init__.py │ │ ├── exception │ │ ├── SQLException.py │ │ └── __init__.py │ │ ├── executor │ │ ├── CursorCallback.py │ │ ├── ExecuteTemplate.py │ │ ├── Executor.py │ │ ├── LockConflictException.py │ │ ├── LockWaitTimeoutException.py │ │ ├── PlainExecutor.py │ │ ├── __init__.py │ │ └── mysql │ │ │ ├── MySQLDeleteExecutor.py │ │ │ ├── MySQLInsertExecutor.py │ │ │ ├── MySQLSelectForUpdateExecutor.py │ │ │ ├── MySQLUpdateExecutor.py │ │ │ └── __init__.py │ │ ├── sql │ │ ├── SQLVisitorFactory.py │ │ ├── TableMetaCacheFactory.py │ │ ├── __init__.py │ │ └── struct │ │ │ ├── ColumnMeta.py │ │ │ ├── Field.py │ │ │ ├── IndexMeta.py │ │ │ ├── IndexType.py │ │ │ ├── KeyType.py │ │ │ ├── Row.py │ │ │ ├── TableMeta.py │ │ │ ├── TableRecords.py │ │ │ └── __init__.py │ │ └── undo │ │ ├── BranchUndoLog.py │ │ ├── SQLUndoLog.py │ │ ├── State.py │ │ ├── UndoExecutor.py │ │ ├── UndoExecutorFactory.py │ │ ├── UndoExecutorHolder.py │ │ ├── UndoExecutorHolderFactory.py │ │ ├── UndoLogManager.py │ │ ├── UndoLogManagerFactory.py │ │ ├── UndoLogParser.py │ │ ├── UndoLogParserFactory.py │ │ ├── __init__.py │ │ ├── mysql │ │ ├── MySQLUndoDeleteExecutor.py │ │ ├── MySQLUndoExecutorHolder.py │ │ ├── MySQLUndoInsertExecutor.py │ │ ├── MySQLUndoLogManager.py │ │ ├── MySQLUndoUpdateExecutor.py │ │ └── __init__.py │ │ └── parser │ │ ├── ProtobufUndoLogParser.py │ │ ├── __init__.py │ │ ├── branch_undolog.proto │ │ └── proto │ │ ├── __init__.py │ │ └── branch_undolog_pb2.py ├── script │ └── client.yml ├── sqlparser │ ├── SQLDMLRecognizer.py │ ├── SQLParsingException.py │ ├── SQLRecognizer.py │ ├── SQLType.py │ ├── __init__.py │ ├── mysql │ │ ├── MySQLDeleteSQLRecognizer.py │ │ ├── MySQLDmlRecognizer.py │ │ ├── MySQLInsertSQLRecognizer.py │ │ ├── MySQLSelectSQLRecognizer.py │ │ ├── MySQLUpdateSQLRecognizer.py │ │ ├── MySQLWhereSQLRecognizer.py │ │ ├── __init__.py │ │ └── antlr4 │ │ │ ├── __init__.py │ │ │ ├── util │ │ │ ├── MySQLStatementUtil.py │ │ │ ├── ParamMysqlOutputVisitor.py │ │ │ └── __init__.py │ │ │ ├── value │ │ │ ├── MySQLValue.py │ │ │ └── __init__.py │ │ │ └── visit │ │ │ ├── MySQLDeleteStatement.py │ │ │ ├── MySQLInsertStatement.py │ │ │ ├── MySQLSelectForUpdateStatement.py │ │ │ ├── MySQLUpdateStatement.py │ │ │ └── __init__.py │ └── util │ │ ├── CollectionUtil.py │ │ ├── JdbcConstants.py │ │ ├── SQLUtil.py │ │ └── __init__.py ├── test │ ├── ConfigurationTest.py │ ├── EnumTest.py │ ├── InsertTest.py │ ├── MySQLStatementTest.py │ ├── ProtobufTest.py │ ├── RpcTest.py │ ├── SqlParserTest.py │ ├── SqlTest.py │ └── __init__.py └── tm │ ├── DefaultTransactionManager.py │ ├── TMClient.py │ ├── TMHandler.py │ ├── TransactionalTemplate.py │ ├── __init__.py │ └── api │ ├── DefaultGlobalTransaction.py │ ├── GlobalTransaction.py │ ├── GlobalTransactionContext.py │ ├── GlobalTransactionRole.py │ ├── TransactionalExecutor.py │ └── __init__.py ├── setup.py └── tool └── protoc ├── osx ├── bin │ └── protoc └── include │ └── google │ └── protobuf │ ├── any.proto │ ├── api.proto │ ├── compiler │ └── plugin.proto │ ├── descriptor.proto │ ├── duration.proto │ ├── empty.proto │ ├── field_mask.proto │ ├── source_context.proto │ ├── struct.proto │ ├── timestamp.proto │ ├── type.proto │ └── wrappers.proto └── windows ├── bin └── protoc.exe ├── include └── google │ └── protobuf │ ├── any.proto │ ├── api.proto │ ├── compiler │ └── plugin.proto │ ├── descriptor.proto │ ├── duration.proto │ ├── empty.proto │ ├── field_mask.proto │ ├── source_context.proto │ ├── struct.proto │ ├── timestamp.proto │ ├── type.proto │ └── wrappers.proto └── readme.txt /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report a bug 4 | labels: kind/bug 5 | 6 | --- 7 | 8 | 11 | 12 | 13 | **What happened**: 14 | 15 | **What you expected to happen**: 16 | 17 | **How to reproduce it (as minimally and precisely as possible)**: 18 | 19 | **Anything else we need to know?**: 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Enhancement Request 3 | about: Suggest an enhancement 4 | labels: kind/feature 5 | 6 | --- 7 | 8 | 9 | **What would you like to be added**: 10 | 11 | **Why is this needed**: -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 3 | 4 | **What this PR does**: 5 | 6 | **Which issue(s) this PR fixes**: 7 | 12 | Fixes # 13 | 14 | **Special notes for your reviewer**: 15 | 16 | **Does this PR introduce a user-facing change?**: 17 | 22 | ```release-note 23 | 24 | ``` -------------------------------------------------------------------------------- /.github/auto-comment.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | # Comment to a new issue. 21 | issueOpened: > 22 | Thank your for raising a issue. We will try and get back to you as soon as possible. 23 | Please make sure you have given us as much context as possible. 24 | pullRequestOpened: > 25 | Thank your for raising your pull request. 26 | Please make sure you have followed our contributing guidelines. We will review it as soon as possible 27 | -------------------------------------------------------------------------------- /.github/licenserc.yml: -------------------------------------------------------------------------------- 1 | header: 2 | license: 3 | spdx-id: Apache-2.0 4 | copyright-owner: Apache Software Foundation 5 | content: 6 | Licensed to the Apache Software Foundation (ASF) under one or more 7 | contributor license agreements. See the NOTICE file distributed with 8 | this work for additional information regarding copyright ownership. 9 | The ASF licenses this file to You under the Apache License, Version 2.0 10 | (the "License"); you may not use this file except in compliance with 11 | the License. You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | Unless required by applicable law or agreed to in writing, software 15 | distributed under the License is distributed on an "AS IS" BASIS, 16 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | See the License for the specific language governing permissions and 18 | limitations under the License. 19 | 20 | pattern: 21 | Licensed to the Apache Software Foundation (ASF) under one or more 22 | contributor license agreements. See the NOTICE file distributed with 23 | this work for additional information regarding copyright ownership. 24 | The ASF licenses this file to You under the Apache License, Version 2.0 25 | (the "License"); you may not use this file except in compliance with 26 | the License. You may obtain a copy of the License at 27 | 28 | http://www.apache.org/licenses/LICENSE-2.0 29 | Unless required by applicable law or agreed to in writing, software 30 | distributed under the License is distributed on an "AS IS" BASIS, 31 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 32 | See the License for the specific language governing permissions and 33 | limitations under the License. 34 | 35 | paths-ignore: 36 | - 'LICENSE' 37 | - 'NOTICE' 38 | - '.github/' 39 | - 'tool/' 40 | - '**/*.md' 41 | - '**/*.txt' 42 | - '**/*.yaml' 43 | - '**/*.yml' 44 | - '**/*.gitignore' 45 | - '**/*.ini' 46 | - '**/*.in' 47 | - '**/*.cfg' 48 | - '**/*.proto' 49 | comment: on-failure 50 | -------------------------------------------------------------------------------- /.github/workflows/license-checker.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | name: License checker 21 | 22 | on: 23 | push: 24 | branches: 25 | - master 26 | pull_request: 27 | branches: 28 | - master 29 | pull_request_target: 30 | branches: 31 | - master 32 | 33 | jobs: 34 | check-license: 35 | runs-on: ubuntu-latest 36 | steps: 37 | - uses: actions/checkout@v2 38 | - name: Check License Header 39 | uses: apache/skywalking-eyes@main 40 | env: 41 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 42 | with: 43 | log: info 44 | config: .github/licenserc.yml 45 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | exclude: 'docs/|ext/' 2 | 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v4.0.1 6 | hooks: 7 | - id: check-yaml 8 | - id: debug-statements 9 | - id: end-of-file-fixer 10 | - id: trailing-whitespace 11 | - repo: https://github.com/PyCQA/isort 12 | rev: 5.10.1 13 | hooks: 14 | - id: isort 15 | - repo: https://github.com/psf/black 16 | rev: 22.3.0 17 | hooks: 18 | - id: black 19 | exclude: tests/test_lowlevel.py 20 | - repo: https://github.com/asottile/pyupgrade 21 | rev: v2.31.1 22 | hooks: 23 | - id: pyupgrade 24 | args: [--py37-plus] 25 | - repo: https://gitlab.com/pycqa/flake8 26 | rev: 4.0.1 27 | hooks: 28 | - id: flake8 29 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include seata/script/client.yml 2 | exclude seata/test/pool_config.py 3 | exclude seata/test/*my_test.py 4 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Seata-python 2 | Copyright 2019-2022 Seata.io Group. 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | 2 | # seata-python: 简单的可扩展自主事务架构(Python版本) 3 | 4 | [![Build Status](https://github.com/seata/seata/workflows/build/badge.svg?branch=develop)](https://github.com/seata/seata/actions) 5 | [![license](https://img.shields.io/github/license/seata/seata.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 6 | 7 | [English 🇺🇸](./README.md) 8 | 9 | ## 什么是 seata-python? 10 | 11 | Seata是一个非常成熟的分布式事务框架,在Java领域是事实上的分布式事务技术标准平台。Seata-python 是 seata 多语言生态中的Go语言实现版本,实现了 Java 和 Python 之间的互通,让 Python 开发者也能使用 seata-python 来实现分布式事务。请访问[Seata 官网](https://seata.io/zh-cn/)查看快速开始和文档。 12 | 13 | Seata-python 的原理和 Seata-java 保持一致,都是由 TM、RM 和 TC 组成,其中 TC 的功能复用 Java 的,TM和RM功能后面会和 Seata-java对齐,整体流程如下: 14 | 15 | ![](https://user-images.githubusercontent.com/68344696/145942191-7a2d469f-94c8-4cd2-8c7e-46ad75683636.png) 16 | 17 | ## 待办事项 18 | 19 | - [ ] TCC 20 | - [ ] XA 21 | - [x] AT 22 | - [ ] SAGA 23 | - [ ] TM 24 | - [x] RPC 通信 25 | - [ ] 事务防悬挂 26 | - [ ] 空补偿 27 | - [ ] 配置中心 28 | - [ ] 注册中心 29 | - [ ] Metric监控 30 | - [x] Sample例子 31 | 32 | 33 | ## 如何运行项目? 34 | 35 | 1. 首先下载 [**Seata Java**](https://github.com/seata/seata/tree/v1.5.2) 的源码,启动 TC 服务即可,具体流程参考 **[Seata部署指南](https://seata.io/zh-cn/docs/ops/deploy-guide-beginner.ht)**文档 36 | 2. 执行根目录下的 samples/ 下的 main 函数即可 37 | 38 | python# 如何给Seata-python贡献代码? 39 | 40 | Seata-python 目前正在建设阶段,欢迎行业同仁入群参与其中,与我们一起推动 seata-python 的建设!如果你想给 seata-python 贡献代码,可以参考 **[代码贡献规范](./CONTRIBUTING_CN.md)** 文档来了解社区的规范,也可以加入我们的社区钉钉群:44788121,一起沟通交流! 41 | 42 | ## 协议 43 | 44 | Seata-python 使用 Apache 许可证2.0版本,请参阅 LICENSE 文件了解更多。 -------------------------------------------------------------------------------- /flask-sample/.gitignore: -------------------------------------------------------------------------------- 1 | pool_config.py -------------------------------------------------------------------------------- /flask-sample/README.md: -------------------------------------------------------------------------------- 1 | 1. 安装依赖 requirements.txt 2 | 2. 增加pool_config.py文件 3 | ``` 4 | host = "localhost" 5 | port = 3306 6 | user = "" 7 | password = "" 8 | database = "" 9 | ``` 10 | 3. 创建表 11 | ``` 12 | create table `test` ( 13 | `id` int(11) not null auto_increment, 14 | `name` varchar(20), 15 | `created` datetime, 16 | primary key (`id`) 17 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 18 | 19 | CREATE TABLE `undo_log` ( 20 | `branch_id` bigint(20) NOT NULL COMMENT 'branch transaction id', 21 | `xid` varchar(128) NOT NULL COMMENT 'global transaction id', 22 | `context` varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization', 23 | `rollback_info` longblob NOT NULL COMMENT 'rollback info', 24 | `log_status` int(11) NOT NULL COMMENT '0:normal status,1:defense status', 25 | `log_created` datetime(6) NOT NULL COMMENT 'create datetime', 26 | `log_modified` datetime(6) NOT NULL COMMENT 'modify datetime', 27 | UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) 28 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='AT transaction mode undo table'; 29 | ``` 30 | 4. 启动flask_test.py 31 | 5. 启动flask_test2.py 32 | 6. 浏览器或者http工具访问 33 | ``` 34 | rollback 35 | http://127.0.0.1:8001/hello2?e=true 36 | commit 37 | http://127.0.0.1:8001/hello2?e=false 38 | ``` -------------------------------------------------------------------------------- /flask-sample/client.yml: -------------------------------------------------------------------------------- 1 | application-id: applicationName 2 | tx-service-group: my_test_tx_group 3 | config: 4 | type: file # file, nacos 5 | nacos: 6 | namespace: "" 7 | server-addr: 127.0.0.1:8848 8 | group: SEATA_GROUP 9 | username: "" 10 | password: "" 11 | data-id: seata.properties 12 | registry: 13 | type: file # file, nacos 14 | nacos: 15 | application: seata-server 16 | server-addr: 127.0.0.1:8848 17 | group: "SEATA_GROUP" 18 | namespace: "" 19 | username: "" 20 | password: "" 21 | # file mode 22 | client: 23 | rm: 24 | report-retry-count: 5 25 | table-meta-check-enable: false 26 | report-success-enable: false 27 | lock: 28 | retry-interval: 0.01 # seconds 29 | retry-times: 30 30 | retry-policy-branch-rollback-on-conflict: true 31 | tm: 32 | commit-retry-count: 5 33 | rollback-retry-count: 5 34 | default-global-transaction-timeout: 60000 35 | undo: 36 | data-validation: true 37 | log-table: undo_log 38 | only-care-update-columns: true 39 | service: 40 | vgroupMapping: 41 | my_test_tx_group: default 42 | grouplist: 43 | default: "127.0.0.1:8091" -------------------------------------------------------------------------------- /flask-sample/db.py: -------------------------------------------------------------------------------- 1 | # -- coding: utf-8 -- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import pymysql 20 | from dbutils.pooled_db import PooledDB 21 | from seata.rm.datasource.DataSourceProxy import DataSourceProxy 22 | from seata.sqlparser.util.JdbcConstants import JdbcConstants 23 | 24 | import pool_config 25 | 26 | 27 | def get_pool(): 28 | host = pool_config.host 29 | port = pool_config.port 30 | user = pool_config.user 31 | password = pool_config.password 32 | database = pool_config.database 33 | return PooledDB(creator=pymysql, host=host, port=port, user=user, password=password, database=database) 34 | 35 | 36 | class DB: 37 | pool = None 38 | data_source_proxy = None 39 | 40 | @classmethod 41 | def init(cls): 42 | if cls.pool is None: 43 | cls.pool = get_pool() 44 | if cls.data_source_proxy is None: 45 | cls.data_source_proxy = DataSourceProxy(cls.pool, JdbcConstants.MYSQL) 46 | 47 | @classmethod 48 | def get_data_source(cls): 49 | return cls.data_source_proxy 50 | -------------------------------------------------------------------------------- /flask-sample/requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML==5.4.1 2 | flask==2.0.1 3 | requests==2.26.0 4 | seata-python==0.1 -------------------------------------------------------------------------------- /flask-sample/test_dao.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import datetime 20 | 21 | from db import DB 22 | 23 | 24 | class TestDao: 25 | 26 | @classmethod 27 | def insert(cls): 28 | con = None 29 | try: 30 | con = DB.get_data_source().connection() 31 | cursor = con.cursor() 32 | cursor.execute("insert into test values(%s, %s, %s)", (None, 'namexx', datetime.datetime.now())) 33 | con.commit() 34 | except Exception: 35 | con.rollback() 36 | finally: 37 | if con is not None: 38 | try: 39 | con.close() 40 | except Exception: 41 | pass 42 | -------------------------------------------------------------------------------- /flask-sample/test_service.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.tm.TransactionalTemplate import GlobalTransactional 20 | 21 | from test_dao import TestDao 22 | 23 | 24 | class TestService: 25 | 26 | @classmethod 27 | @GlobalTransactional() 28 | def save(cls, e): 29 | TestDao.insert() 30 | if e.lower() == 'true': 31 | raise RuntimeError('rollback') 32 | -------------------------------------------------------------------------------- /flask-sample/test_service2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import requests 20 | from seata.core.context.RootContext import RootContext 21 | from seata.tm.TransactionalTemplate import GlobalTransactional 22 | 23 | from test_dao import TestDao 24 | 25 | 26 | class TestService: 27 | 28 | @classmethod 29 | @GlobalTransactional() 30 | def save(cls, e): 31 | TestDao.insert() 32 | # http request pass `KEY_XID` 33 | headers = { 34 | RootContext.KEY_XID: RootContext.get_xid() 35 | } 36 | r = requests.get('http://127.0.0.1:8000/hello?e=' + e, headers=headers) 37 | if r.status_code > 299: 38 | raise RuntimeError('rollback') 39 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | DBUtils==2.0 2 | antlr4-mysql==0.1.1 3 | protobuf==3.17.3 4 | PyYAML==5.4.1 5 | loguru==0.5.3 -------------------------------------------------------------------------------- /seata/Boostrap.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import threading 20 | 21 | from seata.rm.RMClient import RMClient 22 | from seata.tm.TMClient import TMClient 23 | 24 | 25 | class Bootstrap(object): 26 | 27 | @classmethod 28 | def start(cls): 29 | pass 30 | -------------------------------------------------------------------------------- /seata/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/boot/GlobalTransactionScanner.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.rm.RMClient import RMClient 20 | from seata.tm.TMClient import TMClient 21 | from seata.config.Config import ConfigFactory 22 | 23 | 24 | class GlobalTransactionScanner: 25 | _init = False 26 | 27 | def __init__(self): 28 | config = ConfigFactory.get_config() 29 | self.application_id = config.get('application-id') 30 | self.transaction_service_group = config.get('tx-service-group') 31 | if not self._init: 32 | self._init = True 33 | self._init_client() 34 | 35 | def _init_client(self): 36 | tm = TMClient.get(self.application_id, self.transaction_service_group) 37 | tm.init_client() 38 | 39 | rm = RMClient.get(self.application_id, self.transaction_service_group) 40 | rm.init_client() 41 | -------------------------------------------------------------------------------- /seata/boot/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/config/Configuration.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import os 20 | 21 | from seata.log.LogConfiguration import LogConfiguration 22 | 23 | 24 | class Configuration: 25 | 26 | def __init__(self, path): 27 | LogConfiguration() 28 | os.environ['config.name'] = path 29 | # 1. 读取client.yml 30 | # 2. 从client.yml中读取config节点配置 31 | # 3. 从client.yml中读取registry节点配置 32 | pass 33 | -------------------------------------------------------------------------------- /seata/config/NacosConfig.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.config.Config import Config 20 | 21 | 22 | class NacosConfig(Config): 23 | 24 | def __init__(self): 25 | pass 26 | -------------------------------------------------------------------------------- /seata/config/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/core/Number.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class Number(object): 21 | SHORT_MAX_VALUE = 32767 22 | -------------------------------------------------------------------------------- /seata/core/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ -------------------------------------------------------------------------------- /seata/core/c/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/core/compressor/CompressorFactory.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.exception.NotSupportYetException import NotSupportYetException 20 | 21 | 22 | class CompressorFactory(object): 23 | 24 | @staticmethod 25 | def get(compressor_type=0): 26 | if compressor_type == 0: 27 | from seata.core.compressor.DefaultCompressor import DefaultCompressor 28 | return DefaultCompressor() 29 | else: 30 | raise NotSupportYetException('not support compress type {}'.format(compressor_type)) 31 | -------------------------------------------------------------------------------- /seata/core/compressor/CompressorType.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from enum import Enum 20 | 21 | 22 | class CompressorType(Enum): 23 | 24 | NONE = 0 25 | 26 | GZIP = 1 -------------------------------------------------------------------------------- /seata/core/compressor/DefaultCompressor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | 21 | class DefaultCompressor(object): 22 | 23 | def __init__(self): 24 | pass 25 | 26 | def compress(self, byte_array): 27 | return byte_array 28 | 29 | def decompress(self, byte_array): 30 | return byte_array 31 | -------------------------------------------------------------------------------- /seata/core/compressor/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/core/context/ContextCore.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import threading 20 | 21 | core = None 22 | lock = threading.RLock() 23 | 24 | 25 | class ContextCore(object): 26 | threadLocal = threading.local() 27 | 28 | @staticmethod 29 | def get_instance(): 30 | global core, lock 31 | if core is None: 32 | with lock: 33 | if core is None: 34 | core = ContextCore() 35 | return core 36 | 37 | def put(self, key, value): 38 | setattr(self.threadLocal, key, value) 39 | 40 | def get(self, key): 41 | try: 42 | return getattr(self.threadLocal, key) 43 | except AttributeError: 44 | return None 45 | 46 | def remove(self, key): 47 | delattr(self.threadLocal, key) 48 | 49 | def entries(self): 50 | return vars(self.threadLocal) 51 | -------------------------------------------------------------------------------- /seata/core/context/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/core/model/BranchType.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from enum import Enum 20 | 21 | 22 | class BranchType(Enum): 23 | AT = 0 24 | TCC = 1 25 | SAGA = 2 26 | XA = 3 27 | 28 | -------------------------------------------------------------------------------- /seata/core/model/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/core/protocol/HeartbeatMessage.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol.MessageType import MessageType 20 | from seata.core.protocol.MessageTypeAware import MessageTypeAware 21 | 22 | 23 | class HeartbeatMessage(MessageTypeAware): 24 | ping = True 25 | 26 | def __init__(self, ping): 27 | self.ping = ping 28 | 29 | def set_ping(self, ping): 30 | self.ping = ping 31 | 32 | def get_ping(self): 33 | return self.ping 34 | 35 | def get_type_code(self): 36 | return MessageType.TYPE_HEARTBEAT_MSG 37 | 38 | -------------------------------------------------------------------------------- /seata/core/protocol/MergeResultMessage.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol import MessageType 20 | from seata.core.protocol.MessageTypeAware import MessageTypeAware 21 | 22 | 23 | class MergeResultMessage(MessageTypeAware): 24 | 25 | def __init__(self): 26 | self.msgs = [] 27 | 28 | def get_type_code(self): 29 | return MessageType.TYPE_SEATA_MERGE_RESULT -------------------------------------------------------------------------------- /seata/core/protocol/MergedWarpMessage.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol import MessageType 20 | from seata.core.protocol.MessageTypeAware import MessageTypeAware 21 | 22 | 23 | class MergedWarpMessage(MessageTypeAware): 24 | 25 | def __init__(self): 26 | self.msgs = [] 27 | self.msg_ids = [] 28 | 29 | def get_type_code(self): 30 | return MessageType.TYPE_SEATA_MERGE -------------------------------------------------------------------------------- /seata/core/protocol/MessageType.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class MessageType(object): 21 | 22 | TYPE_GLOBAL_BEGIN = 1 23 | 24 | TYPE_GLOBAL_BEGIN_RESULT = 2 25 | 26 | TYPE_GLOBAL_COMMIT = 7 27 | 28 | TYPE_GLOBAL_COMMIT_RESULT = 8 29 | 30 | TYPE_GLOBAL_ROLLBACK = 9 31 | 32 | TYPE_GLOBAL_ROLLBACK_RESULT = 10 33 | 34 | TYPE_GLOBAL_STATUS = 15 35 | 36 | TYPE_GLOBAL_STATUS_RESULT = 16 37 | 38 | TYPE_GLOBAL_REPORT = 17 39 | 40 | TYPE_GLOBAL_REPORT_RESULT = 18 41 | 42 | TYPE_GLOBAL_LOCK_QUERY = 21 43 | 44 | TYPE_GLOBAL_LOCK_QUERY_RESULT = 22 45 | 46 | TYPE_BRANCH_COMMIT = 3 47 | 48 | TYPE_BRANCH_COMMIT_RESULT = 4 49 | 50 | TYPE_BRANCH_ROLLBACK = 5 51 | 52 | TYPE_BRANCH_ROLLBACK_RESULT = 6 53 | 54 | TYPE_BRANCH_REGISTER = 11 55 | 56 | TYPE_BRANCH_REGISTER_RESULT = 12 57 | 58 | TYPE_BRANCH_STATUS_REPORT = 13 59 | 60 | TYPE_BRANCH_STATUS_REPORT_RESULT = 14 61 | 62 | TYPE_SEATA_MERGE = 59 63 | 64 | TYPE_SEATA_MERGE_RESULT = 60 65 | 66 | TYPE_REG_CLT = 101 67 | 68 | TYPE_REG_CLT_RESULT = 102 69 | 70 | TYPE_REG_RM = 103 71 | 72 | TYPE_REG_RM_RESULT = 104 73 | 74 | TYPE_RM_DELETE_UNDOLOG = 111 75 | 76 | TYPE_HEARTBEAT_MSG = 120 77 | 78 | def __init__(self): 79 | pass 80 | -------------------------------------------------------------------------------- /seata/core/protocol/MessageTypeAware.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class MessageTypeAware(object): 21 | 22 | def get_type_code(self): 23 | raise NotImplemented("need subclass implemented") 24 | 25 | class ResultMessage: 26 | 27 | def __init__(self): 28 | self.result_code = None 29 | self.msg = None 30 | 31 | pass 32 | -------------------------------------------------------------------------------- /seata/core/protocol/ProtocolConstants.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class ProtocolConstants(object): 21 | # Magic code 22 | MAGIC_CODE_BYTES = bytearray([0xda, 0xda]) 23 | # Protocol version 24 | VERSION = 1 25 | # Max frame length 26 | MAX_FRAME_LENGTH = 8 * 1024 * 1024 27 | # HEAD_LENGTH of protocol v1 28 | V1_HEAD_LENGTH = 16 29 | # Message type: Request 30 | MSGTYPE_RESQUEST_SYNC = 0 31 | # Message type: Response 32 | MSGTYPE_RESPONSE = 1 33 | # Message type: Request which no need response 34 | MSGTYPE_RESQUEST_ONEWAY = 2 35 | # Message type: Heartbeat Request 36 | MSGTYPE_HEARTBEAT_REQUEST = 3 37 | # Message type: Heartbeat Response 38 | MSGTYPE_HEARTBEAT_RESPONSE = 4 39 | -------------------------------------------------------------------------------- /seata/core/protocol/RegisterRMRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol import Version 20 | from seata.core.protocol.MessageType import MessageType 21 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 22 | 23 | 24 | class RegisterRMRequest(MessageTypeAware): 25 | 26 | def __init__(self, application_id=None, transaction_service_group=None, extra_data=None): 27 | self.version = Version.CURRENT 28 | self.application_id = application_id 29 | self.transaction_service_group = transaction_service_group 30 | self.extra_data = extra_data 31 | 32 | self.resource_ids = None 33 | 34 | def get_type_code(self): 35 | return MessageType.TYPE_REG_RM 36 | 37 | 38 | class RegisterRMResponse(ResultMessage, MessageTypeAware): 39 | 40 | def __init__(self, result=True): 41 | super(RegisterRMResponse, self).__init__() 42 | self.result = result 43 | 44 | self.version = Version.CURRENT 45 | self.identified = result 46 | self.extra_data = None 47 | 48 | def get_type_code(self): 49 | return MessageType.TYPE_REG_RM_RESULT 50 | -------------------------------------------------------------------------------- /seata/core/protocol/RegisterTMRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol import Version 20 | from seata.core.protocol.MessageType import MessageType 21 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 22 | 23 | 24 | class RegisterTMRequest(MessageTypeAware): 25 | UDATA_VGROUP = "vgroup" 26 | UDATA_AK = "ak" 27 | UDATA_DIGEST = "digest" 28 | UDATA_IP = "ip" 29 | UDATA_TIMESTAMP = "timestamp" 30 | 31 | def __init__(self, application_id, transaction_service_group, extra_data): 32 | self.version = Version.CURRENT 33 | self.application_id = application_id 34 | self.transaction_service_group = transaction_service_group 35 | self.extra_data = extra_data 36 | 37 | def get_type_code(self): 38 | return MessageType.TYPE_REG_CLT 39 | 40 | 41 | class RegisterTMResponse(ResultMessage, MessageTypeAware): 42 | 43 | def __init__(self, result=True): 44 | super(RegisterTMResponse, self).__init__() 45 | self.result = result 46 | 47 | self.version = Version.CURRENT 48 | self.identified = result 49 | self.extra_data = None 50 | 51 | def get_type_code(self): 52 | return MessageType.TYPE_REG_CLT_RESULT 53 | -------------------------------------------------------------------------------- /seata/core/protocol/RegisterTMRequestResponseCodec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.ByteBuffer import ByteBuffer 20 | from seata.core.protocol.AbstractIdentifyRequestResponseCodec import AbstractIdentifyRequestCodec, \ 21 | AbstractIdentifyResponseCodec 22 | 23 | 24 | class RegisterTMRequestCodec(object): 25 | 26 | def encode(self, t, out_buffer): 27 | if not isinstance(out_buffer, ByteBuffer): 28 | raise TypeError("out_buffer is not ByteBuffer class") 29 | AbstractIdentifyRequestCodec.encode(t, out_buffer) 30 | 31 | def decode(self, t, in_buffer): 32 | if not isinstance(in_buffer, ByteBuffer): 33 | raise TypeError("in_buffer is not ByteBuffer class") 34 | AbstractIdentifyRequestCodec.decode(t, in_buffer) 35 | 36 | 37 | class RegisterTMResponseCodec(object): 38 | 39 | def encode(self, t, out_buffer): 40 | if not isinstance(out_buffer, ByteBuffer): 41 | raise TypeError("out_buffer is not ByteBuffer class") 42 | AbstractIdentifyResponseCodec.encode(t, out_buffer) 43 | 44 | def decode(self, t, in_buffer): 45 | if not isinstance(in_buffer, ByteBuffer): 46 | raise TypeError("in_buffer is not ByteBuffer class") 47 | AbstractIdentifyResponseCodec.decode(t, in_buffer) 48 | -------------------------------------------------------------------------------- /seata/core/protocol/ResultCode.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from enum import Enum 20 | 21 | 22 | class ResultCode(Enum): 23 | """ 24 | Failed result code. 25 | """ 26 | Failed = 0 27 | """ 28 | Success result code. 29 | """ 30 | Success = 1 31 | 32 | -------------------------------------------------------------------------------- /seata/core/protocol/RpcMessage.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import threading 20 | 21 | atom = 0 22 | lock = threading.RLock() 23 | 24 | 25 | class RpcMessage(object): 26 | 27 | def __init__(self): 28 | # int 29 | self.id = 0 30 | # byte 31 | self.message_type = 0 32 | # byte 33 | self.codec = 0 34 | # byte 35 | self.compressor = 0 36 | # map string, string 37 | self.head_map = dict() 38 | # Object 39 | self.body = None 40 | 41 | @staticmethod 42 | def get_id(): 43 | global atom, lock 44 | with lock: 45 | atom = (atom + 1) & 0x7FFFFFFF 46 | return atom 47 | 48 | @staticmethod 49 | def build_request_message(msg, message_type): 50 | rpc_message = RpcMessage() 51 | rpc_message.id = RpcMessage.get_id() 52 | rpc_message.message_type = message_type 53 | # TODO 54 | rpc_message.codec = 0x1 55 | rpc_message.compressor = 0x0 56 | rpc_message.body = msg 57 | return rpc_message 58 | 59 | @classmethod 60 | def build_response_message(cls, rpc_message, msg, message_type): 61 | rpc_msg = RpcMessage() 62 | rpc_msg.message_type = message_type 63 | rpc_msg.codec = rpc_message.codec 64 | rpc_msg.compressor = rpc_message.compressor 65 | rpc_msg.body = msg 66 | rpc_msg.id = rpc_message.id 67 | return rpc_msg 68 | -------------------------------------------------------------------------------- /seata/core/protocol/Version.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | CURRENT = "1.0" -------------------------------------------------------------------------------- /seata/core/protocol/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/AbstractTransactionRequestResponseCodec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.ByteBuffer import ByteBuffer 20 | from seata.core.protocol.AbstractResultMessageCodec import AbstractResultMessageCodec 21 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 22 | 23 | 24 | class AbstractTransactionResponseCodec(object): 25 | 26 | @staticmethod 27 | def encode(t, out_buffer): 28 | if not isinstance(out_buffer, ByteBuffer): 29 | raise TypeError("out_buffer is not ByteBuffer class") 30 | AbstractResultMessageCodec.encode(t, out_buffer) 31 | transaction_exception_code = t.transaction_exception_code 32 | out_buffer.put_int8(transaction_exception_code.value) 33 | 34 | @staticmethod 35 | def decode(t, in_buffer): 36 | if not isinstance(in_buffer, ByteBuffer): 37 | raise TypeError("in_buffer is not ByteBuffer class") 38 | AbstractResultMessageCodec.decode(t, in_buffer) 39 | tec = in_buffer.get_int8() 40 | t.transaction_exception_code = TransactionExceptionCode(tec) 41 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/BranchCommitRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.model.BranchType import BranchType 20 | from seata.core.protocol.MessageType import MessageType 21 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 22 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 23 | 24 | 25 | class BranchCommitRequest(MessageTypeAware): 26 | 27 | def __init__(self): 28 | self.xid = None 29 | self.branch_id = 0 30 | self.branch_type = BranchType.AT 31 | self.resource_id = None 32 | self.application_data = None 33 | 34 | def get_type_code(self): 35 | return MessageType.TYPE_BRANCH_COMMIT 36 | 37 | 38 | class BranchCommitResponse(ResultMessage, MessageTypeAware): 39 | 40 | def __init__(self): 41 | super(BranchCommitResponse, self).__init__() 42 | self.xid = None 43 | self.branch_id = 0 44 | self.branch_status = None 45 | 46 | self.transaction_exception_code = TransactionExceptionCode.Unknown 47 | self.result_code = None 48 | self.msg = None 49 | 50 | def get_type_code(self): 51 | return MessageType.TYPE_BRANCH_COMMIT_RESULT 52 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/BranchCommitRequestResponseCodec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.ByteBuffer import ByteBuffer 20 | from seata.core.protocol.transaction.AbstractBranchEndRequestResponseCodec import AbstractBranchEndRequestCodec, \ 21 | AbstractBranchEndResponseCodec 22 | 23 | 24 | class BranchCommitRequestCodec(object): 25 | 26 | def __init__(self): 27 | pass 28 | 29 | def encode(self, t, out_buffer): 30 | if not isinstance(out_buffer, ByteBuffer): 31 | raise TypeError("out_buffer is not ByteBuffer") 32 | AbstractBranchEndRequestCodec.encode(t, out_buffer) 33 | 34 | def decode(self, t, in_buffer): 35 | if not isinstance(in_buffer, ByteBuffer): 36 | raise TypeError("in_buffer is not ByteBuffer") 37 | AbstractBranchEndRequestCodec.decode(t, in_buffer) 38 | 39 | 40 | class BranchCommitResponseCodec(object): 41 | 42 | def __init__(self): 43 | pass 44 | 45 | def encode(self, t, out_buffer): 46 | AbstractBranchEndResponseCodec.encode(t, out_buffer) 47 | 48 | def decode(self, t, in_buffer): 49 | AbstractBranchEndResponseCodec.decode(t, in_buffer) 50 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/BranchRegisterRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.model.BranchType import BranchType 20 | from seata.core.protocol.MessageType import MessageType 21 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 22 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 23 | 24 | 25 | class BranchRegisterRequest(MessageTypeAware): 26 | 27 | def __int__(self): 28 | self.xid = None 29 | self.branch_type = BranchType.AT 30 | self.resource_id = None 31 | self.lock_key = None 32 | self.application_data = None 33 | 34 | def get_type_code(self): 35 | return MessageType.TYPE_BRANCH_REGISTER 36 | 37 | 38 | class BranchRegisterResponse(ResultMessage, MessageTypeAware): 39 | 40 | def __init__(self): 41 | super(BranchRegisterResponse, self).__init__() 42 | self.branch_id = 0 43 | 44 | self.transaction_exception_code = TransactionExceptionCode.Unknown 45 | self.result_code = None 46 | self.msg = None 47 | 48 | def get_type_code(self): 49 | return MessageType.TYPE_BRANCH_REGISTER_RESULT 50 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/BranchReportRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.model.BranchType import BranchType 20 | from seata.core.protocol.MessageType import MessageType 21 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 22 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 23 | 24 | 25 | class BranchReportRequest(MessageTypeAware): 26 | 27 | def __int__(self): 28 | self.xid = None 29 | self.branch_id = 0 30 | self.resource_id = None 31 | self.status = None 32 | self.application_data = None 33 | self.branch_type = BranchType.AT 34 | 35 | def get_type_code(self): 36 | return MessageType.TYPE_BRANCH_STATUS_REPORT 37 | 38 | 39 | class BranchReportResponse(ResultMessage, MessageTypeAware): 40 | 41 | def __init__(self): 42 | super(BranchReportResponse, self).__init__() 43 | self.branch_id = 0 44 | 45 | self.transaction_exception_code = TransactionExceptionCode.Unknown 46 | self.result_code = None 47 | self.msg = None 48 | 49 | def get_type_code(self): 50 | return MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT 51 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/BranchRollbackRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.model.BranchType import BranchType 20 | from seata.core.protocol.MessageType import MessageType 21 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 22 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 23 | 24 | 25 | class BranchRollbackRequest(MessageTypeAware): 26 | 27 | def __int__(self): 28 | self.xid = None 29 | self.branch_id = 0 30 | self.branch_type = BranchType.AT 31 | self.resource_id = None 32 | self.application_data = None 33 | 34 | def get_type_code(self): 35 | return MessageType.TYPE_BRANCH_ROLLBACK 36 | 37 | 38 | class BranchRollbackResponse(ResultMessage, MessageTypeAware): 39 | 40 | def __init__(self): 41 | super(BranchRollbackResponse, self).__init__() 42 | self.xid = None 43 | self.branch_id = 0 44 | self.branch_status = None 45 | 46 | self.transaction_exception_code = TransactionExceptionCode.Unknown 47 | self.result_code = None 48 | self.msg = None 49 | 50 | def get_type_code(self): 51 | return MessageType.TYPE_BRANCH_ROLLBACK_RESULT 52 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/BranchRollbackRequestResponseCodec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.ByteBuffer import ByteBuffer 20 | from seata.core.protocol.transaction.AbstractBranchEndRequestResponseCodec import AbstractBranchEndRequestCodec, \ 21 | AbstractBranchEndResponseCodec 22 | 23 | 24 | class BranchRollbackRequestCodec(object): 25 | 26 | def __init__(self): 27 | pass 28 | 29 | def encode(self, t, out_buffer): 30 | if not isinstance(out_buffer, ByteBuffer): 31 | raise TypeError("out_buffer is not ByteBuffer") 32 | AbstractBranchEndRequestCodec.encode(t, out_buffer) 33 | 34 | def decode(self, t, in_buffer): 35 | if not isinstance(in_buffer, ByteBuffer): 36 | raise TypeError("in_buffer is not ByteBuffer") 37 | AbstractBranchEndRequestCodec.decode(t, in_buffer) 38 | 39 | 40 | class BranchRollbackResponseCodec(object): 41 | 42 | def __init__(self): 43 | pass 44 | 45 | def encode(self, t, out_buffer): 46 | if not isinstance(out_buffer, ByteBuffer): 47 | raise TypeError("out_buffer is not ByteBuffer") 48 | AbstractBranchEndResponseCodec.encode(t, out_buffer) 49 | 50 | def decode(self, t, in_buffer): 51 | if not isinstance(in_buffer, ByteBuffer): 52 | raise TypeError("in_buffer is not ByteBuffer") 53 | AbstractBranchEndResponseCodec.decode(t, in_buffer) 54 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/GlobalBeginRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol.MessageType import MessageType 20 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 21 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 22 | 23 | 24 | class GlobalBeginRequest(MessageTypeAware): 25 | 26 | def __int__(self): 27 | self.timeout = 60000 28 | self.transaction_name = None 29 | 30 | def get_type_code(self): 31 | return MessageType.TYPE_GLOBAL_BEGIN 32 | 33 | 34 | class GlobalBeginResponse(ResultMessage, MessageTypeAware): 35 | 36 | def __init__(self): 37 | super(GlobalBeginResponse, self).__init__() 38 | self.xid = None 39 | self.extra_data = None 40 | 41 | self.transaction_exception_code = TransactionExceptionCode.Unknown 42 | self.result_code = None 43 | self.msg = None 44 | 45 | def get_type_code(self): 46 | return MessageType.TYPE_GLOBAL_BEGIN_RESULT 47 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/GlobalCommitRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol.MessageType import MessageType 20 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 21 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 22 | 23 | 24 | class GlobalCommitRequest(MessageTypeAware): 25 | 26 | def __int__(self): 27 | self.xid = None 28 | self.extra_data = None 29 | 30 | def get_type_code(self): 31 | return MessageType.TYPE_GLOBAL_COMMIT 32 | 33 | 34 | class GlobalCommitResponse(ResultMessage, MessageTypeAware): 35 | 36 | def __init__(self): 37 | super(GlobalCommitResponse, self).__init__() 38 | self.global_status = None 39 | 40 | self.transaction_exception_code = TransactionExceptionCode.Unknown 41 | self.result_code = None 42 | self.msg = None 43 | 44 | def get_type_code(self): 45 | return MessageType.TYPE_GLOBAL_COMMIT_RESULT 46 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/GlobalCommitRequestResponseCodec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.ByteBuffer import ByteBuffer 20 | from seata.core.protocol.transaction.AbstractGlobalEndRequestResponseCodec import AbstractGlobalEndRequestCodec, \ 21 | AbstractGlobalEndResponseCodec 22 | 23 | 24 | class GlobalCommitRequestCodec(object): 25 | 26 | def __init__(self): 27 | pass 28 | 29 | def encode(self, t, out_buffer): 30 | if not isinstance(out_buffer, ByteBuffer): 31 | raise TypeError("out_buffer is not ByteBuffer") 32 | AbstractGlobalEndRequestCodec.encode(t, out_buffer) 33 | 34 | def decode(self, t, in_buffer): 35 | if not isinstance(in_buffer, ByteBuffer): 36 | raise TypeError("in_buffer is not ByteBuffer") 37 | AbstractGlobalEndRequestCodec.decode(t, in_buffer) 38 | 39 | 40 | class GlobalCommitResponseCodec(object): 41 | 42 | def __init__(self): 43 | pass 44 | 45 | def encode(self, t, out_buffer): 46 | if not isinstance(out_buffer, ByteBuffer): 47 | raise TypeError("out_buffer is not ByteBuffer") 48 | AbstractGlobalEndResponseCodec.encode(t, out_buffer) 49 | 50 | def decode(self, t, in_buffer): 51 | if not isinstance(in_buffer, ByteBuffer): 52 | raise TypeError("in_buffer is not ByteBuffer") 53 | AbstractGlobalEndResponseCodec.decode(t, in_buffer) 54 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/GlobalLockQueryRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.model.BranchType import BranchType 20 | from seata.core.protocol.MessageType import MessageType 21 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 22 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 23 | 24 | 25 | class GlobalLockQueryRequest(MessageTypeAware): 26 | 27 | def __int__(self): 28 | self.xid = None 29 | self.branch_type = BranchType.AT 30 | self.resource_id = None 31 | self.lock_key = None 32 | self.application_data = None 33 | 34 | def get_type_code(self): 35 | return MessageType.TYPE_GLOBAL_LOCK_QUERY 36 | 37 | 38 | class GlobalLockQueryResponse(ResultMessage, MessageTypeAware): 39 | 40 | def __init__(self): 41 | super(GlobalLockQueryResponse, self).__init__() 42 | self.lockable = False 43 | 44 | self.transaction_exception_code = TransactionExceptionCode.Unknown 45 | self.result_code = None 46 | self.msg = None 47 | 48 | def get_type_code(self): 49 | return MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT 50 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/GlobalReportRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol.MessageType import MessageType 20 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 21 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 22 | 23 | 24 | class GlobalReportRequest(MessageTypeAware): 25 | 26 | def __int__(self): 27 | self.xid = None 28 | self.extra_data = None 29 | self.global_status = None 30 | 31 | def get_type_code(self): 32 | return MessageType.TYPE_GLOBAL_REPORT 33 | 34 | 35 | class GlobalReportResponse(ResultMessage, MessageTypeAware): 36 | 37 | def __init__(self): 38 | super(GlobalReportResponse, self).__init__() 39 | self.global_status = None 40 | 41 | self.transaction_exception_code = TransactionExceptionCode.Unknown 42 | self.result_code = None 43 | self.msg = None 44 | 45 | def get_type_code(self): 46 | return MessageType.TYPE_GLOBAL_REPORT_RESULT 47 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/GlobalRollbackRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol.MessageType import MessageType 20 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 21 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 22 | 23 | 24 | class GlobalRollbackRequest(MessageTypeAware): 25 | 26 | def __int__(self): 27 | self.xid = None 28 | self.extra_data = None 29 | 30 | def get_type_code(self): 31 | return MessageType.TYPE_GLOBAL_ROLLBACK 32 | 33 | 34 | class GlobalRollbackResponse(ResultMessage, MessageTypeAware): 35 | 36 | def __init__(self): 37 | super(GlobalRollbackResponse, self).__init__() 38 | self.global_status = None 39 | 40 | self.transaction_exception_code = TransactionExceptionCode.Unknown 41 | self.result_code = None 42 | self.msg = None 43 | 44 | def get_type_code(self): 45 | return MessageType.TYPE_GLOBAL_ROLLBACK_RESULT 46 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/GlobalRollbackRequestResponseCodec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.ByteBuffer import ByteBuffer 20 | from seata.core.protocol.transaction.AbstractGlobalEndRequestResponseCodec import AbstractGlobalEndRequestCodec, \ 21 | AbstractGlobalEndResponseCodec 22 | 23 | 24 | class GlobalRollbackRequestCodec(object): 25 | 26 | def __init__(self): 27 | pass 28 | 29 | def encode(self, t, out_buffer): 30 | if not isinstance(out_buffer, ByteBuffer): 31 | raise TypeError("out_buffer is not ByteBuffer") 32 | AbstractGlobalEndRequestCodec.encode(t, out_buffer) 33 | 34 | def decode(self, t, in_buffer): 35 | if not isinstance(in_buffer, ByteBuffer): 36 | raise TypeError("in_buffer is not ByteBuffer") 37 | AbstractGlobalEndRequestCodec.decode(t, in_buffer) 38 | 39 | 40 | class GlobalRollbackResponseCodec(object): 41 | 42 | def __init__(self): 43 | pass 44 | 45 | def encode(self, t, out_buffer): 46 | if not isinstance(out_buffer, ByteBuffer): 47 | raise TypeError("out_buffer is not ByteBuffer") 48 | AbstractGlobalEndResponseCodec.encode(t, out_buffer) 49 | 50 | def decode(self, t, in_buffer): 51 | if not isinstance(in_buffer, ByteBuffer): 52 | raise TypeError("in_buffer is not ByteBuffer") 53 | AbstractGlobalEndResponseCodec.decode(t, in_buffer) 54 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/GlobalStatusRequestResponse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.protocol.MessageType import MessageType 20 | from seata.core.protocol.MessageTypeAware import MessageTypeAware, ResultMessage 21 | from seata.exception.TransactionExceptionCode import TransactionExceptionCode 22 | 23 | 24 | class GlobalStatusRequest(ResultMessage, MessageTypeAware): 25 | 26 | def __int__(self): 27 | self.xid = None 28 | self.extra_data = None 29 | 30 | def get_type_code(self): 31 | return MessageType.TYPE_GLOBAL_STATUS 32 | 33 | 34 | class GlobalStatusResponse(ResultMessage, MessageTypeAware): 35 | 36 | def __init__(self): 37 | super(GlobalStatusResponse, self).__init__() 38 | self.global_status = None 39 | 40 | self.transaction_exception_code = TransactionExceptionCode.Unknown 41 | self.result_code = None 42 | self.msg = None 43 | 44 | def get_type_code(self): 45 | return MessageType.TYPE_GLOBAL_STATUS_RESULT 46 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/GlobalStatusRequestResponseCodec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.ByteBuffer import ByteBuffer 20 | from seata.core.protocol.transaction.AbstractGlobalEndRequestResponseCodec import AbstractGlobalEndRequestCodec, \ 21 | AbstractGlobalEndResponseCodec 22 | 23 | 24 | class GlobalStatusRequestCodec(object): 25 | 26 | def __init__(self): 27 | pass 28 | 29 | def encode(self, t, out_buffer): 30 | if not isinstance(out_buffer, ByteBuffer): 31 | raise TypeError("out_buffer is not ByteBuffer") 32 | AbstractGlobalEndRequestCodec.encode(t, out_buffer) 33 | 34 | def decode(self, t, in_buffer): 35 | if not isinstance(in_buffer, ByteBuffer): 36 | raise TypeError("in_buffer is not ByteBuffer") 37 | AbstractGlobalEndRequestCodec.decode(t, in_buffer) 38 | 39 | 40 | class GlobalStatusResponseCodec(object): 41 | 42 | def __init__(self): 43 | pass 44 | 45 | def encode(self, t, out_buffer): 46 | if not isinstance(out_buffer, ByteBuffer): 47 | raise TypeError("out_buffer is not ByteBuffer") 48 | AbstractGlobalEndResponseCodec.encode(t, out_buffer) 49 | 50 | def decode(self, t, in_buffer): 51 | if not isinstance(in_buffer, ByteBuffer): 52 | raise TypeError("in_buffer is not ByteBuffer") 53 | AbstractGlobalEndResponseCodec.decode(t, in_buffer) 54 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/UndoLogDeleteRequest.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.model.BranchType import BranchType 20 | from seata.core.protocol.MessageType import MessageType 21 | from seata.core.protocol.MessageTypeAware import MessageTypeAware 22 | 23 | 24 | class UndoLogDeleteRequest(MessageTypeAware): 25 | 26 | def __init__(self): 27 | self.resource_id = None 28 | self.save_days = 7 29 | self.branch_type = BranchType.AT 30 | 31 | def get_type_code(self): 32 | return MessageType.TYPE_RM_DELETE_UNDOLOG 33 | -------------------------------------------------------------------------------- /seata/core/protocol/transaction/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/core/rpc/Address.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | 21 | class Address: 22 | def __init__(self, host, port): 23 | self.host = host 24 | self.port = port 25 | 26 | def to_string(self): 27 | return self.host + ":" + str(self.port) 28 | -------------------------------------------------------------------------------- /seata/core/rpc/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/core/rpc/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/core/serializer/SerializerFactory.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.exception.NotSupportYetException import NotSupportYetException 20 | 21 | 22 | class SerializerFactory(object): 23 | 24 | @staticmethod 25 | def get(codec_type=1): 26 | if codec_type == 1: 27 | from seata.core.serializer.seata.SeataSerializer import SeataSerializer 28 | return SeataSerializer() 29 | else: 30 | raise NotSupportYetException('not support serialize type {}'.format(codec_type)) 31 | -------------------------------------------------------------------------------- /seata/core/serializer/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/core/serializer/seata/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ -------------------------------------------------------------------------------- /seata/core/util/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ -------------------------------------------------------------------------------- /seata/exception/NotSupportYetException.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class NotSupportYetException(RuntimeError): 21 | pass -------------------------------------------------------------------------------- /seata/exception/RmTransactionException.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.exception.TransactionException import TransactionException 20 | 21 | 22 | class RmTransactionException(TransactionException): 23 | 24 | def __init__(self, code, message=None, cause=None): 25 | self.code = code 26 | self.message = message 27 | self.cause = cause 28 | -------------------------------------------------------------------------------- /seata/exception/ShouldNeverHappenException.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class ShouldNeverHappenException(RuntimeError): 21 | pass -------------------------------------------------------------------------------- /seata/exception/TmTransactionException.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.exception.TransactionException import TransactionException 20 | 21 | 22 | class TmTransactionException(TransactionException): 23 | 24 | def __init__(self, code, message=None, cause=None): 25 | self.code = code 26 | self.message = message 27 | self.cause = cause -------------------------------------------------------------------------------- /seata/exception/TransactionException.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class TransactionException(Exception): 21 | 22 | def __init__(self, code, message=None, cause=None): 23 | self.code = code 24 | self.message = message 25 | self.cause = cause 26 | 27 | 28 | class BranchTransactionException(TransactionException): 29 | 30 | def __init__(self, code, message=None, cause=None): 31 | super(BranchTransactionException, self).__init__(code, message, cause) 32 | -------------------------------------------------------------------------------- /seata/exception/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ -------------------------------------------------------------------------------- /seata/log/LogConfiguration.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import os 20 | 21 | from loguru import logger 22 | 23 | 24 | class LogConfiguration: 25 | 26 | def __init__(self): 27 | home = os.path.expanduser('~') 28 | log_file_path = os.path.join(home, 'logs/seata/info.log') 29 | err_log_file_path = os.path.join(home, 'logs/seata/error.log') 30 | logger.add(log_file_path, rotation="500 MB", encoding='utf-8', 31 | format="{time:YYYY-MM-DD HH:mm:ss} {level} {message}", filter="", level="INFO", enqueue=True) 32 | logger.add(err_log_file_path, rotation="500 MB", encoding='utf-8', 33 | format="{time:YYYY-MM-DD HH:mm:ss} {level} {message}", filter="", level="ERROR", enqueue=True) 34 | logger.info("init logger...") 35 | -------------------------------------------------------------------------------- /seata/log/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/registry/FileRegistry.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.config.Config import ConfigFactory 20 | from seata.core.rpc.Address import Address 21 | from seata.registry.Registry import Registry 22 | 23 | 24 | class FileRegistry(Registry): 25 | config = ConfigFactory.get_config() 26 | 27 | def __init__(self): 28 | pass 29 | 30 | def register(self, address): 31 | pass 32 | 33 | def unregister(self, address): 34 | pass 35 | 36 | def subscribe(self, cluster, listener): 37 | pass 38 | 39 | def unsubscribe(self, cluster, listener): 40 | pass 41 | 42 | def lookup(self, key): 43 | cluster_name = super(FileRegistry, self).get_service_group(key) 44 | if cluster_name is None: 45 | return None 46 | endpoint_str = self.config.get('service.grouplist.' + cluster_name) 47 | endpoints = endpoint_str.split(';') 48 | addresses = [] 49 | for endpoint in endpoints: 50 | if endpoint is None or len(endpoint.strip()) == 0: 51 | continue 52 | ip_port_arr = endpoint.split(':') 53 | if len(ip_port_arr) != 2: 54 | raise ValueError('endpoint format should like ip:port') 55 | addresses.append(Address(ip_port_arr[0], int(ip_port_arr[1]))) 56 | return addresses 57 | 58 | def close(self): 59 | pass 60 | -------------------------------------------------------------------------------- /seata/registry/NacosRegistry.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.registry.Registry import Registry 20 | 21 | 22 | class NacosRegistry(Registry): 23 | 24 | def __init__(self): 25 | pass 26 | 27 | def register(self, address): 28 | pass 29 | 30 | def unregister(self, address): 31 | pass 32 | 33 | def subscribe(self, cluster, listener): 34 | pass 35 | 36 | def unsubscribe(self, cluster, listener): 37 | pass 38 | 39 | def lookup(self, key): 40 | pass 41 | 42 | def close(self): 43 | pass 44 | -------------------------------------------------------------------------------- /seata/registry/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/RMClient.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import threading 20 | 21 | from seata.core.rpc.v1.RmRemotingClient import RmRemotingClient 22 | 23 | 24 | class RMClient(object): 25 | client = None 26 | lock = threading.RLock() 27 | 28 | @classmethod 29 | def get(cls, application_id=None, transaction_service_group=None): 30 | if cls.client is None: 31 | try: 32 | cls.lock.acquire() 33 | if cls.client is None: 34 | cls.client = RMClient(application_id, transaction_service_group) 35 | finally: 36 | cls.lock.release() 37 | return cls.client 38 | 39 | def __init__(self, application_id=None, transaction_service_group=None): 40 | self.application_id = application_id 41 | self.transaction_service_group = transaction_service_group 42 | self.remote_client = None 43 | from seata.rm.DefaultResourceManager import DefaultResourceManager 44 | self.resource_manager = DefaultResourceManager.get() 45 | 46 | def init_client(self): 47 | from seata.rm.RMHandlerAT import RMHandlerAT 48 | message_handler = RMHandlerAT() 49 | self.remote_client = RmRemotingClient.get_client(self.application_id, self.transaction_service_group, 50 | message_handler) 51 | -------------------------------------------------------------------------------- /seata/rm/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/datasource/Types.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | 21 | class Types: 22 | BIT = -7 23 | TINYINT = -6 24 | SMALLINT = 5 25 | INTEGER = 4 26 | BIGINT = -5 27 | FLOAT = 6 28 | REAL = 7 29 | DOUBLE = 8 30 | NUMERIC = 2 31 | DECIMAL = 3 32 | CHAR = 1 33 | VARCHAR = 12 34 | LONGVARCHAR = -1 35 | DATE = 91 36 | TIME = 92 37 | TIMESTAMP = 93 38 | BINARY = -2 39 | VARBINARY = -3 40 | LONGVARBINARY = -4 41 | 42 | NULL = 0 43 | OTHER = 1111 44 | JAVA_OBJECT = 2000 45 | DISTINCT = 2001 46 | STRUCT = 2002 47 | ARRAY = 2003 48 | BLOB = 2004 49 | CLOB = 2005 50 | REF = 2006 51 | DATALINK = 70 52 | 53 | BOOLEAN = 16 54 | ROWID = -8 55 | NCHAR = -15 56 | NVARCHAR = -9 57 | LONGNVARCHAR = -16 58 | NCLOB = 2011 59 | SQLXML = 2009 60 | REF_CURSOR = 2012 61 | 62 | TIME_WITH_TIMEZONE = 2013 63 | TIMESTAMP_WITH_TIMEZONE = 2014 64 | 65 | # mysql 66 | INT = 4 67 | DATETIME = 93 68 | TINYTEXT = 2005 69 | TEXT = 2005 70 | MEDIUMTEXT = 2005 71 | LONGTEXT = 2005 72 | JSON = 2005 73 | 74 | @classmethod 75 | def get(cls, name: str): 76 | return getattr(cls, name.upper(), None) 77 | -------------------------------------------------------------------------------- /seata/rm/datasource/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/datasource/exception/SQLException.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class SQLException(RuntimeError): 21 | pass 22 | -------------------------------------------------------------------------------- /seata/rm/datasource/exception/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/datasource/executor/CursorCallback.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | 21 | class CursorCallback: 22 | 23 | def __init__(self, func_name): 24 | self.func_name = func_name 25 | 26 | def execute(self, target, sql, parameters): 27 | """ 28 | :param target: cursor 29 | :param sql: sql 30 | :param parameters: parameters 31 | :return: 32 | """ 33 | return getattr(target, self.func_name)(sql, parameters) 34 | -------------------------------------------------------------------------------- /seata/rm/datasource/executor/LockConflictException.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | 21 | class LockConflictException(RuntimeError): 22 | pass -------------------------------------------------------------------------------- /seata/rm/datasource/executor/LockWaitTimeoutException.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class LockWaitTimeoutException(RuntimeError): 21 | pass 22 | -------------------------------------------------------------------------------- /seata/rm/datasource/executor/PlainExecutor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | 21 | class PlainExecutor(object): 22 | 23 | def __int__(self, cursor_proxy, cursor_callback, sql_recognizer): 24 | self.cursor_proxy = cursor_proxy 25 | self.cursor_callback = cursor_callback 26 | self.sql_recognizer = sql_recognizer 27 | 28 | def execute(self, args): 29 | self.cursor_callback.execute(self.cursor_proxy.target_cursor, self.cursor_proxy.target_sql, args) 30 | -------------------------------------------------------------------------------- /seata/rm/datasource/executor/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/datasource/executor/mysql/MySQLDeleteExecutor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.rm.datasource.executor.Executor import DeleteExecutor 20 | 21 | 22 | class MySQLDeleteExecutor(DeleteExecutor): 23 | 24 | def __int__(self, cursor_proxy, cursor_callback, sql_recognizer): 25 | self.cursor_proxy = cursor_proxy 26 | self.cursor_callback = cursor_callback 27 | self.sql_recognizer = sql_recognizer 28 | -------------------------------------------------------------------------------- /seata/rm/datasource/executor/mysql/MySQLSelectForUpdateExecutor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.rm.datasource.executor.Executor import SelectForUpdateExecutor 20 | 21 | 22 | class MySQLSelectForUpdateExecutor(SelectForUpdateExecutor): 23 | 24 | def __int__(self, cursor_proxy, cursor_callback, sql_recognizer): 25 | self.cursor_proxy = cursor_proxy 26 | self.cursor_callback = cursor_callback 27 | self.sql_recognizer = sql_recognizer 28 | -------------------------------------------------------------------------------- /seata/rm/datasource/executor/mysql/MySQLUpdateExecutor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.rm.datasource.executor.Executor import UpdateExecutor 20 | 21 | 22 | class MySQLUpdateExecutor(UpdateExecutor): 23 | 24 | def __int__(self, cursor_proxy, cursor_callback, sql_recognizer): 25 | self.cursor_proxy = cursor_proxy 26 | self.cursor_callback = cursor_callback 27 | self.sql_recognizer = sql_recognizer 28 | -------------------------------------------------------------------------------- /seata/rm/datasource/executor/mysql/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/datasource/sql/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/datasource/sql/struct/ColumnMeta.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class ColumnMeta(object): 21 | 22 | def __init__(self): 23 | self.table_cat = None 24 | self.table_schema_name = None 25 | self.table_name = None 26 | self.column_name = None 27 | self.data_type = None 28 | self.data_type_name = None 29 | self.column_size = None 30 | self.decimal_digits = None 31 | self.num_prec_radix = None 32 | self.null_able = None 33 | self.remarks = None 34 | self.column_def = None 35 | self.sql_data_type = None 36 | self.sql_datetime_sub = None 37 | self.char_octet_length = None 38 | self.ordinal_position = None 39 | self.is_nullable = None 40 | self.is_autoincrement = None 41 | 42 | def is_auto_increment(self): 43 | return self.is_autoincrement == "YES" 44 | 45 | def __eq__(self, other): 46 | return self.__dict__ == other.__dict__ 47 | -------------------------------------------------------------------------------- /seata/rm/datasource/sql/struct/IndexMeta.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class IndexMeta(object): 21 | 22 | def __init__(self): 23 | # ColumnMeta list 24 | self.values = [] 25 | self.non_unique = False 26 | self.index_qualifier = None 27 | self.index_name = None 28 | self.type = 0 29 | # IndexType 30 | self.index_type = None 31 | self.asc_or_desc = None 32 | self.cardinality = 0 33 | self.ordinal_position = 0 34 | 35 | def __eq__(self, other): 36 | return self.__dict__ == other.__dict__ 37 | -------------------------------------------------------------------------------- /seata/rm/datasource/sql/struct/IndexType.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from enum import Enum 20 | 21 | 22 | class IndexType(Enum): 23 | # Primary index type. 24 | PRIMARY = 0 25 | # Normal index type. 26 | NORMAL = 1 27 | # Unique index type. 28 | UNIQUE = 2 29 | # Full text index type. 30 | FULL_TEXT = 3 31 | -------------------------------------------------------------------------------- /seata/rm/datasource/sql/struct/KeyType.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from enum import Enum 20 | 21 | 22 | class KeyType(Enum): 23 | NULL = 1 24 | PRIMARY_KEY = 2 25 | -------------------------------------------------------------------------------- /seata/rm/datasource/sql/struct/Row.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.rm.datasource.sql.struct.KeyType import KeyType 20 | 21 | 22 | class Row(object): 23 | 24 | def __init__(self): 25 | # Field 26 | self.fields = [] 27 | 28 | def __eq__(self, other): 29 | return self.__dict__ == other.__dict__ 30 | 31 | def add(self, field): 32 | self.fields.append(field) 33 | 34 | def primary_keys(self): 35 | keys = [] 36 | for i in range(len(self.fields)): 37 | f = self.fields[i] 38 | if f.key_type == KeyType.PRIMARY_KEY: 39 | keys.append(f) 40 | return keys 41 | 42 | def non_primary_keys(self): 43 | keys = [] 44 | for i in range(len(self.fields)): 45 | f = self.fields[i] 46 | if f.key_type != KeyType.PRIMARY_KEY: 47 | keys.append(f) 48 | return keys 49 | -------------------------------------------------------------------------------- /seata/rm/datasource/sql/struct/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/SQLUndoLog.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class SQLUndoLog(object): 21 | def __int__(self): 22 | # SQLType 23 | self.sql_type = None 24 | self.table_name = None 25 | # TableRecords 26 | self.before_image = None 27 | self.after_image = None 28 | 29 | def set_table_meta(self, table_meta): 30 | if self.before_image is not None: 31 | self.before_image.set_table_meta(table_meta) 32 | if self.after_image is not None: 33 | self.after_image.set_table_meta(table_meta) 34 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/State.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from enum import Enum 20 | 21 | 22 | class State(Enum): 23 | Normal = 0 24 | GlobalFinished = 1 25 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/UndoExecutorFactory.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.exception.ShouldNeverHappenException import ShouldNeverHappenException 20 | 21 | from seata.sqlparser.SQLType import SQLType 22 | 23 | 24 | class UndoExecutorFactory: 25 | @classmethod 26 | def get_undo_executor(cls, db_type, sql_undo_log): 27 | from seata.rm.datasource.undo.UndoExecutorHolderFactory import UndoExecutorHolderFactory 28 | holder = UndoExecutorHolderFactory.get_undo_executor_holder(db_type.lower()) 29 | result = None 30 | sql_type = sql_undo_log.sql_type 31 | if sql_type == SQLType.INSERT: 32 | result = holder.get_insert_executor(sql_undo_log) 33 | elif sql_type == SQLType.UPDATE: 34 | result = holder.get_update_executor(sql_undo_log) 35 | elif sql_type == SQLType.DELETE: 36 | result = holder.get_delete_executor(sql_undo_log) 37 | else: 38 | raise ShouldNeverHappenException() 39 | return result 40 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/UndoExecutorHolder.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | 21 | class UndoExecutorHolder: 22 | def get_insert_executor(self, sql_undo_log): 23 | raise NotImplemented("need subclass implemented") 24 | 25 | def get_update_executor(self, sql_undo_log): 26 | raise NotImplemented("need subclass implemented") 27 | 28 | def get_delete_executor(self, sql_undo_log): 29 | raise NotImplemented("need subclass implemented") 30 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/UndoExecutorHolderFactory.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.sqlparser.util.JdbcConstants import JdbcConstants 20 | 21 | 22 | class UndoExecutorHolderFactory: 23 | _HOLDER_MAP = {} 24 | 25 | @classmethod 26 | def get_undo_executor_holder(cls, db_type): 27 | if cls._HOLDER_MAP.get(db_type, None) is not None: 28 | return cls._HOLDER_MAP[db_type] 29 | if db_type == JdbcConstants.MYSQL: 30 | from seata.rm.datasource.undo.mysql.MySQLUndoExecutorHolder import MySQLUndoExecutorHolder 31 | cls._HOLDER_MAP[db_type] = MySQLUndoExecutorHolder() 32 | return cls._HOLDER_MAP[db_type] 33 | raise NotImplemented("db type : " + db_type) 34 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/UndoLogManagerFactory.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.exception.NotSupportYetException import NotSupportYetException 20 | from seata.sqlparser.util.JdbcConstants import JdbcConstants 21 | 22 | 23 | class UndoLogManagerFactory(object): 24 | 25 | @staticmethod 26 | def get_undo_log_manager(db_type): 27 | if db_type == JdbcConstants.MYSQL: 28 | from seata.rm.datasource.undo.mysql.MySQLUndoLogManager import MySQLUndoLogManager 29 | return MySQLUndoLogManager() 30 | raise NotSupportYetException("not support db type : [{}]".format(db_type)) 31 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/UndoLogParser.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class UndoLogParser: 21 | def get_name(self): 22 | raise NotImplemented("need subclass implemented") 23 | 24 | def get_default_content(self): 25 | raise NotImplemented("need subclass implemented") 26 | 27 | def encode(self, branch_undo_log): 28 | raise NotImplemented("need subclass implemented") 29 | 30 | def decode(self, bytes_): 31 | raise NotImplemented("need subclass implemented") 32 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/UndoLogParserFactory.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class UndoLogParserFactory: 21 | DEFAULT_SERIALIZER = "protobuf" 22 | 23 | @classmethod 24 | def get_instance(cls, serializer=None): 25 | if serializer is None: 26 | serializer = cls.DEFAULT_SERIALIZER 27 | if serializer == cls.DEFAULT_SERIALIZER: 28 | from seata.rm.datasource.undo.parser.ProtobufUndoLogParser import ProtobufUndoLogParser 29 | return ProtobufUndoLogParser() 30 | raise NotImplemented() 31 | 32 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/mysql/MySQLUndoDeleteExecutor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.exception.ShouldNeverHappenException import ShouldNeverHappenException 20 | from seata.rm.datasource.ColumnUtils import ColumnUtils 21 | from seata.rm.datasource.undo.UndoExecutor import UndoExecutor 22 | from seata.sqlparser.util.JdbcConstants import JdbcConstants 23 | 24 | 25 | class MySQLUndoDeleteExecutor(UndoExecutor): 26 | INSERT_SQL_TEMPLATE = "INSERT INTO {} ({}) VALUES ({})" 27 | 28 | def __init__(self, sql_undo_log): 29 | super(MySQLUndoDeleteExecutor, self).__init__(sql_undo_log) 30 | 31 | def build_undo_sql(self): 32 | before_image = self.sql_undo_log.before_image 33 | rows = before_image.rows 34 | if rows is None or len(rows) == 0: 35 | raise ShouldNeverHappenException('Invalid undo log') 36 | row = rows[0] 37 | fields = [] 38 | fields.extend(row.non_primary_keys()) 39 | fields.extend(self.get_ordered_pk_list(before_image, row, JdbcConstants.MYSQL)) 40 | 41 | columns = ', '.join([ColumnUtils.add_by_col_dbtype(f.name, JdbcConstants.MYSQL) for f in fields]) 42 | values = ', '.join(["%s" for f in fields]) 43 | return self.INSERT_SQL_TEMPLATE.format(self.sql_undo_log.table_name, columns, values) 44 | 45 | def get_undo_rows(self): 46 | return self.sql_undo_log.before_image 47 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/mysql/MySQLUndoExecutorHolder.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.rm.datasource.undo.UndoExecutorHolder import UndoExecutorHolder 20 | from seata.rm.datasource.undo.mysql.MySQLUndoDeleteExecutor import MySQLUndoDeleteExecutor 21 | from seata.rm.datasource.undo.mysql.MySQLUndoInsertExecutor import MySQLUndoInsertExecutor 22 | from seata.rm.datasource.undo.mysql.MySQLUndoUpdateExecutor import MySQLUndoUpdateExecutor 23 | 24 | 25 | class MySQLUndoExecutorHolder(UndoExecutorHolder): 26 | def get_insert_executor(self, sql_undo_log): 27 | return MySQLUndoInsertExecutor(sql_undo_log) 28 | 29 | def get_update_executor(self, sql_undo_log): 30 | return MySQLUndoUpdateExecutor(sql_undo_log) 31 | 32 | def get_delete_executor(self, sql_undo_log): 33 | return MySQLUndoDeleteExecutor(sql_undo_log) -------------------------------------------------------------------------------- /seata/rm/datasource/undo/mysql/MySQLUndoInsertExecutor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.exception.ShouldNeverHappenException import ShouldNeverHappenException 20 | from seata.rm.datasource.undo.UndoExecutor import UndoExecutor 21 | from seata.sqlparser.util.JdbcConstants import JdbcConstants 22 | from seata.sqlparser.util.SQLUtil import SQLUtil 23 | 24 | 25 | class MySQLUndoInsertExecutor(UndoExecutor): 26 | DELETE_SQL_TEMPLATE = "DELETE FROM {} WHERE {}" 27 | 28 | def __init__(self, sql_undo_log): 29 | super(MySQLUndoInsertExecutor, self).__init__(sql_undo_log) 30 | 31 | def get_undo_rows(self): 32 | return self.sql_undo_log.after_image 33 | 34 | def build_undo_sql(self): 35 | after_image = self.sql_undo_log.after_image 36 | rows = after_image.rows 37 | if rows is None or len(rows) <= 0: 38 | raise ShouldNeverHappenException('invalid undo log') 39 | return self.generate_delete_sql(rows, after_image) 40 | 41 | def undo_prepare(self, cursor, undo_values, pk_value_list): 42 | params = [x.value for x in pk_value_list] 43 | return params 44 | 45 | def generate_delete_sql(self, rows, after_image): 46 | pk_name_list = [x.name for x in self.get_ordered_pk_list(after_image, rows[0], JdbcConstants.MYSQL)] 47 | where_sql = SQLUtil.build_where_condition_by_pks_single(pk_name_list, JdbcConstants.MYSQL) 48 | return self.DELETE_SQL_TEMPLATE.format(self.sql_undo_log.table_name, where_sql) 49 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/mysql/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ -------------------------------------------------------------------------------- /seata/rm/datasource/undo/parser/ProtobufUndoLogParser.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from google.protobuf import json_format 20 | 21 | from seata.core.util.ClassUtil import ClassUtil 22 | from seata.rm.datasource.undo.BranchUndoLog import BranchUndoLog 23 | from seata.rm.datasource.undo.UndoLogParser import UndoLogParser 24 | from seata.rm.datasource.undo.parser.proto import branch_undolog_pb2 25 | 26 | 27 | class ProtobufUndoLogParser(UndoLogParser): 28 | def get_name(self): 29 | return "protobuf" 30 | 31 | def get_default_content(self): 32 | return self.encode(BranchUndoLog()) 33 | 34 | def encode(self, branch_undo_log): 35 | dic = ClassUtil.obj_to_dic(branch_undo_log, ignore_names=['table_meta']) 36 | bul_pb = json_format.ParseDict(dic, branch_undolog_pb2.BranchUndoLog(), ignore_unknown_fields=True) 37 | bs = bul_pb.SerializeToString() 38 | return bs 39 | 40 | def decode(self, bytes_): 41 | bul_pb = branch_undolog_pb2.BranchUndoLog() 42 | bul_pb.ParseFromString(bytes_) 43 | dic = json_format.MessageToDict(bul_pb, including_default_value_fields=True, preserving_proto_field_name=True) 44 | bul = BranchUndoLog(dic) 45 | return bul 46 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/parser/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/rm/datasource/undo/parser/branch_undolog.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // https://github.com/protocolbuffers/protobuf/releases 4 | // https://developers.google.com/protocol-buffers/docs/overview 5 | // cd seata/rm/datasource/undo/parser 6 | // ..\..\..\..\..\tool\protoc\windows\bin\protoc --python_out=./proto branch_undolog.proto 7 | // ../../../../../tool/protoc/osx/bin/protoc --python_out=./proto branch_undolog.proto 8 | 9 | package seata.rm.datasource.undo.parser.proto; 10 | 11 | import "google/protobuf/any.proto"; 12 | 13 | message BranchUndoLog { 14 | optional string xid = 1; 15 | optional int64 branch_id = 2; 16 | repeated SQLUndoLog sql_undo_logs = 3; 17 | } 18 | 19 | message SQLUndoLog { 20 | // SQLType enum value 21 | int32 sql_type = 1; 22 | string table_name = 2; 23 | TableRecords before_image = 3; 24 | TableRecords after_image = 4; 25 | } 26 | 27 | message TableRecords { 28 | TableMeta table_meta = 1; 29 | string table_name = 2; 30 | repeated Row rows = 3; 31 | } 32 | 33 | message TableMeta { 34 | string table_name = 1; 35 | map all_columns = 2; 36 | map all_indexs = 3; 37 | } 38 | 39 | message ColumnMeta { 40 | string table_cat = 1; 41 | string table_schema_name = 2; 42 | string table_name = 3; 43 | string column_name = 4; 44 | int32 data_type = 5; 45 | string data_type_name = 6; 46 | int32 column_size = 7; 47 | int32 decimal_digits = 8; 48 | int32 num_prec_radix = 9; 49 | int32 null_able = 10; 50 | string remarks = 11; 51 | string column_def = 12; 52 | int32 sql_data_type = 13; 53 | int32 sql_datetime_sub = 14; 54 | google.protobuf.Any char_octet_length = 15; 55 | int32 ordinal_position = 16; 56 | string is_nullable = 17; 57 | string is_autoincrement = 18; 58 | } 59 | 60 | message IndexMeta { 61 | repeated ColumnMeta values = 1; 62 | bool non_unique = 2; 63 | string index_qualifier = 3; 64 | string index_name = 4; 65 | int32 type = 5; 66 | // IndexType enum value 67 | int32 index_type = 6; 68 | string asc_or_desc = 7; 69 | int32 cardinality = 8; 70 | int32 ordinal_position = 9; 71 | } 72 | 73 | message Row { 74 | repeated Field fields = 1; 75 | } 76 | 77 | message Field { 78 | string name = 1; 79 | // KeyType enum value 80 | int32 key_type = 2; 81 | int32 type = 3; 82 | string value = 4; 83 | } -------------------------------------------------------------------------------- /seata/rm/datasource/undo/parser/proto/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/script/client.yml: -------------------------------------------------------------------------------- 1 | application-id: applicationName 2 | tx-service-group: my_test_tx_group 3 | config: 4 | type: file # file, nacos 5 | nacos: 6 | namespace: "" 7 | server-addr: 127.0.0.1:8848 8 | group: SEATA_GROUP 9 | username: "" 10 | password: "" 11 | data-id: seata.properties 12 | registry: 13 | type: file # file, nacos 14 | nacos: 15 | application: seata-server 16 | server-addr: 127.0.0.1:8848 17 | group: "SEATA_GROUP" 18 | namespace: "" 19 | username: "" 20 | password: "" 21 | # file mode 22 | client: 23 | rm: 24 | report-retry-count: 5 25 | table-meta-check-enable: false 26 | report-success-enable: false 27 | lock: 28 | retry-interval: 0.01 # seconds 29 | retry-times: 30 30 | retry-policy-branch-rollback-on-conflict: true 31 | tm: 32 | commit-retry-count: 5 33 | rollback-retry-count: 5 34 | default-global-transaction-timeout: 60000 35 | undo: 36 | data-validation: true 37 | log-table: undo_log 38 | only-care-update-columns: true 39 | service: 40 | vgroupMapping: 41 | my_test_tx_group: default 42 | grouplist: 43 | default: "127.0.0.1:8091" -------------------------------------------------------------------------------- /seata/sqlparser/SQLDMLRecognizer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.sqlparser.SQLRecognizer import SQLRecognizer 20 | 21 | 22 | class SQLInsertRecognizer(SQLRecognizer): 23 | 24 | def insert_columns_is_empty(self): 25 | raise NotImplemented("need subclass implemented") 26 | 27 | def get_insert_columns(self): 28 | raise NotImplemented("need subclass implemented") 29 | 30 | def get_insert_rows(self, pk_index: list): 31 | raise NotImplemented("need subclass implemented") 32 | 33 | 34 | class SQLUpdateRecognizer(SQLRecognizer): 35 | 36 | def get_update_columns(self): 37 | raise NotImplemented("need subclass implemented") 38 | 39 | def get_update_values(self): 40 | raise NotImplemented("need subclass implemented") 41 | -------------------------------------------------------------------------------- /seata/sqlparser/SQLParsingException.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class SQLParsingException(RuntimeError): 21 | pass 22 | -------------------------------------------------------------------------------- /seata/sqlparser/SQLRecognizer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | 21 | class SQLRecognizer(object): 22 | 23 | def get_sql_type(self): 24 | raise NotImplemented("need subclass implemented") 25 | 26 | def get_table_alias(self): 27 | raise NotImplemented("need subclass implemented") 28 | 29 | def get_table_name(self): 30 | raise NotImplemented("need subclass implemented") 31 | 32 | def get_original_sql(self): 33 | raise NotImplemented("need subclass implemented") 34 | 35 | def get_where_condition(self, parameters_map=None, param_list=None): 36 | raise NotImplemented("need subclass implemented") 37 | -------------------------------------------------------------------------------- /seata/sqlparser/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/MySQLDeleteSQLRecognizer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | from am.mysql_base import DeleteStatement 21 | 22 | from seata.sqlparser.mysql.MySQLWhereSQLRecognizer import MySQLWhereSQLRecognizer 23 | from seata.sqlparser.mysql.antlr4.visit.MySQLDeleteStatement import MySQLDeleteStatement 24 | 25 | 26 | class MySQLDeleteSQLRecognizer(MySQLWhereSQLRecognizer): 27 | 28 | def __int__(self, original_sql=None, sql_type=None, stmt=None): 29 | self.original_sql = original_sql 30 | self.sql_type = sql_type 31 | self.stmt = stmt 32 | self.statement = None 33 | 34 | def init(self): 35 | if not isinstance(self.stmt, DeleteStatement): 36 | raise TypeError('stmt type error.' + type(self.stmt).__name__) 37 | self.statement = MySQLDeleteStatement(self.stmt) 38 | 39 | def get_sql_type(self): 40 | return self.sql_type 41 | 42 | def get_table_name(self): 43 | return self.statement.table_name 44 | 45 | def get_table_alias(self): 46 | return self.statement.table_alias 47 | 48 | def get_original_sql(self): 49 | return self.original_sql 50 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/MySQLDmlRecognizer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.sqlparser.SQLDMLRecognizer import SQLInsertRecognizer, SQLUpdateRecognizer 20 | from seata.sqlparser.mysql.MySQLWhereSQLRecognizer import MySQLWhereSQLRecognizer 21 | 22 | 23 | class MySQLInsertRecognizer(SQLInsertRecognizer, MySQLWhereSQLRecognizer): 24 | pass 25 | 26 | 27 | class MySQLUpdateRecognizer(SQLUpdateRecognizer, MySQLWhereSQLRecognizer): 28 | pass 29 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/MySQLSelectSQLRecognizer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from am.mysql_base import SelectStatement 20 | 21 | from seata.sqlparser.mysql.MySQLWhereSQLRecognizer import MySQLWhereSQLRecognizer 22 | from seata.sqlparser.mysql.antlr4.visit.MySQLSelectForUpdateStatement import MySQLSelectForUpdateStatement 23 | 24 | 25 | class MySQLSelectSQLRecognizer(MySQLWhereSQLRecognizer): 26 | 27 | def __int__(self, original_sql=None, sql_type=None, stmt=None): 28 | self.original_sql = original_sql 29 | self.sql_type = sql_type 30 | self.stmt = stmt 31 | self.statement = None 32 | 33 | def init(self): 34 | if not isinstance(self.stmt, SelectStatement): 35 | raise TypeError('stmt type error.' + type(self.stmt).__name__) 36 | self.statement = MySQLSelectForUpdateStatement(self.stmt) 37 | 38 | def get_sql_type(self): 39 | return self.sql_type 40 | 41 | def get_table_name(self): 42 | return self.statement.table_name 43 | 44 | def get_table_alias(self): 45 | return self.statement.table_alias 46 | 47 | def get_original_sql(self): 48 | return self.original_sql 49 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/MySQLWhereSQLRecognizer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from am.mysql_base import MysqlOutputVisitor 20 | 21 | from seata.sqlparser.SQLRecognizer import SQLRecognizer 22 | from seata.sqlparser.mysql.antlr4.util.ParamMysqlOutputVisitor import ParamMysqlOutputVisitor 23 | 24 | 25 | class MySQLWhereSQLRecognizer(SQLRecognizer): 26 | 27 | def get_where_condition(self, parameters_map=None, param_list=None): 28 | where = self.statement.where 29 | if where is None: 30 | return "" 31 | if parameters_map is not None: 32 | output = list() 33 | ParamMysqlOutputVisitor(parameters_map, param_list).visitWhere(where, output) 34 | return ''.join(output) 35 | else: 36 | output = list() 37 | MysqlOutputVisitor().visitWhere(where, output) 38 | return ''.join(output) 39 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/antlr4/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/antlr4/util/MySQLStatementUtil.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from am.mysql_base import BitString, RealLiteral, DecimalLiteral, BooleanLiteral, \ 20 | ParameterMarker, StringLiteral, HexadecimalLiteral, NullLiteral 21 | from seata.sqlparser.mysql.antlr4.value import MySQLValue 22 | 23 | 24 | class MySQLStatementUtil: 25 | 26 | @classmethod 27 | def parse_constant(cls, val): 28 | if isinstance(val, BitString): 29 | return MySQLValue.OtherValue(val.value) 30 | elif isinstance(val, RealLiteral): 31 | return MySQLValue.IntValue(val.value) 32 | elif isinstance(val, DecimalLiteral): 33 | return MySQLValue.DoubleValue(val.value) 34 | elif isinstance(val, BooleanLiteral): 35 | return MySQLValue.BoolValue(val.value) 36 | elif isinstance(val, ParameterMarker): 37 | return MySQLValue.ParameterMarkerValue(val.name, val.value) 38 | elif isinstance(val, StringLiteral): 39 | return MySQLValue.StringValue(val.value) 40 | elif isinstance(val, HexadecimalLiteral): 41 | return MySQLValue.OtherValue(val.value) 42 | elif isinstance(val, NullLiteral): 43 | return MySQLValue.NullValue() 44 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/antlr4/util/ParamMysqlOutputVisitor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from am.mysql_base import MysqlOutputVisitor 20 | 21 | 22 | class ParamMysqlOutputVisitor(MysqlOutputVisitor): 23 | 24 | def __init__(self, parameters_map, param_list): 25 | self.parameters_map = parameters_map 26 | self.param_list = param_list 27 | 28 | def visitParameterMarker(self, parameter_marker, output): 29 | param_values = self.parameters_map[parameter_marker.index] 30 | if self.param_list is None or len(self.param_list) == 0: 31 | for i in range(len(param_values)): 32 | self.param_list.append([]) 33 | for i in range(len(param_values)): 34 | val = param_values[i] 35 | self.param_list[i].append(val) 36 | output.append("%s") 37 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/antlr4/util/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/antlr4/value/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/antlr4/visit/MySQLDeleteStatement.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from am.mysql_base import DeleteStatement 20 | 21 | 22 | class MySQLDeleteStatement: 23 | 24 | def __init__(self, ctx: DeleteStatement): 25 | self.table_name = None 26 | self.table_alias = None 27 | self.where = None 28 | self.order_by = None 29 | self.limit = None 30 | self.__ctx = ctx 31 | self.__parse() 32 | 33 | def __parse(self): 34 | self.__parse_table_name() 35 | self.__parse_table_alias() 36 | self.__parse_where() 37 | self.__parse_order_by() 38 | self.__parse_limit() 39 | 40 | def __parse_table_name(self): 41 | self.table_name = self.__ctx.tableSource.tableName 42 | 43 | def __parse_table_alias(self): 44 | self.table_alias = self.__ctx.tableSource.tableAlias 45 | 46 | def __parse_where(self): 47 | self.where = self.__ctx.where 48 | 49 | def __parse_order_by(self): 50 | self.order_by = self.__ctx.orderBy 51 | 52 | def __parse_limit(self): 53 | self.limit = self.__ctx.limit 54 | -------------------------------------------------------------------------------- /seata/sqlparser/mysql/antlr4/visit/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | -------------------------------------------------------------------------------- /seata/sqlparser/util/CollectionUtil.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class CollectionUtil: 21 | 22 | @classmethod 23 | def encode_map(cls, map_): 24 | if map_ is None: 25 | return None 26 | if len(map_) == 0: 27 | return "" 28 | result = "" 29 | for k, v in map_.items(): 30 | result += (k + "=" + v + "&") 31 | return result 32 | 33 | @classmethod 34 | def decode_map(cls, string): 35 | if string is None: 36 | return None 37 | map_ = {} 38 | cs = string.split("&") 39 | for i in range(len(cs)): 40 | c = cs[i] 41 | if c.strip() != '': 42 | kv = c.split("=") 43 | map_[kv[0]] = kv[1] 44 | return map_ 45 | -------------------------------------------------------------------------------- /seata/sqlparser/util/JdbcConstants.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class JdbcConstants(object): 21 | 22 | MYSQL = "mysql" 23 | MARIADB = "mariadb" 24 | -------------------------------------------------------------------------------- /seata/sqlparser/util/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ -------------------------------------------------------------------------------- /seata/test/ConfigurationTest.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import os 20 | 21 | from seata.config.Config import ConfigFactory 22 | from seata.config.Configuration import Configuration 23 | 24 | BASEDIR = os.path.dirname(os.path.dirname(__file__)) 25 | 26 | if __name__ == '__main__': 27 | Configuration(BASEDIR + '/script/client.yml') 28 | config = ConfigFactory.get_config() 29 | print(config) 30 | -------------------------------------------------------------------------------- /seata/test/EnumTest.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.model.GlobalStatus import GlobalStatus 20 | 21 | if __name__ == '__main__': 22 | val = GlobalStatus.UnKnown.value 23 | print(val) 24 | e = GlobalStatus(val) 25 | print(e) 26 | -------------------------------------------------------------------------------- /seata/test/RpcTest.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import os 20 | 21 | from seata.boot.GlobalTransactionScanner import GlobalTransactionScanner 22 | from seata.config.Configuration import Configuration 23 | from seata.tm.api.DefaultGlobalTransaction import DefaultGlobalTransaction 24 | from seata.tm.api.GlobalTransactionRole import GlobalTransactionRole 25 | 26 | if __name__ == '__main__': 27 | base_dir = os.path.dirname(os.path.dirname(__file__)) 28 | Configuration(base_dir + '/script/client.yml') 29 | GlobalTransactionScanner() 30 | 31 | gt = DefaultGlobalTransaction(None, None, GlobalTransactionRole.Launcher) 32 | gt.begin(60000, "xxx") 33 | print("xid = [{}]".format(gt.xid)) 34 | -------------------------------------------------------------------------------- /seata/test/SqlTest.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.exception.ShouldNeverHappenException import ShouldNeverHappenException 20 | from seata.rm.datasource.sql.SQLVisitorFactory import SQLVisitorFactory 21 | from seata.sqlparser.util.JdbcConstants import JdbcConstants 22 | 23 | if __name__ == '__main__': 24 | sql = "insert into test values(?, ?)" 25 | sql_recognizer = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL) 26 | print(1) 27 | 28 | sql = "insert ignore into test values(?, ?)" 29 | sql_recognizer = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL) 30 | print(2) 31 | 32 | sql = "delete from test where a = ?" 33 | sql_recognizer = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL) 34 | print(3) 35 | 36 | sql = "update test set a = ? where b = ?" 37 | sql_recognizer = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL) 38 | print(4) 39 | 40 | sql = "select * from test" 41 | sql_recognizer = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL) 42 | print(5) 43 | 44 | sql = "select * from test for update" 45 | sql_recognizer = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL) 46 | print(6) 47 | 48 | try: 49 | sql = "show create table test" 50 | sql_recognizer = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL) 51 | except ShouldNeverHappenException: 52 | print(7) 53 | 54 | 55 | -------------------------------------------------------------------------------- /seata/test/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ -------------------------------------------------------------------------------- /seata/tm/TMClient.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import threading 20 | import time 21 | 22 | from seata.core.protocol.RegisterTMRequestResponse import RegisterTMRequest 23 | from seata.core.rpc.v1.TmRemotingClient import TmRemotingClient 24 | 25 | 26 | class TMClient(object): 27 | client = None 28 | lock = threading.RLock() 29 | 30 | @classmethod 31 | def get(cls, application_id=None, transaction_service_group=None): 32 | if cls.client is None: 33 | try: 34 | cls.lock.acquire() 35 | if cls.client is None: 36 | cls.client = TMClient(application_id, transaction_service_group) 37 | finally: 38 | cls.lock.release() 39 | return cls.client 40 | 41 | def __init__(self, application_id=None, transaction_service_group=None): 42 | self.application_id = application_id 43 | self.transaction_service_group = transaction_service_group 44 | self.remote_client = None 45 | 46 | def init_client(self): 47 | # 程序启动 48 | from seata.tm.TMHandler import TMHandler 49 | message_handler = TMHandler() 50 | self.remote_client = TmRemotingClient.get_client(self.application_id, self.transaction_service_group, 51 | message_handler) 52 | -------------------------------------------------------------------------------- /seata/tm/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | -------------------------------------------------------------------------------- /seata/tm/api/GlobalTransaction.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | 20 | class GlobalTransaction: 21 | def begin(self, timeout=None, name="default"): 22 | raise NotImplemented("need subclass implemented") 23 | 24 | def commit(self): 25 | raise NotImplemented("need subclass implemented") 26 | 27 | def rollback(self): 28 | raise NotImplemented("need subclass implemented") 29 | 30 | def suspend(self): 31 | raise NotImplemented("need subclass implemented") 32 | 33 | def resume(self, suspend_resource_holder): 34 | raise NotImplemented("need subclass implemented") 35 | 36 | def get_status(self): 37 | raise NotImplemented("need subclass implemented") 38 | 39 | def get_xid(self): 40 | raise NotImplemented("need subclass implemented") 41 | 42 | def global_report(self, global_status): 43 | raise NotImplemented("need subclass implemented") 44 | 45 | def get_local_status(self): 46 | raise NotImplemented("need subclass implemented") 47 | -------------------------------------------------------------------------------- /seata/tm/api/GlobalTransactionContext.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | from seata.core.context.RootContext import RootContext 20 | from seata.core.model.GlobalStatus import GlobalStatus 21 | from seata.tm.api.DefaultGlobalTransaction import DefaultGlobalTransaction 22 | from seata.tm.api.GlobalTransactionRole import GlobalTransactionRole 23 | 24 | 25 | class GlobalTransactionContext: 26 | 27 | @classmethod 28 | def create_new(cls): 29 | return DefaultGlobalTransaction() 30 | 31 | @classmethod 32 | def get_current(cls): 33 | xid = RootContext.get_xid() 34 | if xid is None: 35 | return None 36 | return DefaultGlobalTransaction(xid, GlobalStatus.Begin, GlobalTransactionRole.Participant) 37 | 38 | @classmethod 39 | def get_current_or_create(cls): 40 | tx = cls.get_current() 41 | if tx is None: 42 | return cls.create_new() 43 | return tx 44 | 45 | @classmethod 46 | def reload(cls, xid): 47 | tx = DefaultGlobalTransaction(xid, GlobalStatus.UnKnown, GlobalTransactionRole.Launcher) 48 | tx.begin = lambda timeout, name: (_ for _ in ()).throw(Exception('never begin on a reload global transaction.')) 49 | return tx 50 | -------------------------------------------------------------------------------- /seata/tm/api/GlobalTransactionRole.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import enum 20 | 21 | 22 | class GlobalTransactionRole(enum.Enum): 23 | Launcher = 0 24 | Participant = 1 -------------------------------------------------------------------------------- /seata/tm/api/TransactionalExecutor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import enum 20 | 21 | 22 | class TransactionalExecutor: 23 | class ExecutionException(Exception): 24 | 25 | def __init__(self, tx, cause, code, origin_exception): 26 | self.tx = tx 27 | self.cause = cause 28 | self.code = code 29 | self.origin_exception = origin_exception 30 | 31 | def __str__(self): 32 | return 'globalStatus={}, cause={}, code={}, origin_exception={}'.format( 33 | self.tx.status, self.cause, self.code, self.origin_exception) 34 | 35 | def __repr__(self): 36 | return self.__str__() 37 | 38 | class Code(enum.Enum): 39 | BeginFailure = 0 40 | CommitFailure = 1 41 | RollbackFailure = 2 42 | RollbackDone = 3 43 | ReportFailure = 4 44 | RollbackRetrying = 5 45 | -------------------------------------------------------------------------------- /seata/tm/api/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Licensed to the Apache Software Foundation (ASF) under one or more 5 | contributor license agreements. See the NOTICE file distributed with 6 | this work for additional information regarding copyright ownership. 7 | The ASF licenses this file to You under the Apache License, Version 2.0 8 | (the "License"); you may not use this file except in compliance with 9 | the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | """ 18 | 19 | import os 20 | 21 | import setuptools 22 | 23 | VERSION = "0.1" 24 | 25 | base_dir = os.path.dirname(os.path.abspath(__file__)) 26 | 27 | with open(os.path.join(base_dir, "README.md"), "r") as f: 28 | long_description = f.read() 29 | 30 | with open(os.path.join(base_dir, "requirements.txt"), "r") as f: 31 | install_requires = f.read().splitlines() 32 | 33 | setuptools.setup( 34 | name="seata-python", 35 | version=VERSION, 36 | author="jsbxyyx", 37 | author_email="jsbxyyx@163.com", 38 | description="seata-python", 39 | long_description=long_description, 40 | long_description_content_type="text/markdown", 41 | license="Apache License 2.0", 42 | install_requires=install_requires, 43 | url="https://github.com/opentrx/seata-python", 44 | packages=setuptools.find_packages(), 45 | include_package_data=True, 46 | classifiers=[ 47 | "Programming Language :: Python :: 3.7", 48 | "Operating System :: OS Independent", 49 | ], 50 | python_requires='>=3.7', 51 | ) 52 | -------------------------------------------------------------------------------- /tool/protoc/osx/bin/protoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seata/fescar-python/e34b3bb8e1f4c20db0cb1c9a582c73e6eca65897/tool/protoc/osx/bin/protoc -------------------------------------------------------------------------------- /tool/protoc/windows/bin/protoc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seata/fescar-python/e34b3bb8e1f4c20db0cb1c9a582c73e6eca65897/tool/protoc/windows/bin/protoc.exe -------------------------------------------------------------------------------- /tool/protoc/windows/readme.txt: -------------------------------------------------------------------------------- 1 | Protocol Buffers - Google's data interchange format 2 | Copyright 2008 Google Inc. 3 | https://developers.google.com/protocol-buffers/ 4 | 5 | This package contains a precompiled binary version of the protocol buffer 6 | compiler (protoc). This binary is intended for users who want to use Protocol 7 | Buffers in languages other than C++ but do not want to compile protoc 8 | themselves. To install, simply place this binary somewhere in your PATH. 9 | 10 | If you intend to use the included well known types then don't forget to 11 | copy the contents of the 'include' directory somewhere as well, for example 12 | into '/usr/local/include/'. 13 | 14 | Please refer to our official github site for more installation instructions: 15 | https://github.com/protocolbuffers/protobuf 16 | --------------------------------------------------------------------------------