Giter Site home page Giter Site logo

fireside-story / nodetcc Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 797 KB

Node.js分布式事务框架, NodeTCC is an open source distributed transaction solution for Node.js

JavaScript 100.00%
tcc-transaction distributed-transaction microservice tcc transaction

nodetcc's Introduction

一、简介

这是一个分布式事务框架,支持 Mysql、Postgres、Mariadb、Sqlite, 功能如下:

  • 资源管理器,追踪事务数据的读写操作,保存数据快照,
  • 事务协调器,开启子事务,并将其添加至全局事务,
  • 事务管理器,设置全局事务隔离级别、超时时间,管理全局/子事务的挂起、提交、回滚

roadmap

  • 内存模式下的事务处理,基于 redis 实现关注高性能,不保证全局事务的原子性
  • RPC 调用下的事务处理,针对微服务,消息队列等, 基于中间件实现
  • 基于 redis 的 Undo Log,实现去全局事务的隔离级别、并发提交及回滚处理

二、用例

const NodeTCC = require('node-tcc');

/**
 * @param Models: sequelize Model
 * @param durable
 * - true   内存模式,
 * - false  持久化模式,
 */
NodeTCC.init(Models, redisConfig, { durable: true, tccDB: sequelize });

/**
 * 针对三种不同数据源resourceA、resourceB、resourceC,做写操作
 *
 * @param {Object} options
 * @param {String} options.isolationLevel 全局事务隔离级别,默认READ_UNCOMMITTED
 *  - READ_UNCOMMITTED: 读未提交
 *  - READ_COMMITTED:   读已提交
 *  - REPEATABLE_READ:  可重复读
 *  - SERIALIZABLE:     串行化
 * @param {Number} options.timeout 超时时间,默认3000秒
 * @param {Transaction} gt 事务协调器, start:添加子事务,其中任何一方失败,全局事务将回滚, 返回Promise。
 */
NodeTCC.transaction(options, async gt => {
  await resourceA.create({ amount: 1 }, { transaction: await gt.start(resourceA, options) });
  await resourceB.create({ amount: 2 }, { transaction: await gt.start(resourceB, options) });
  await resourceC.create({ amount: 3 }, { transaction: await gt.start(resourceC, options) });
});
  • 备注
1、全局事务依赖Hook,请勿禁用

nodetcc's People

Contributors

time-gate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

yutiansut

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.