Coder Social home page Coder Social logo

incubator-seata-go's Introduction

Seata-go: Simple Extensible Autonomous Transaction Architecture(Go version)

CI license

简体中文 ZH

What is seata-go?

Apache Seata(incubating) is a very mature distributed transaction framework, and is the de facto standard platform for distributed transaction technology in the Java field. Seata-go is the implementation version of go language in Seata multilingual ecosystem, which realizes the interoperability between Java and Go, so that Go developers can also use seata-go to realize distributed transactions. Please visit the official website of Seata to view the quick start and documentation.

The principle of seata-go is consistent with that of Seata-java, which is composed of TM, RM and TC. The functions of TC reuse Java, and the functions of TM and RM will be aligned with Seata-java later. The overall process is as follows:

TODO list

  • TCC
  • XA
  • AT
    • Insert SQL
    • Delete SQL
    • Insert on update SQL
    • Multi update SQL
    • Multi delete SQL
    • Select for update SQL
    • Update SQL
  • SAGA
  • TM
  • RPC communication
  • Transaction anti suspension
    • Manually way
    • Proxy datasource way
  • Null compensation
  • Configuration center
    • Configuration file
  • Registration Center
  • Metric monitoring
  • Compressor algorithm
  • Examples

How to run?

if you want to know how to use and integrate seata-go, please refer to apache/seata-go-samples

How to join us?

Seata-go is currently in the construction stage. Welcome colleagues in the industry to join the group and work with us to promote the construction of seata-go! If you want to contribute code to seata-go, you can refer to the code contribution Specification document to understand the specifications of the community, or you can join our community DingTalk group: 33069364 and communicate together!

Licence

Seata-go uses Apache license version 2.0. Please refer to the license file for more information.

incubator-seata-go's People

Contributors

106umao avatar 576470954 avatar alexstocks avatar baerwang avatar betterwinsone avatar cgdeeplearn avatar charlie17li avatar chuntaojun avatar code-fight avatar dependabot[bot] avatar funky-eyes avatar georgehao avatar isupercoder avatar iunyasha avatar jasondeng1997 avatar jsbxyyx avatar liiibpm avatar luky116 avatar lxfeng1997 avatar miaoxueyu avatar mooleetzi avatar raspberry-hu avatar slievrly avatar smiletrl avatar testwill avatar wang1309 avatar wt-better avatar xyombo avatar yizhibian avatar zhangymperson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

incubator-seata-go's Issues

Count active RM instead of counting TM

Is your feature request related to a problem? Please describe.
Currently, the TC server side is counting active TM to avoid querying clients that are off-line.
If RM and TM are using the same addressing, then it's ok because if TM is alive, then RM is also alive.
But when the addressing of RM and TM are different, it may cause an issue that TM is alive but RM is dead.
In such scenario, the branch message that sent to client side will get timeout issue.

Describe the solution you'd like
I'd like to count the active RM instead of TM.

Describe alternatives you've considered

Additional context

AT模式事物隔离问题

分布式事物由两个事物组成
1负责创建订单时扣减库存
2负责创建订单时写入订单主表和订单明细表

当1事物 commit 之后(库存减少了) , 2事物出错了需要回滚 , 全局回滚完成 之前, 这时读取的库存数是1事物commit之后的, 这种问题要怎么处理?

Summer 2021 For Seata

Summer 2021 is a program hosted by ISCAS(Institute of Software Chinese Academy of Sciences) and openEuler community. It is very similar with Google Summer of Code.

Seata will join The Summer 2021 as the mentoring organization.

Home page, https://summer.iscas.ac.cn

Seata community will choose some challenging topics, so that more college students can participate in the open source community and learn more about Seata. At the same time, the Seata community will gain more new contributors.

. At the same time, Seata community will obtain more new contributors.

