Coder Social home page Coder Social logo

rentiansheng / mongodb_driver_transaction Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 5.12 MB

Use Mongodb Driver To Solve Distributed Transactions

Home Page: http://www.ireage.com/%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8/2021/01/03/mongodb_go_driver_distributed_transaction_en.html

License: Apache License 2.0

Makefile 0.17% Go 97.77% Perl 0.96% Python 0.41% Shell 0.11% C 0.58%
mongodb

mongodb_driver_transaction's Introduction

中文文档

Use mongodb driver to solve distributed transactions

Solving distributed transaction scenarios

This project can only solve distributed transactions in multiple tables in the same database in the same replica-set in mongodb.

Main principles

The mongodb server does not strictly bind the transaction in which the transaction is in, and the mongodb driver can initiate transactions to achieve this. Changing this solution will extend the mongodb golang driver code, It can be used for verification in mongodb driver 1.1.2 release and mongodb 4.0.x-4.2.x replica-set mode

mongodb golang driver code extension content

Extension code:

 mongo/session_exposer.go
 x/mongo/driver/session/session_ext.go

The extension code is mainly the underlying logic, used to activate the transaction and bind the transaction. Does not contain business logic

Related test cases:

Transaction/Transaction_test.go

Upper-level use logic:

Transaction/Transaction.go

Encapsulate business logic, realize business-level management interfaces such as opening, committing, and rolling back transactions, and provide an operation interface for the transaction uuid and the cursor id record operation of the statement execution within the transaction.

Now that the real transaction id of mongodb is directly exposed, there may be security risks in passing between different service nodes.

Specific implementation
  1. Activate a transaction, generate a transaction uuid (mongodb driver provides the generation method), Transaction/Transaction.go: StartTransaction
  2. Activate a session through the uuid of the transaction and join a transaction of the mongodb server, Transaction/Transaction.go: ReloadSession
  3. Bind the transaction to the session, get the SessionContext, mongo/session_exposer.go:TxnContextWithSession
  4. Perform curl operations

Solution implementation

Use project:

BlueKing Configuration Platform

Drainage

bson decode register

Bson decoding interface priority uses the actual type as the final object, such as slice, map In the mongodb golang official driver, when bson uses interface at the top level, it puts slice and map in an object called primitive.D (golang []interface type).

mongodb_driver_transaction's People

Contributors

rentiansheng avatar

Stargazers

 avatar  avatar Four Hu avatar liujiangshuai avatar

Watchers

 avatar  avatar

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.