当前位置:网站首页>Shardingsphere-proxy-5.0.0 distributed snowflake ID generation (III)
Shardingsphere-proxy-5.0.0 distributed snowflake ID generation (III)
2022-07-27 16:55:00 【Luo Lei】
High quality resource sharing
| Learning route guidance ( Click unlock ) | Knowledge orientation | Crowd positioning |
|---|---|---|
| 🧡 Python Actual wechat ordering applet 🧡 | Progressive class | This course is python flask+ Perfect combination of wechat applet , From the deployment of Tencent to the launch of the project , Create a full stack ordering system . |
| Python Quantitative trading practice | beginner | Take you hand in hand to create an easy to expand 、 More secure 、 More efficient quantitative trading system |
One 、 Purpose
Ensure the uniqueness of each data in the sub database and sub table
Two 、 Modify the configuration file config-sharding.yaml, And restart the service
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
######################################################################################################
#
# Here you can configure the rules for the proxy.
# This example is configuration of sharding rule.
#
######################################################################################################
#
#schemaName: sharding\_db
#
#dataSources:
# ds\_0:
# url: jdbc:postgresql://127.0.0.1:5432/demo\_ds\_0
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# ds\_1:
# url: jdbc:postgresql://127.0.0.1:5432/demo\_ds\_1
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
#
#rules:
#- !SHARDING
# tables:
# t\_order:
# actualDataNodes: ds\_${0..1}.t\_order\_${0..1}
# tableStrategy:
# standard:
# shardingColumn: order\_id
# shardingAlgorithmName: t\_order\_inline
# keyGenerateStrategy:
# column: order\_id
# keyGeneratorName: snowflake
# t\_order\_item:
# actualDataNodes: ds\_${0..1}.t\_order\_item\_${0..1}
# tableStrategy:
# standard:
# shardingColumn: order\_id
# shardingAlgorithmName: t\_order\_item\_inline
# keyGenerateStrategy:
# column: order\_item\_id
# keyGeneratorName: snowflake
# bindingTables:
# - t\_order,t\_order\_item
# defaultDatabaseStrategy:
# standard:
# shardingColumn: user\_id
# shardingAlgorithmName: database\_inline
# defaultTableStrategy:
# none:
#
# shardingAlgorithms:
# database\_inline:
# type: INLINE
# props:
# algorithm-expression: ds\_${user\_id % 2}
# t\_order\_inline:
# type: INLINE
# props:
# algorithm-expression: t\_order\_${order\_id % 2}
# t\_order\_item\_inline:
# type: INLINE
# props:
# algorithm-expression: t\_order\_item\_${order\_id % 2}
#
# keyGenerators:
# snowflake:
# type: SNOWFLAKE
# props:
# worker-id: 123
######################################################################################################
#
# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory.
#
######################################################################################################
# Connect mysql Database name used
schemaName: MyDb
dataSources:
ds\_0:
url: jdbc:mysql://127.0.0.1:3306/MyDb?serverTimezone=UTC&useSSL=false
username: root # Database user name
password: mysql123 # The login password
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
# ds\_1:
# url: jdbc:mysql://127.0.0.1:3306/demo\_ds\_1?serverTimezone=UTC&useSSL=false
# username: root
# password:
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
#
# The rules
rules:
- !SHARDING
tables:
t\_product: # The name of the table to be split
actualDataNodes: ds\_0.t\_product\_${0..1} # expression , Divide the table into t\_product\_0 , t\_product\_1
tableStrategy:
standard:
shardingColumn: product\_id # Field name
shardingAlgorithmName: t\_product\_MOD
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake # Snowflake algorithm
# t\_order\_item:
# actualDataNodes: ds\_${0..1}.t\_order\_item\_${0..1}
# tableStrategy:
# standard:
# shardingColumn: order\_id
# shardingAlgorithmName: t\_order\_item\_inline
# keyGenerateStrategy:
# column: order\_item\_id
# keyGeneratorName: snowflake
# bindingTables:
# - t\_order,t\_order\_item
# defaultDatabaseStrategy:
# standard:
# shardingColumn: user\_id
# shardingAlgorithmName: database\_inline
# defaultTableStrategy:
# none:
#
shardingAlgorithms:
t\_product\_MOD: # Mold name , Customizable
type: MOD # Modular algorithm
props:
sharding-count: 2 # Number of slices , Because I divided 2 Tables , So this is 2
# t\_order\_inline:
# type: INLINE
# props:
# algorithm-expression: t\_order\_${order\_id % 2}
# t\_order\_item\_inline:
# type: INLINE
# props:
# algorithm-expression: t\_order\_item\_${order\_id % 2}
#
keyGenerators:
snowflake: # Snowflake algorithm name , Custom name
type: SNOWFLAKE
props:
worker-id: 123

