ShardingSphere-proxy-5.0.0容量范围分片的实现(五)

一、修改配置文件config-sharding.yaml,并重启服务

#
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.

#
######################################################################################################

连接mysql所使用的数据库名
 schemaName: MyDb

 dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/MyDb?serverTimezone=UTC&useSSL=false
    username: root # 数据库用户名
    password: mysql123  # 登录密码
    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
#
规则
 rules:
 - !SHARDING
   tables:
     t_product: #需要进行分表的表名
       actualDataNodes: ds_0.t_product_${0..1} # 表达式,将表分为t_product_0 , t_product_1
       tableStrategy:
        standard:
           shardingColumn: product_id # 字段名
           shardingAlgorithmName: t_product_VOLUME_RANGE
       keyGenerateStrategy:
         column: 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:
     t_product_VOLUME_RANGE: # 取模名称,可自定义
       type: VOLUME_RANGE # 取模算法
       props:
         range-lower: '5' # 最小容量为5条数据,仅方便测试
         range-upper: '10' #最大容量为10条数据,仅方便测试
         sharding-volume: '5' #分片的区间的数据的间隔
   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

ShardingSphere-proxy-5.0.0容量范围分片的实现(五)

二、数据准备

-- 创建表
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for t_product
-- ----------------------------
DROP TABLE IF EXISTS t_product;
CREATE TABLE t_product  (
  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 INTO t_product(product_id,product_name) VALUES(1,'one');
INSERT INTO t_product(product_id,product_name) VALUES(2,'two');
INSERT INTO t_product(product_id,product_name) VALUES(3,'three');
INSERT INTO t_product(product_id,product_name) VALUES(4,'four');
INSERT INTO t_product(product_id,product_name) VALUES(5,'five');
INSERT INTO t_product(product_id,product_name) VALUES(6,'six');
INSERT INTO t_product(product_id,product_name) VALUES(7,'seven');

三、查看数据

1、查看shardingsphere中间件t_product表数据

ShardingSphere-proxy-5.0.0容量范围分片的实现(五)

2、查看t_product_0、t_product_1表数据,同时对数据进行了分表存储(因为配置文件中有做分表和雪花id生成配置)

ShardingSphere-proxy-5.0.0容量范围分片的实现(五)

ShardingSphere-proxy-5.0.0容量范围分片的实现(五)

Original: https://www.cnblogs.com/sportsky/p/16407097.html
Author: SportSky
Title: ShardingSphere-proxy-5.0.0容量范围分片的实现(五)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/609984/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • gnutls_handshake() failed

    原文链接:https://www.zhoubotong.site/post/75.html使用git clone https://github.com/xxx.git的时候,出现错…

    Linux 2023年6月6日
    0139
  • 世界上最流行的操作系统不是Windows?

    前言 打住,我知道列位是被标题骗进来的,但是这个论题并不是我瞎吹牛,世界上最流行的操作系统还真不是Windows。 提及操作系统,我们印象中比较深刻的无非就是Windows,Lin…

    Linux 2023年6月13日
    0158
  • Twikoo私有化部署教程–迁移腾讯云

    备份数据 私有化部署 创建容器 导入数据 重新配置twikoo面板设置 引入前端CDN Nginx https反代http 作者:小牛呼噜噜 | https://xiaoniuhu…

    Linux 2023年6月6日
    0183
  • shell脚本

    一、shell脚本基本介绍 格式要求 脚本要以 #!/bin/bash 开头,debain需要改成#!/bin/dash 脚本需要有可执行权限 shell常用执行方式 输入脚本的绝…

    Linux 2023年6月6日
    0114
  • DOS-批处理隐藏自身窗口

    批处理隐藏运行效果代码,防止出现黑窗口不建议非法用途,可以用来执行命令,提供用户体验。 运行bat时隐藏cmd窗口的方法 运行bat时隐藏cmd窗口的方法 可以编辑一个vbs脚本,…

    Linux 2023年6月8日
    0155
  • SpringBoot中通过AOP整合日志文件

    1.SpringBoot中通过AOP整合日志文件 1. 导入相关的依赖 org.springframework.boot spring-boot-starter org.sprin…

    Linux 2023年6月14日
    0133
  • 项目经验示例

    一,期中项目经验示例 1,根据现有结构部署工具(PXE+kickstart)2,结合应用系统需求定制部署模版3,制作系统优化等一键执行脚本4,自动化部署实施5,根据定制的优化内容对…

    Linux 2023年6月7日
    0127
  • Shell中$0、$?、$!、$$、$*、$#、$@

    1. $$Shell本身的PID(ProcessID) 2. $!Shell最后运行的后台Process的PID 3. $?最后运行的命令的结束代码(返回值) 4. $-使用Set…

    Linux 2023年5月28日
    0124
  • 自动化集成:Pipeline整合Docker+K8S

    前言:该系列文章,围绕持续集成:Jenkins+Docker+K8S相关组件,实现自动化管理源码编译、打包、镜像构建、部署等操作; 本篇文章主要描述流水线集成K8S用法。 一、背景…

    Linux 2023年5月27日
    0207
  • redis cluster 数据迁移

    1,先停止java的后台和.net的后台,停止对redis cluster进行访问 2,然后 cd /usr/local/redis-cluster/7001 每个节点都要做如下操…

    Linux 2023年5月28日
    0120
  • Windows 域控配置时间同步

    此功能是因内网时间与互联网时间不同步,需我们手动指定互联网NTP服务器来同步时间。一般默认情况下,加域客户端同步的是域主机的时间。如果域控的主机时间不准的话,那么域内的客户端也就随…

    Linux 2023年6月8日
    0187
  • 版本控制gitlab

    版本控制gitlab 版本控制gitlab 什么是版本控制gitlab gitlab部署 什么是版本控制gitlab GitLab 是一个用于仓库管理系统的开源项目,使用Git作为…

    Linux 2023年6月6日
    0147
  • [LINUX] Arch Linux 硬盘拷贝式装系统+新增 home 分区

    前言 1. 实操 1.1 整个磁盘拷贝 1.2 创建 home 分区 1.3 修改 fstab 实现自动挂载 2. 涉及到的知识点 2.1 fstab 2.2 dd 命令 2.3 …

    Linux 2023年5月27日
    0255
  • Tensorflow

    1.什么是Tensorflow? Tensor(张量)意味着 N 维数组,Flow(流)意味着基于数据流图的计算,TensorFlow即为张量从图的一端流动到另一端。 它支持CNN…

    Linux 2023年6月6日
    0136
  • 编程入门之日志聚合系统

    (关心具体部署的同学,可以移步我的另外一篇《Centos部署Loki日志聚合系统 》https://www.cnblogs.com/uncleguo/p/15975647.html…

    Linux 2023年6月13日
    0125
  • 初识MySQL数据库

    一 、引言 假设现在你已经是某大型互联网公司的高级程序员,让你写一个火车票购票系统,来hold住双十一期间全国的购票需求,你怎么写? 由于在同一时段抢票的人数太多,所以你的程序不可…

    Linux 2023年6月14日
    0159
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球