Shard-Jdbc-based sub-library sub-table mode, the database expansion program

This article Source: GitHub · Click here || GitEE · Click here

First, the database expansion

1, business scene

Internet project, there are many "data volume, high complexity business requires sub-library sub-table" business scenarios.

Shard-Jdbc-based sub-library sub-table mode, the database expansion program

Such layered architecture
(1) is an upper layer service biz, business logic package;
(2) service is an intermediate layer service, access to encapsulated data;
(3) the lower layer is the data db, store business data;

2, expansion scenarios and issues

When the amount of data is continuously added, are faced with a number of requirements, can not accommodate two database, the database required expansion, Pick 2 - to three expansion mode, as shown below:

Shard-Jdbc-based sub-library sub-table mode, the database expansion program

Such expansion problem
(1) sub-library sub-table strategy led to large data migration;
(2) the impact of continuous service data;
(3) a specified time to complete, technical pressure, error-prone unexpected;

How smooth non-stop migration of data to ensure continuous service system, this article is a question to be discussed.

Second, the expansion of the solution

1, illustrating expansion program

Shard-Jdbc-based sub-library sub-table mode, the database expansion program

(1) sub-library sub-table based on MySQL database, use the shard-jdbc middleware
(2) the idea of the program as a whole based on SpringCloud micro Services Architecture

2, to solve the problem of expansion

(1) suspended without the need for expansion;
Small (2) the pressure data migration, does not require a specified time;

3, the data access layer logic

Shard-Jdbc-based sub-library sub-table mode, the database expansion program

Program description
based on two database sub-library sub-table, referred to as: two services
based on three sub-library sub-table database, referred to as: three services
(1) provides two sets of services, service two and three services
(2) expansion of the database, if access service Triple direct access to the data, the process ends.
(3) If you can not get access to the service three data, the two services to get data access.
(4) over a period of time migration starts, the pressure will visit the two services above.
(5) so that it does not stop data access services.
(6) This access model is based on SpringCloud very easy to do.

4, the logical data migration layer

Shard-Jdbc-based sub-library sub-table mode, the database expansion program

Program Description
(1) close the storage process based on two data libraries
(2) open storage process based on three data libraries, so the new storage data can be accessed directly to the three services.
(3) development of a data migration middleware, scanning both the original data library.
(4) whether the scanned data needs to be migrated based on three sub-library policy decisions.
(5) If the data needs to be migrated, then call the three service data storage interface.
(6) Data migration is complete, delete the original location of the data.
(7) This migration patterns based on SpringCloud very easy to do.

5, the advantages of the migration program

(1) The entire process is continued for the online service;
lower development complexity (2) Data Migration middleware;
(3) may migrate slowly speed, there is no time pressure;

Third, source code management

GitHub·地址
https://github.com/cicadasmile/spring-cloud-base
GitEE·地址
https://gitee.com/cicadasmile/spring-cloud-base

Shard-Jdbc-based sub-library sub-table mode, the database expansion program

Guess you like

Origin blog.51cto.com/14439672/2443885