3、 ... and 、 Data preparation
-- Create table
SET NAMES utf8mb4;
SET FOREIGN\_KEY\_CHECKS = 0;
-- ----------------------------
-- Table structure for t\_product\_0
-- ----------------------------
DROP TABLE IF EXISTS `t\_product`;
CREATE TABLE `t\_product\_0` (
`id` varchar(225) CHARACTER SET utf8mb4 COLLATE utf8mb4\_general\_ci NOT NULL,
`product\_id` int(11) NOT NULL,
`product\_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4\_general\_ci NOT NULL,
PRIMARY KEY (`id`, `product\_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4\_general\_ci ROW\_FORMAT = Dynamic;
SET FOREIGN\_KEY\_CHECKS = 1;
-- Insert table data
INSERT INTO t\_product(product\_id,product\_name) VALUES(1,'apple');
INSERT INTO t\_product(product\_id,product\_name) VALUES(2,'banana');
Four 、 View the data
1、 see shardingsphere middleware t_product Table data , among id Fields will automatically generate unique id

2、 see t_product_0、t_product_1 Table data , At the same time, the data is stored in tables ( Because the configuration file contains table splitting configuration )


边栏推荐
- [paper reading] single- and cross modality near duplicate image pairsdetection via spatial transformer compare
- Opencv (III) -- image segmentation
- Apache
- Jupyter creates a virtual environment and installs pytorch (GPU)
- Get the array list of the previous n days and the previous and subsequent days of the current time, and cycle through each day
- Life game, universe 25 and striver
- Cubemx combined with IAR engineering transplantation
- After the cubemx is reconfigured, the generated code cannot be opened successfully with IAR
- C语言之动态内存分配
- Circular statements and arrays
猜你喜欢

Simulation generate report

CODIS cluster deployment

OpenCV(三)——图像分割
![[paper reading] single- and cross modality near duplicate image pairsdetection via spatial transformer compare](/img/33/8af12d58f4afeb807ebf9a90a2ea47.png)
[paper reading] single- and cross modality near duplicate image pairsdetection via spatial transformer compare

C语言之指针进阶

【论文阅读】A CNN-transformer hybrid approach for decoding visual neuralactivity into text
![Jerry's built-in touch parameters for modification [chapter]](/img/6b/38c3ad28a7256e5e41bb444d0993db.png)
Jerry's built-in touch parameters for modification [chapter]

Matlab legend usage

UML图介绍
The difference between MVC and MVP and MVVM
随机推荐
Duplicate numbers in array
T5 learning
Servlet用Cookie实现用户上次登录时间
Servlet uses cookies to realize the last login time of users
数据库基础
Get the array list of the previous n days and the previous and subsequent days of the current time, and cycle through each day
Crawl common English names
How to modify the decoding clock [chapter]
Supplement - example of integer programming
jsp-El表达式,JSTL标签
清晰的认识Torchvision(思维导图版)
C language output string in reverse order
牛客题目——链表的奇偶重排、输出二叉树的右视图、括号生成、字符流中第一个不重复的字符
Jerry's maximum volume prompt sound cannot be broadcast [article]
The difference between select/poll/epoll
C语言之程序环境和预处理
mvc和mvp和mvvm的区别
HowNet and Wanfang database download papers for free ----- several times faster than connecting to the school intranet (some schools Wanfang database does not support downloading)
Collection! 0 basic open source data visualization platform flyfish large screen development guide
(2) Dynamic convolution of dynamic convolution