Skip to content

taiqiang/sharding-jdbc

 
 

Repository files navigation

License

Maven Status GitHub release Download

Build Status Coverage Status Gitter OpenTracing-1.0 Badge Skywalking Tracing

Overview

Sharding-JDBC: A data sharding, read-write splitting, BASE transaction and database orchestration middleware. It provides maximum compatibilities for applications by JDBC and MySQL protocol.

Document

EN doc Roadmap

CN doc

Features

1. Data sharding

  • Both databases and tables sharding supported.
  • Standard aggregation functions, GROUP BY, ORDER BY, LIMIT and JOIN DQL supported.
  • Standard DML, DDL, TCL and database administrator command supported.
  • Sharding operator =, BETWEEN and IN supported.
  • Sharding algorithm customization and inline expression supported.
  • Route by hint supported.
  • Distributed sequence supported.

2. Read-write splitting

  • Multiple slaves replica supported.
  • Data consistency guarantee in same thread supported.
  • Mix read-write splitting and data sharding supported.
  • Route by hint supported.

3. BASE Transaction

  • Best efforts delivery transaction supported.
  • Try confirm cancel transaction (TBD).

4. Orchestration

  • Configuration center supported, can refresh dynamically.
  • Circuit breaker supported.
  • Open tracing supported.

Architecture

Sharding-JDBC-Driver

Use JDBC connect databases without redirect cost for java application, best performance for production.

  • ORM compatible. JPA, Hibernate, Mybatis, Spring JDBC Template or JDBC supported.
  • Connection-pool compatible. DBCP, C3P0, BoneCP, Druid supported.
  • Multi SQL-based databases compatible. Any Database supported theoretically. Support MySQL, Oracle, SQLServer and PostgreSQL right now.

Sharding-JDBC-Driver Architecture

Sharding-JDBC-Server

Database router. Deploy as a stateless server, support MySQL protocol for now.

  • Use standard MySQL protocol, application do not care about whether proxy or real MySQL.
  • Any MySQL command line and UI workbench supported in theoretically. MySQL Workbench are fully compatible right now.

Sharding-JDBC-Server Architecture

Sharding-JDBC-Sidecar(TBD)

Use sidecar to connect databases, best for Kubernetes or Mesos together.

Sharding-JDBC-Sidecar Architecture

Quick Start

Sharding-JDBC-Driver

Add maven dependency

<!-- import sharding-jdbc core -->
<dependency>
    <groupId>io.shardingjdbc</groupId>
    <artifactId>sharding-jdbc-core</artifactId>
    <version>${latest.release.version}</version>
</dependency>

Configure sharding rule

Sharding-JDBC support 4 types for sharding rule configuration, they are Java, YAML, Spring namespace and Spring boot starter. Developers can choose any one for best suitable situation.

Create DataSource

Use ShardingDataSourceFactory to create ShardingDataSource, which is a standard JDBC DataSource. Then developers can use it for raw JDBC, JPA, MyBatis or Other JDBC based ORM frameworks.

DataSource dataSource = ShardingDataSourceFactory.createDataSource(dataSourceMap, shardingRuleConfig);

Sharding-JDBC-Server

Configure sharding rule

Edit ${sharding-jdbc-server}\conf\sharding-config.yaml. Same format with Sharding-JDBC-Driver's YAML configuration.

Start server

${sharding-jdbc-server}\bin\start.sh ${port}

About

Distributed database middleware

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.9%
  • Other 0.1%