FastLu17 / guidepost

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Guidepost

The Guidepost is a solution of Database Read Write Splitting. It only supports MySQL with Group replication right now. (MySQLInnoDB Cluster is supported since it is using Group Replication.) It does the following works.

  • Proxying DataSource

The Guidepost creates Pooled Data Source of each available database server, and wrap them into a new Data Source which named GuidepostDataSource. When GuidepostDataSource.getConnection() is called, it determines whether current Transaction is readonly or not, then use a DataSource of a readonly server to get a database connection if current Transaction is readonly, otherwise it used one of the DataSources of writable servers.

  • Database Topology Discovery.

The Guidepost retrieve database servers information periodically. It will create DataSource of newly added server automatically. It will also discard the DataSources of removed/offline database servers. And it will periodically check the servers whether they are readonly or writable.

How to Use

Please check the demo: guidepost-demo

  • Depend on the Whistle in maven pom.xml.
        <dependency>
            <groupId>org.coderclan</groupId>
            <artifactId>spring-boot-starter-guidepost</artifactId>
        </dependency>

Limitation

  • Autocommit of GuidepostDataSource will always be set to false.
  • Property hibernate.connection.handling_mode need to be set to DELAYED_ACQUISITION_*. Guidepost set it to DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION default.

(If the two above requirements didn't meet, org.springframework.transaction.support.TransactionSynchronizationManager.isCurrentTransactionReadOnly will return false always. )

About

License:Apache License 2.0


Languages

Language:Java 100.0%