From eb59362dedc23d11eec21e726c2f253b3d7abb59 Mon Sep 17 00:00:00 2001 From: buter Date: Fri, 18 Jun 2021 10:46:14 +0800 Subject: [PATCH] sharding config --- zyzDOC/sharding/config-sharding.yaml | 167 +++++++++++++++++++++++++++ zyzDOC/sharding/readme.txt | 10 ++ zyzDOC/sharding/server.yaml | 61 ++++++++++ zyzDOC/sharding/sharding.yaml | 20 ++++ 4 files changed, 258 insertions(+) create mode 100644 zyzDOC/sharding/config-sharding.yaml create mode 100644 zyzDOC/sharding/readme.txt create mode 100644 zyzDOC/sharding/server.yaml create mode 100644 zyzDOC/sharding/sharding.yaml diff --git a/zyzDOC/sharding/config-sharding.yaml b/zyzDOC/sharding/config-sharding.yaml new file mode 100644 index 0000000..f5a64de --- /dev/null +++ b/zyzDOC/sharding/config-sharding.yaml @@ -0,0 +1,167 @@ +# +# 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://10.244.1.16:5000/demo_ds_0?serverTimezone=UTC&useSSL=false + username: postgres + password: postgres + connectionTimeoutMilliseconds: 30000 + idleTimeoutMilliseconds: 60000 + maxLifetimeMilliseconds: 1800000 + maxPoolSize: 50 + minPoolSize: 1 + maintenanceIntervalMilliseconds: 30000 + +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. +# +###################################################################################################### + +#schemaName: sharding_db +# +#dataSources: +# ds_0: +# url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false +# username: root +# password: +# connectionTimeoutMilliseconds: 30000 +# idleTimeoutMilliseconds: 60000 +# maxLifetimeMilliseconds: 1800000 +# maxPoolSize: 50 +# minPoolSize: 1 +# maintenanceIntervalMilliseconds: 30000 +# 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 +# maintenanceIntervalMilliseconds: 30000 +# +#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 diff --git a/zyzDOC/sharding/readme.txt b/zyzDOC/sharding/readme.txt new file mode 100644 index 0000000..29bcdf1 --- /dev/null +++ b/zyzDOC/sharding/readme.txt @@ -0,0 +1,10 @@ +sharding.yaml ---sharding的部署yaml文件 +server.yaml ---sharding的配置文件,非必需项 +config-sharding---sharding的配置文件,必选项 +前提条件: +已部署好openGauss主备+haproxy环境。sharding链接haproxy的相关配置在sharding.yaml 内完成。 + +server.yaml和config-sharding.yaml文件需要放到指定位置(sharding.yaml 内配置的默认地址是/etc/k8s)。注意这里指的位置是pod部署的机器上面。可以通过get pod查看pod在那台机器上面部署。 + +测试链接:在内网环境中,通过gsql链接测试。 +gsql -d sharding_db -p 3307 -r -h 10.244.2.200 -U root -W root \ No newline at end of file diff --git a/zyzDOC/sharding/server.yaml b/zyzDOC/sharding/server.yaml new file mode 100644 index 0000000..8500627 --- /dev/null +++ b/zyzDOC/sharding/server.yaml @@ -0,0 +1,61 @@ +# +# 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. +# + +###################################################################################################### +# +# If you want to configure governance, authorization and proxy properties, please refer to this file. +# +###################################################################################################### + +#governance: +# name: governance_ds +# registryCenter: +# type: ZooKeeper +# serverLists: localhost:2181 +# props: +# retryIntervalMilliseconds: 500 +# timeToLiveSeconds: 60 +# maxRetries: 3 +# operationTimeoutMilliseconds: 500 +# overwrite: false + +scaling: + blockQueueSize: 10000 + workerThread: 40 + +rules: + - !AUTHORITY + users: + - root@%:root + - sharding@:sharding + provider: + type: ALL_PRIVILEGES_PERMITTED + +props: + max-connections-size-per-query: 1 + executor-size: 16 # Infinite by default. + proxy-frontend-flush-threshold: 128 # The default value is 128. + # LOCAL: Proxy will run with LOCAL transaction. + # XA: Proxy will run with XA transaction. + # BASE: Proxy will run with B.A.S.E transaction. + proxy-transaction-type: LOCAL + xa-transaction-manager-type: Atomikos + proxy-opentracing-enabled: false + proxy-hint-enabled: false + sql-show: false + check-table-metadata-enabled: false + lock-wait-timeout-milliseconds: 50000 # The maximum time to wait for a lock diff --git a/zyzDOC/sharding/sharding.yaml b/zyzDOC/sharding/sharding.yaml new file mode 100644 index 0000000..bd82422 --- /dev/null +++ b/zyzDOC/sharding/sharding.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Pod +metadata: + name: opengauss-sha +spec: + containers: + - name: opengauss-sha + image: shardingsphere + imagePullPolicy: Never + volumeMounts: + - name: sys-time + mountPath: /tmp/ + ports: + - containerPort: 5401 + name: opengauss + volumes: + - name: sys-time + hostPath: + path: /etc/k8s/ + type: Directory -- Gitee