Topic list:

  • Support SAGA mode (#43)
  • Support postgresql and oracle(achieve one) (#44)
  • Support nacos and etcd (#45)

“开源之夏2021”是由ISCAS(**科学院软件研究所)和openEuler社区托管的程序。 与Google Summer of Code非常相似。

Seata 将会作为指导组织参加本次的“开源之夏2021”。

“开源之夏2021”的官方网站为:https://summer.iscas.ac.cn

Seata 将选择一些具有挑战性的主题,让更多的高校学生参与到开源社区和了解Seata的更多信息。 同时,Seata 社区将获得更多新的贡献者。

主题列表如下:

  • 支持 SAGA 模式 (#43)
  • 支持 postgresql 和 oracle (二选一)(#44)
  • 支持 nacos 和 etcd(#45)

cpu占用率100%

编译运行cmd,再启动aggregation_svc下的服务,未发起任何请求的情况下,cpu占用率都飙升到100%

1

定位到问题代码行在这里:transaction_coordinator.go,请问是什么原因?

2

3

[Summer 2021] Support SAGA mode

Background

The SAGA mode is driven by a state machine. In the Saga mode, each participant in the business process submits a local transaction. When a participant fails, it will compensate the previously successful participant. The first-stage forward service and the second-stage compensation service All are implemented by business developer. The Seata Java version already supports SAGA mode.

Target

make seata-golang support saga mode.

Difficulty

High

Mentor

@dk-lockdown

Output Requirements

Support describing state machine with state diagram.
Distributed transactions driven by the state machine to achieve final consistency.

Technical Requirements

Familiar with the Seata-Golang,and, understand the principle of SAGA mode.

背景

SAGA 模式由状态机驱动,在Saga模式中,业务流程中每个参与者都提交本地事务,当出现某一个参与者失败则补偿前面已经成功的参与者,一阶段正向服务和二阶段补偿服务都由业务开发实现。Seata Java 版本已经支持 SAGA 模式。

目标

使 Seata-Golang 支持 SAGA 模式。

难度

导师

@dk-lockdown

产出要求

支持用状态图描述状态机
由状态机驱动分布式事务达到最终一致性

能力要求

熟悉 Seata-Golang 框架,了解 SAGA 模式的原理。

[Summer 2021] Support nacos and etcd

Background

Currently, the configuration of seata-golang is configured through yaml files. In the era of microservices, it is necessary to provide support for the registration center and configuration center.

Target

Refer to dubbo-go to support nacos.

Difficulty

Low

Mentor

@dk-lockdown

Output Requirements

Make seata-golang support registration to nacos and read configuration from nacos and etcd.
Make seata-golang client support reading configuration from nacos and etcd.

Technical Requirements

Familiar with the seata-golang,Familiar with the nacos and etcd.

背景

当前,seata-golang 的配置通过 yaml 文件配置,在微服务时代,有必要对注册中心、配置中心提供支持。

目标

参考 dubbo-go 支持 nacos、etcd。

难度

导师

@dk-lockdown

产出要求

使 seata-golang 支持注册到 nacos 、支持从 nacos、etcd 读取配置。
使 seata-golang client 支持从 nacos、etcd 读取配置。

能力要求

熟悉 seata-golang,熟悉 nacos、etcd。

Insert cannot get branch transaction

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

Describe the bug

//ok
tx.ExecContext(ctx, "UPDATE so_master SET memo=? WHERE 1=1 ", time.Now().Format("2006-01-02 15:04:05"))

//error :Branch lock acquire failed xid
tx.ExecContext(ctx, "INSERT INTO testinsert (id) values(?) ", time.Now().Format("2006-01-02 15:04:05"))

To Reproduce

package main

import (
	"context"
	"database/sql"
	"fmt"
	"time"

	"github.com/opentrx/mysql"
	"github.com/transaction-wg/seata-golang/pkg/client"
	"github.com/transaction-wg/seata-golang/pkg/client/config"
	seataContext "github.com/transaction-wg/seata-golang/pkg/client/context"
	"github.com/transaction-wg/seata-golang/pkg/client/tm"
)

const configPath = "./conf/client.yml"

/**
DROP TABLE IF EXISTS `testinsert`;
CREATE TABLE `testinsert` (
  `id` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
*/

func main() {
	//r := gin.Default()
	config.InitConf(configPath)
	client.NewRpcClient()
	mysql.InitDataResourceManager()
	mysql.RegisterResource(config.GetATConfig().DSN)

	sqlDB, err := sql.Open("mysql", config.GetATConfig().DSN)
	if err != nil {
		panic(err)
	}
	sqlDB.SetMaxOpenConns(100)
	sqlDB.SetMaxIdleConns(20)
	sqlDB.SetConnMaxLifetime(4 * time.Hour)

	ctx := context.Background()
	//获取seata的rootContext
	rootContext := seataContext.NewRootContext(ctx)
	//创建seata事务
	seataTx := tm.GetCurrentOrCreate(rootContext)
	seataTx.BeginWithTimeoutAndName(int32(6000000), "test", rootContext)
	xid := rootContext.GetXID()

	ctx = context.WithValue(ctx, "XID", xid)
	tx, err := sqlDB.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelDefault, ReadOnly: false})
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("XID:", xid)

	//update 语句可以正常执行
	//_, err = tx.ExecContext(ctx, "UPDATE so_master SET memo=? WHERE 1=1 ", time.Now().Format("2006-01-02 15:04:05"))
	// insert 语句出现异常
	_, err = tx.ExecContext(ctx, "INSERT INTO testinsert (id) values(?) ", time.Now().Format("2006-01-02 15:04:05"))

	if err != nil {
		fmt.Println(err)
	}
	err = tx.Commit()
	if err != nil {
		fmt.Println(err)
	}
	err = seataTx.Commit(rootContext)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("--------end---")

}

Expected behavior
The insert statement is used normally

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Seata go server不维护了

作为go的seata server的作者,现在seata go server已经不维护了,协议只兼容到0.5.x版本,后面的协议大改版之后,就不支持了。

seata-go user list

Welcome to use seata-go. To know who is using it, pls append your org info as follow,

Organization:Alibaba (Required)
Location: Hangzhou, Zhejiang, China(Required)
Contact: [[email protected]](mailto:[email protected]) (Optional)
Purpose:used as our fundamental transaction lib (Required)
Registry: zookeeper(Required)
Config: zookeeper(Required)
Version: 1.5.5(Required)
TransactionMode: AT\TCC\SAGA\XA
Com/Org Logo:(Optional)
Thanks again for your participation!

Thanks again for your participation!


欢迎使用 seata-go,首先感谢您的使用,其次您可以参考下面的样例来提供您的信息以收集使用场景:

* 组织:阿里巴巴(Required)
* 地点:**杭州(Required)
* 联系方式:[email protected](Optional)
* 场景:阿里内部服务化改造(Required)
* 注册中心: zookeeper(Optional)
* 配置中心: zookeeper(Optional)
* 版本: 1.5.5(Optional)
* 事务模式: AT\TCC\SAGA\XA
* 公司图标:(Optional)

Add TCC async commit configuration

Is your feature request related to a problem? Please describe.
Currently in TCC mode, the commit and rollback are in sync way. I'd like to make them async and able to be configurable.

Describe the solution you'd like
Make the TCC async commit and rollback way configurable

Describe alternatives you've considered
process TCC async commit and rollback in branch session

Additional context
TBD

如果UPDATE, DELETE操作没数据,将导致异常

executor.go中,如果UPDATE, DELETE操作没数据,beforeImage, afterImage将为nil。
有多处使用到的地方,会出现
runtime error: invalid memory address or nil pointer dereference

由于存在多次调用,我怕自己弄的有遗漏,没提PR,留待作者修改。

如何参与呢?

1 后期还有什么维护计划吗?
2 代码有更详细的文档说明吗?

base/model/set.go代码优化

base/model/set.go

// Len returns the number of items in a set.
func (s *Set) Len() int {
	return len(s.List())
}

改成下面效率会更高

// Len returns the number of items in a set.
func (s *Set) Len() int {
	s.RLock()
	defer s.RUnlock()
	return len(s.m)
}

合并grpc和Getty的分支

分成两个版本的分支日后难以维护,是否存在通过接口屏蔽GRPC和Getty的差异,用户可以通过配置切换

branchID is int64 instead of string

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

Describe the bug
branchID is bigint type in database, and int64 in seata-golang, but its type is defined string in BusinessActionContext

To Reproduce
No error to be reproduced. This is not a bug actually, just need to set BranchID to a correct type

Expected behavior
None

Screenshots
image
image

Additional context
None

golint is obsolete

Is your feature request related to a problem? Please describe.
Golint is deprecated by official golint

Describe the solution you'd like
how about use golangci-lint : golangci-lint
I'd like to update github action and create a pull-req to fix lint if any

Describe alternatives you've considered

Additional context
image

[Summer2021] Support postgresql and oracle(achieve one)

Background

More and more people use the golang to develop microservices. The seata-golang distributed transaction framework already supports mysql database. Some companies use postgresql database and oracle database, so it is necessary to provide support for postgresql database and oracle database.

Target

Refer to mysql driver to implement postgresql driver and oracle driver.

Difficulty

Medium

Mentor

@dk-lockdown

Output Requirements

make seata-golang support postgresql.
make seata-golang support oracle.
achieve one of two.

Technical Requirements

Familiar with the mysql driver,understand the principle.

背景

越来越多人使用 go 语言开发微服务,seata-golang 分布式事务已经支持 mysql 数据库,还有公司使用 postgresql 数据库、oracle 数据库,所以有必要对 postgresql 数据库、oracle 数据库也提供支持。

目标

参考 mysql driver 实现 postgresql driver、oracle driver。

难度

导师

@dk-lockdown

产出要求

使 postgresql driver 集成 seata。
使 oracle driver 集成 seata。
二选一实现。

能力要求

熟悉 mysql driver 的原理。

麻烦帮看下这些错误是如何产生的?

最新版本,mariadb最新版本。

2022-03-02T09:20:33.737+0800	ERROR	log/logging.go:178	exception committing branch xid=%!d(string=stock:9243734585778180) branchID=9243734585778182, err: driver: bad connection
2022-03-02T09:20:33.737+0800	ERROR	log/logging.go:178	failed to async committing [stock:9243734585778180]
2022-03-02T09:20:33.746+0800	ERROR	log/logging.go:178	exception committing branch xid=%!d(string=stock:9243734585778184) branchID=9243734585778186, err: there is no resource manager for AT
2022-03-02T09:20:33.746+0800	ERROR	log/logging.go:178	failed to async committing [stock:9243734585778184]
2022-03-02T09:20:33.757+0800	ERROR	log/logging.go:178	exception committing branch xid=%!d(string=common:9243734585778187) branchID=9243734585778189, err: driver: bad connection
2022-03-02T09:20:33.757+0800	ERROR	log/logging.go:178	failed to async committing [common:9243734585778187]
2022-03-02T09:20:33.761+0800	INFO	log/logging.go:158	global[%!d(string=stock:9243734585778192)] committing is successfully done.
2022-03-02T09:20:33.765+0800	INFO	log/logging.go:158	global[%!d(string=stock:9243734585778193)] committing is successfully done.
2022-03-02T09:20:43.774+0800	ERROR	log/logging.go:178	exception committing branch xid=%!d(string=stock:9243734585778180) branchID=9243734585778183, err: there is no resource manager for AT
2022-03-02T09:20:43.774+0800	ERROR	log/logging.go:178	failed to async committing [stock:9243734585778180]
2022-03-02T09:20:43.787+0800	INFO	log/logging.go:158	global[%!d(string=stock:9243734585778184)] committing is successfully done.
2022-03-02T09:20:43.787+0800	ERROR	log/logging.go:178	exception committing branch xid=%!d(string=common:9243734585778187) branchID=9243734585778189, err: there is no resource manager for AT
2022-03-02T09:20:43.787+0800	ERROR	log/logging.go:178	failed to async committing [common:9243734585778187]
2022-03-02T09:20:53.803+0800	INFO	log/logging.go:158	global[%!d(string=stock:9243734585778180)] committing is successfully done.
2022-03-02T09:20:53.803+0800	ERROR	log/logging.go:178	exception committing branch xid=%!d(string=common:9243734585778187) branchID=9243734585778189, err: there is no resource manager for AT
2022-03-02T09:20:53.803+0800	ERROR	log/logging.go:178	failed to async committing [common:9243734585778187]
2022-03-02T09:21:03.829+0800	INFO	log/logging.go:158	global[%!d(string=common:9243734585778187)] committing is successfully done.

错误判断没有生效

dev 分支,从配置文件读取配置的代码(pkg\config\client_config.go)返回不了错误:

func InitConf(confFile string) error {
	var err error //这里的err 是空的

	if confFile == "" {
                //这里包裹err的时候,因为err是空的,所以这里无法包裹消息
		return errors.WithMessagef(err, fmt.Sprintf("application configure file name is nil"))
	}
	if path.Ext(confFile) != ".yml" {
                //这里和上面是同样的错误
		return errors.WithMessagef(err, fmt.Sprintf("application configure file name{%v} suffix must be .yml", confFile))
	}

	clientConfig = ClientConfig{}
	confFileStream, err := ioutil.ReadFile(confFile)
	if err != nil {
		return errors.WithMessagef(err, fmt.Sprintf("ioutil.ReadFile(file:%s) = error:%s", confFile, err))
	}
	err = yaml.Unmarshal(confFileStream, &clientConfig)
	if err != nil {
		return errors.WithMessagef(err, fmt.Sprintf("yaml.Unmarshal() = error:%s", err))
	}

	(&clientConfig).GettyConfig.CheckValidity()
	(&clientConfig).ATConfig.CheckValidity()

	if clientConfig.ATConfig.DSN != "" {
		cache.SetTableMetaCache(cache.NewMysqlTableMetaCache(clientConfig.ATConfig.DSN))
	}
	return nil
}

Support Struct Configuration

Is your feature request related to a problem? Please describe.
I want to support configuration of struct type instead of yaml file, so that we can find missing config and config errors in go build or go run main.go step, which, will also make it easier to find configurations (in our IDE)

Describe the solution you'd like
I'd like to use .env file and configurations of struct type to manage the configurations.
.env example:

SERVER_PORT=8091
port := config.Cfg.Server.Port

Describe alternatives you've considered

Additional context

请教问题

AT模式下我没有找到分支执行BranchRegister和LockQuery 的具体地方, 只看到RM直接本地commit了(samples里的代码). 可以解答一下吗, 非常感谢

Add env variable support for configs

Is your feature request related to a problem? Please describe.

We want to deploy the tc server at kubernetes with a config file, which stays inside git. So the problem is we want to hide the config credentials, such as db password, username from git.

At this moment, the most important config we want to hide from config file is https://github.com/opentrx/seata-golang/blob/dev/cmd/profiles/dev/config.yml#L34

Describe the solution you'd like
When this config is initialized from file, add an env variable fallback, so we can deploy these db credentials from env.

Describe alternatives you've considered
Maybe config center in the @todo list of this project can solve this issue as well.

Additional context
nope

回滚不成功

tc小错误:
TC中带的config.yml
globaltable: global_table2
branchtable: branch_table2
SQL脚本创建的表名不带2的。会导致进不了CreateSo方法。

在product中,故意写错误,在seata_order数据库中,undo_log表有记录,但是branch_transaction没有记录。
在global_transaction.go中的
status, err := gtx.transactionManager.Rollback(ctx, gtx.XID)
却没有报错。实际第一步的order操作回滚失败的。

请检查一下

关于 import 的包分组写法的疑问

import (
	"time"
)

import (
	"github.com/dubbogo/getty"
	"github.com/pkg/errors"
)

import (
	"github.com/dk-lockdown/seata-golang/base/getty/config"
)

为什么把 import 的包通过多个 import 来拆分呢?我在其他开源项目里没看到过这种写法,如果写成通过空行来分组是不是更好一些?如下:

import (
	"time"

	"github.com/dubbogo/getty"
	"github.com/pkg/errors"

	"github.com/dk-lockdown/seata-golang/base/getty/config"
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.