You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2022/05/09 07:17:38 UTC
[shardingsphere] branch master updated: Update outdated examples under examples/docker (#17177)
This is an automated email from the ASF dual-hosted git repository.
wuweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new a5d125bb135 Update outdated examples under examples/docker (#17177)
a5d125bb135 is described below
commit a5d125bb135ad1126f7f143b4d282c278108a8e7
Author: VOPEN.XYZ <x_...@yeah.net>
AuthorDate: Mon May 9 15:17:31 2022 +0800
Update outdated examples under examples/docker (#17177)
* Update outdated examples under examples/docker
* Fix docker-compose script comment description issue
* Update docker-compose.yml
Replace docker image name to apache/shardingsphere-proxy
---
examples/docker/docker-compose-zh.md | 2 +-
examples/docker/docker-compose.md | 2 +-
.../sharding/conf/config-sharding.yaml | 39 ++++++---
.../shardingsphere-proxy/sharding/conf/server.yaml | 2 +-
.../sharding/docker-compose.yml | 41 +++++----
examples/docker/tools/wait-for-it.sh | 0
examples/src/resources/manual_schema.sql | 99 +++++++++-------------
7 files changed, 87 insertions(+), 98 deletions(-)
diff --git a/examples/docker/docker-compose-zh.md b/examples/docker/docker-compose-zh.md
index 6b89cfd6fc1..3ed0ae6d39d 100644
--- a/examples/docker/docker-compose-zh.md
+++ b/examples/docker/docker-compose-zh.md
@@ -14,7 +14,7 @@
1. 运行 'cd docker/shardingsphere-proxy/sharding',进入 docker 文件夹
2. 运行 'docker-compose up -d',启动 docker compose 环境
-3. 运行 `mysql -h127.0.0.1 -P13308 -proot -uroot` 登录代理
+3. 运行 `psql -d sharding_db -h 127.0.0.1 -U root -p 3308 -W` 登录代理, 示例的默认密码:root
4. 如果有端口冲突,在docker-compose.yml中修改相应的端口,然后再次使用 'docker-compose up -d'启动docker compose
5. 如果需要关闭程序,请使用命令 'docker-compose down'
diff --git a/examples/docker/docker-compose.md b/examples/docker/docker-compose.md
index 56c79d37a96..ceda43fabff 100644
--- a/examples/docker/docker-compose.md
+++ b/examples/docker/docker-compose.md
@@ -14,7 +14,7 @@ before we use docker compose, please install docker and docker-compose first : h
1. access the docker folder (cd docker/shardingsphere-proxy/sharding)
2. launch the environment by docker compose (docker-compose up -d)
-3. access proxy by `mysql -h127.0.0.1 -P13308 -proot -uroot`
+3. access proxy by `psql -d sharding_db -h 127.0.0.1 -U root -p 3308 -W`, default password for example: root
4. if there is conflict on port, just modify the corresponding port defined in docker-compose.yml and then launch docker compose again(docker-compose up -d)
5. if you want to stop the environment, use command docker-compose down
diff --git a/examples/docker/shardingsphere-proxy/sharding/conf/config-sharding.yaml b/examples/docker/shardingsphere-proxy/sharding/conf/config-sharding.yaml
index fab3f676307..b6e53aea8a7 100644
--- a/examples/docker/shardingsphere-proxy/sharding/conf/config-sharding.yaml
+++ b/examples/docker/shardingsphere-proxy/sharding/conf/config-sharding.yaml
@@ -26,17 +26,17 @@ schemaName: sharding_db
dataSources:
ds_0:
- url: jdbc:mysql://shardingsphere-example-mysql:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
- username: root
- password:
+ url: jdbc:postgresql://shardingsphere-example-postgres:5432/demo_ds_0?useUnicode=true&characterEncoding=utf-8&allowEncodingChanges=true
+ username: postgres
+ password: postgres
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
ds_1:
- url: jdbc:mysql://shardingsphere-example-mysql:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
- username: root
- password:
+ url: jdbc:postgresql://shardingsphere-example-postgres:5432/demo_ds_1?useUnicode=true&characterEncoding=utf-8&allowEncodingChanges=true
+ username: postgres
+ password: postgres
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
@@ -50,34 +50,45 @@ rules:
tableStrategy:
standard:
shardingColumn: order_id
- shardingAlgorithmName: t_order_inline
- keyGeneratorColumnName: 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
- keyGeneratorColumnName: order_item_id
+ shardingAlgorithmName: t-order-item-inline
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+
bindingTables:
- t_order,t_order_item
+
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
- shardingAlgorithmName: database_inline
+ shardingAlgorithmName: database-inline
+
defaultTableStrategy:
none:
shardingAlgorithms:
- database_inline:
+ database-inline:
type: INLINE
props:
algorithm-expression: ds_${user_id % 2}
- t_order_inline:
+ t-order-inline:
type: INLINE
props:
algorithm-expression: t_order_${order_id % 2}
- t_order_item_inline:
+ t-order-item-inline:
type: INLINE
props:
algorithm-expression: t_order_item_${order_id % 2}
+
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
\ No newline at end of file
diff --git a/examples/docker/shardingsphere-proxy/sharding/conf/server.yaml b/examples/docker/shardingsphere-proxy/sharding/conf/server.yaml
index aec87484462..3897c599ecd 100644
--- a/examples/docker/shardingsphere-proxy/sharding/conf/server.yaml
+++ b/examples/docker/shardingsphere-proxy/sharding/conf/server.yaml
@@ -41,4 +41,4 @@ props:
max-connections-size-per-query: 1
kernel-executor-size: 16 # Infinite by default.
proxy-frontend-flush-threshold: 128 # The default value is 128.
- sql-show: false
+ sql-show: true
diff --git a/examples/docker/shardingsphere-proxy/sharding/docker-compose.yml b/examples/docker/shardingsphere-proxy/sharding/docker-compose.yml
index 472e76ec2cb..bb0153ac4e1 100644
--- a/examples/docker/shardingsphere-proxy/sharding/docker-compose.yml
+++ b/examples/docker/shardingsphere-proxy/sharding/docker-compose.yml
@@ -17,40 +17,39 @@
version: '3'
services:
- mysql:
- ## for different MySQL version, you could get more at here : https://hub.docker.com/_/mysql?tab=tags
- image: "mysql:5.7"
- ## port binding to 3306, you could change to 13306:3306 or any other available port you want
+ postgres:
+ ## for different postgres version, you could get more at here : https://hub.docker.com/_/postgres?tab=tags
+ image: "postgres:latest"
+ ## port binding to 5432, you could change to 15432:5432 or any other available port you want
ports:
- - "3306:3306"
- container_name: shardingsphere-example-mysql
- ## launch MySQL without password
- ## you could access MySQL like `mysql -h127.0.0.1 -P3306 -uroot`
- ## if you insist to access MySQL with password, remove `MYSQL_ALLOW_EMPTY_PASSWORD=yes` and then use MYSQL_ROOT_PASSWORD argument
- # - MYSQL_ROOT_PASSWORD=root
+ - "5432:5432"
+ container_name: shardingsphere-example-postgres
+ ## you could access Postgres like `psql -d your_database_name -h 127.0.0.1 -U root -p 5432 -W`
environment:
- - MYSQL_ALLOW_EMPTY_PASSWORD=yes
- ## copy the manual_schema.sql to /docker-entrypoint-initdb.d/ . this will init the sql file when the MySQL in container start up
+ - TZ=Asia/Shanghai
+ - POSTGRES_USER=postgres
+ - POSTGRES_PASSWORD=postgres
+ ## copy the manual_schema.sql to /docker-entrypoint-initdb.d/ . this will init the sql file when the Postgres in container start up
volumes:
- ../../../src/resources/manual_schema.sql:/docker-entrypoint-initdb.d/manual_schema.sql
proxy:
- ## get more versions of proxy here : https://hub.docker.com/r/apache/sharding-proxy/tags
- image: "apache/sharding-proxy:4.1.1"
+ ## get more versions of proxy here : https://hub.docker.com/r/apache/shardingsphere-proxy/tags
+ image: "apache/shardingsphere-proxy:latest"
container_name: shardingsphere-example-proxy
depends_on:
- - mysql
- ## wait-for-it.sh will make proxy entry point wait until MySQL container 3306 port open
+ - postgres
+ ## wait-for-it.sh will make proxy entry point wait until Postgres container 5432 port open
entrypoint: >
- /bin/sh -c "/opt/wait-for-it.sh shardingsphere-example-mysql:3306 --timeout=20 --strict --
- && /opt/sharding-proxy/bin/start.sh 3308
- && tail -f /opt/sharding-proxy/logs/stdout.log"
+ /bin/sh -c "/opt/wait-for-it.sh shardingsphere-example-postgres:5432 --timeout=20 --strict --
+ && /opt/shardingsphere-proxy/bin/start.sh 3308
+ && tail -f /opt/shardingsphere-proxy/logs/stdout.log"
ports:
- "3308:3308"
links:
- - "mysql:mysql"
+ - "postgres:postgres"
volumes:
- - ./conf/:/opt/sharding-proxy/conf
+ - ./conf/:/opt/shardingsphere-proxy/conf
- ../../tools/wait-for-it.sh:/opt/wait-for-it.sh
environment:
- JVM_OPTS="-Djava.awt.headless=true"
diff --git a/examples/docker/tools/wait-for-it.sh b/examples/docker/tools/wait-for-it.sh
old mode 100644
new mode 100755
diff --git a/examples/src/resources/manual_schema.sql b/examples/src/resources/manual_schema.sql
index 41ecaf7a529..07e0441d28d 100644
--- a/examples/src/resources/manual_schema.sql
+++ b/examples/src/resources/manual_schema.sql
@@ -15,74 +15,53 @@
* limitations under the License.
*/
-DROP SCHEMA IF EXISTS demo_ds;
-DROP SCHEMA IF EXISTS demo_ds_0;
-DROP SCHEMA IF EXISTS demo_ds_1;
+DROP DATABASE IF EXISTS demo_ds;
+DROP DATABASE IF EXISTS demo_ds_0;
+DROP DATABASE IF EXISTS demo_ds_1;
-DROP SCHEMA IF EXISTS demo_write_ds;
-DROP SCHEMA IF EXISTS demo_read_ds_0;
-DROP SCHEMA IF EXISTS demo_read_ds_1;
+DROP DATABASE IF EXISTS demo_write_ds;
+DROP DATABASE IF EXISTS demo_read_ds_0;
+DROP DATABASE IF EXISTS demo_read_ds_1;
-DROP SCHEMA IF EXISTS demo_write_ds_0;
-DROP SCHEMA IF EXISTS demo_write_ds_0_read_0;
-DROP SCHEMA IF EXISTS demo_write_ds_0_read_1;
-DROP SCHEMA IF EXISTS demo_write_ds_1;
-DROP SCHEMA IF EXISTS demo_write_ds_1_read_0;
-DROP SCHEMA IF EXISTS demo_write_ds_1_read_1;
+DROP DATABASE IF EXISTS demo_write_ds_0;
+DROP DATABASE IF EXISTS demo_write_ds_0_read_0;
+DROP DATABASE IF EXISTS demo_write_ds_0_read_1;
+DROP DATABASE IF EXISTS demo_write_ds_1;
+DROP DATABASE IF EXISTS demo_write_ds_1_read_0;
+DROP DATABASE IF EXISTS demo_write_ds_1_read_1;
-DROP SCHEMA IF EXISTS shadow_demo_ds;
-DROP SCHEMA IF EXISTS shadow_demo_ds_0;
-DROP SCHEMA IF EXISTS shadow_demo_ds_1;
+DROP DATABASE IF EXISTS shadow_demo_ds;
+DROP DATABASE IF EXISTS shadow_demo_ds_0;
+DROP DATABASE IF EXISTS shadow_demo_ds_1;
-DROP SCHEMA IF EXISTS demo_shadow_write_ds;
-DROP SCHEMA IF EXISTS demo_shadow_read_ds;
-DROP SCHEMA IF EXISTS demo_read_ds;
+DROP DATABASE IF EXISTS demo_shadow_write_ds;
+DROP DATABASE IF EXISTS demo_shadow_read_ds;
+DROP DATABASE IF EXISTS demo_read_ds;
-CREATE SCHEMA IF NOT EXISTS demo_ds;
-CREATE SCHEMA IF NOT EXISTS demo_ds_0;
-CREATE SCHEMA IF NOT EXISTS demo_ds_1;
+CREATE DATABASE demo_ds;
+CREATE DATABASE demo_ds_0;
+CREATE DATABASE demo_ds_1;
-CREATE SCHEMA IF NOT EXISTS demo_write_ds;
-CREATE SCHEMA IF NOT EXISTS demo_read_ds_0;
-CREATE SCHEMA IF NOT EXISTS demo_read_ds_1;
+CREATE DATABASE demo_write_ds;
+CREATE DATABASE demo_read_ds_0;
+CREATE DATABASE demo_read_ds_1;
-CREATE SCHEMA IF NOT EXISTS demo_write_ds_0;
-CREATE SCHEMA IF NOT EXISTS demo_write_ds_0_read_0;
-CREATE SCHEMA IF NOT EXISTS demo_write_ds_0_read_1;
-CREATE SCHEMA IF NOT EXISTS demo_write_ds_1;
-CREATE SCHEMA IF NOT EXISTS demo_write_ds_1_read_0;
-CREATE SCHEMA IF NOT EXISTS demo_write_ds_1_read_1;
+CREATE DATABASE demo_write_ds_0;
+CREATE DATABASE demo_write_ds_0_read_0;
+CREATE DATABASE demo_write_ds_0_read_1;
+CREATE DATABASE demo_write_ds_1;
+CREATE DATABASE demo_write_ds_1_read_0;
+CREATE DATABASE demo_write_ds_1_read_1;
-CREATE SCHEMA IF NOT EXISTS shadow_demo_ds;
-CREATE SCHEMA IF NOT EXISTS shadow_demo_ds_0;
-CREATE SCHEMA IF NOT EXISTS shadow_demo_ds_1;
+CREATE DATABASE shadow_demo_ds;
+CREATE DATABASE shadow_demo_ds_0;
+CREATE DATABASE shadow_demo_ds_1;
-CREATE SCHEMA IF NOT EXISTS demo_shadow_write_ds;
-CREATE SCHEMA IF NOT EXISTS demo_shadow_read_ds;
-CREATE SCHEMA IF NOT EXISTS demo_read_ds;
+CREATE DATABASE demo_shadow_write_ds;
+CREATE DATABASE demo_shadow_read_ds;
+CREATE DATABASE demo_read_ds;
--- Should sync from master-salve automatically
--- CREATE TABLE IF NOT EXISTS demo_read_ds_0.t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_read_ds_1.t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_read_ds_0.t_order_item (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
--- CREATE TABLE IF NOT EXISTS demo_read_ds_1.t_order_item (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_0_read_0.t_order_0 (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_0_read_0.t_order_1 (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_0_read_1.t_order_0 (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_0_read_1.t_order_1 (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_1_read_0.t_order_0 (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_1_read_0.t_order_1 (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_1_read_1.t_order_0 (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_1_read_1.t_order_1 (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_0_read_0.t_order_item_0 (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_0_read_0.t_order_item_1 (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_0_read_1.t_order_item_0 (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_0_read_1.t_order_item_1 (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_1_read_0.t_order_item_0 (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_1_read_0.t_order_item_1 (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_1_read_1.t_order_item_0 (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
--- CREATE TABLE IF NOT EXISTS demo_write_ds_1_read_1.t_order_item_1 (order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
-
--- CREATE TABLE IF NOT EXISTS demo_shadow_read_ds.t_user (user_id INT NOT NULL AUTO_INCREMENT, username VARCHAR(200), username_plain VARCHAR(200), pwd VARCHAR(200), assisted_query_pwd VARCHAR(200), PRIMARY KEY (user_id));
--- CREATE TABLE IF NOT EXISTS demo_read_ds.t_user (user_id INT NOT NULL AUTO_INCREMENT, username VARCHAR(200), username_plain VARCHAR(200), pwd VARCHAR(200), assisted_query_pwd VARCHAR(200), PRIMARY KEY (user_id));
+-- Execute SQL Script through logical-database connection , eg: sharding_db. Docker samples configuration in the 'conf/config-sharding.yaml' file
+-- CREATE TABLE t_order ("order_id" serial4, "user_id" int4 NOT NULL, PRIMARY KEY ("order_id"));
+-- CREATE TABLE t_order_item ("order_item_id" serial4, "order_id" int4 NOT NULL, "user_id" int4 NOT NULL, "status" varchar(50), PRIMARY KEY ("order_item_id"));