Giter VIP home page Giter VIP logo

easycar's Introduction

easycar

简体中文

What is easycar?

easycar is a distributed transaction framework implemented in go that supports a two-phase commit protocol. Its full name is (easy commit and rollback).

For more information about easycar see this post easycar.

Architecture

easycar

Features

Supports both protocol and transaction mode mixing

In a set of distributed transactions, each RM can use a different transport protocol (HTTP/gRPC) and transaction mode ( TCC/Sage...), so it allows a mix of RM protocols and transaction modes.

Support for concurrent execution of transactions

Supports concurrent execution in layers. The participating RMs are layered by the set weights, and RMs in the same layer can be invoked concurrently, and the next layer is processed after one layer is finished.

Service Registration and Discovery

Currently supports etcd and consul.

Client-side load balancing

Support

  • IPHash
  • ConsistentHash
  • P2C
  • Random
  • R2
  • LeastLoad
  • Bounded

Examples of success

success

Examples of failed

success

State

global state global

Run

cp conf.example.yml conf.ymal

Modify configuration

## conf
automaticExecution2: true  #when the first stage of execution ends, it will commit automatically or rollback if it is true
timeout: 7 #unit of second
server:
  grpc:
    listenOn: 127.0.0.1:8088
    keyFile:   #server key
    certFile:  #server cert
    gateway:
      isOpen: true
      certFile:  #client cert
      serverName:
  http:
    listenOn: 127.0.0.1:8085

db: #easycar server db
  driver: mongodb
  mysql:
    dbURL: easycar:easycar@tcp(127.0.0.1:3306)/easycar?charset=utf8&parseTime=True&loc=Local
    maxLifetime: 7200
    maxIdleConns: 10
    maxOpenConns: 20
  mongodb:
    url: mongodb://127.0.0.1:27017/easycar
    minPool: 10
    maxPool: 20

registry: 
  etcd:
    user: ""
    pass: ""
    hosts:
      - 127.0.0.1:2379
  #add more

tracing:
  jaegerUrl: http://localhost:14268/api/traces

cron:
  maxTimes: 2   #max retry times when rm is not available
  timeInterval: 1 #unit is minute. it means that the next retry is 1m later, not in strict mode  

run

go run cmd/main.go 

docker-compose

docker-compose up -d easycar

examples

more examples to:examples

todo list

  • Saga
  • TCC
  • XA
  • client
    • client-go
    • client-rust
    • client-php
    • client-python
    • client-java
  • retry
  • registry and discovery
    • etcd
    • consul
  • balancer
  • notify
  • tracing
  • tool
  • more store

easycar's People

Contributors

mfridman avatar wuqinqiang 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

Watchers

 avatar  avatar  avatar

easycar's Issues

client

easycar 客户端可以执行本地事物,如当前参与分布式事务存在a,b,c三个事务,其中是在a的项目中使用easycar,那么本质上a是可以不走网络请求的,但是如果 a未出错,执行b,c出错了咋么办?这时候本质上回退a也是可以在本地执行的,但是地址照样需要提交的。

二阶段其中一个RM出错,不能影响其他RM执行

目前两个阶段并发执行的时候,一旦某一层其中一个RM发生错误时,下一层的RM不会被请求。

在一阶段这样没问题,毕竟一阶段RM发生错误,说明都需要直接回滚,一阶段没有请求到的RM相当于还没参与,对这些RM数据没影响。

但是在二阶段就会存在问题。

假设目前RM分为三层:A (TCC)在第一层,B(TCC)在第二层,C(Saga)在第三层。

假设一阶段 A Try 正常,B Try 正常,C 异常。

此时一阶段失败,

执行第二阶段 A的Cancel发生异常,按照目前的逻辑,

那么二阶段的B的Cancel 和C的compensation 将不会执行,但是她们的一阶段已经执行了,所以这里有误。

同理,正常情况,

假设一阶段 A Try 正常,B Try 正常,C 正常。

此时一阶段prepre成功,

执行第二阶段 A Commit发生异常,按照目前的逻辑,

那么二阶段 的 B的commit 将不会执行,但是她们的一阶段已经执行了,所以这里有误。

解决方案就是 第二阶段本质不需要分层,因为二阶段的时候已经不会有先后关系了。

Execution level of transactions?

事务分支执行可以有以下情况

  • 常规,无依赖4个可以并发调用
  • 有依赖,所谓分层。每一层相同级别可以局部并发
  • 有依赖,每一层除了局部并发,下一层可能依赖上一层的执行结果,父子关系

// 常规情况 无依赖 4个并发调用 (branch1 branch2 branch3 branch4)

Example1

branch1 branch2 branch3 branch4 并发执行

Example2

branch1 branch3 step1

branch2 branch4 step2

Example3

branch1 branch3 step1

依赖1结果 依赖3结果

branch2 branch4 step2

bug:docker-compose

run,

docker-compose up easycar

[error] failed to initialize database, got error dial tcp 127.0.0.1:3306: connect: connection refused
easycar_1 | panic: dial tcp 127.0.0.1:3306: connect: connection refused

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.