document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/index.xml (126 lines of code) (raw):

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>规则配置 on ShardingSphere</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/</link> <description>Recent content in 规则配置 on ShardingSphere</description> <generator>Hugo -- gohugo.io</generator> <language>en-us</language><atom:link href="https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/index.xml" rel="self" type="application/rss+xml" /> <item> <title>数据分片</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sharding/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sharding/</guid> <description>背景信息 数据分片 YAML 配置方式具有非凡的可读性,通过 YAML 格式,能够快速地理解分片规则之间的依赖关系,ShardingSphere 会根据 YAML 配置,自动完成 ShardingSphereDataSource 对象的创建,减少用户不必要的编码工作。 参数解释 rules: - !SHARDING tables: # 数据分片规则配置 &amp;lt;logic_table_name&amp;gt; (+): # 逻辑表名称 actualDataNodes (?): # 由数据源名 + 表名组成(参考 Inline 语法规则) databaseStrategy (?): # 分库策略,缺省表示使用默认分库策略,以下的分片策略只能选其一 standard: # 用于单分片键的标准分片场景 shardingColumn: # 分片列名称 shardingAlgorithmName: # 分片算法名称 complex: # 用于多分片键的复合分片场景 shardingColumns: # 分片列名称,多个列以逗号分隔 shardingAlgorithmName: # 分片算法名称 hint: # Hint 分片策略 shardingAlgorithmName: # 分片算法名称 none: # 不分片 tableStrategy: # 分表策略,同分库策略 keyGenerateStrategy: # 分布式序列策略 column: # 自增列名称,缺省表示不使用自增主键生成器 keyGeneratorName: # 分布式序列算法名称 auditStrategy: # 分片审计策略 auditorNames: # 分片审计算法名称 - &amp;lt;auditor_name&amp;gt; - &amp;lt;auditor_name&amp;gt; allowHintDisable: true # 是否禁用分片审计hint autoTables: # 自动分片表规则配置 t_order_auto: # 逻辑表名称 actualDataSources (?</description> </item> <item> <title>广播表</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/broadcast/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/broadcast/</guid> <description>广播表 YAML 配置方式具有非凡的可读性,通过 YAML 格式,能够快速地理解广播表配置,ShardingSphere 会根据 YAML 配置,自动完成 ShardingSphereDataSource 对象的创建,减少用户不必要的编码工作。 参数解释 rules: - !BROADCAST tables: # 广播表规则列表 - &amp;lt;table_name&amp;gt; - &amp;lt;table_name&amp;gt; 操作步骤 在 YAML 文件中配置广播表列表 调用 YamlShardingSphereDataSourceFactory 对象的 createDataSource 方法,根据 YAML 文件中的配置信息创建 ShardingSphereDataSource。 配置示例 广播表 YAML 配置示例如下: dataSources: ds_0: dataSourceClassName: com.zaxxer.hikari.HikariDataSource driverClassName: com.mysql.jdbc.Driver jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&amp;amp;useSSL=false&amp;amp;useUnicode=true&amp;amp;characterEncoding=UTF-8 username: root password: ds_1: dataSourceClassName: com.zaxxer.hikari.HikariDataSource driverClassName: com.mysql.jdbc.Driver jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&amp;amp;useSSL=false&amp;amp;useUnicode=true&amp;amp;characterEncoding=UTF-8 username: root password: rules: - !BROADCAST tables: - t_address 通过 YamlShardingSphereDataSourceFactory 的 createDataSource 方法,读取 YAML 配置完成数据源的创建。</description> </item> <item> <title>读写分离</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting/</guid> <description>背景信息 读写分离 YAML 配置方式可读性高,通过 YAML 格式,能够快速地理解读写分片规则之间的依赖关系,ShardingSphere 会根据 YAML 配置,自动完成 ShardingSphereDataSource 对象的创建,减少用户不必要的编码工作。 参数解释 读写分离 rules: - !READWRITE_SPLITTING dataSourceGroups: &amp;lt;data_source_name&amp;gt; (+): # 读写分离逻辑数据源名称,默认使用 Groovy 的行表达式 SPI 实现来解析 write_data_source_name: # 写库数据源名称,默认使用 Groovy 的行表达式 SPI 实现来解析 read_data_source_names: # 读库数据源名称,多个从数据源用逗号分隔,默认使用 Groovy 的行表达式 SPI 实现来解析 transactionalReadQueryStrategy (?): # 事务内读请求的路由策略,可选值:PRIMARY(路由至主库)、FIXED(同一事务内路由至固定数据源)、DYNAMIC(同一事务内路由至非固定数据源)。默认值:DYNAMIC loadBalancerName: # 负载均衡算法名称 # 负载均衡算法配置 loadBalancers: &amp;lt;load_balancer_name&amp;gt; (+): # 负载均衡算法名称 type: # 负载均衡算法类型 props: # 负载均衡算法属性配置 # ... 算法类型的详情,请参见内置负载均衡算法列表。 操作步骤 添加读写分离数据源 设置负载均衡算法 使用读写分离数据源 配置示例 rules: - !</description> </item> <item> <title>分布式事务</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/transaction/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/transaction/</guid> <description>背景信息 ShardingSphere 提供了三种模式的分布式事务 LOCAL, XA, BASE。 参数解释 transaction: defaultType: # 事务模式,可选值 LOCAL/XA/BASE providerType: # 指定模式下的具体实现 操作步骤 使用 LOCAL 模式 global.yaml 配置文件内容如下: transaction: defaultType: LOCAL 使用 XA 模式 global.yaml 配置文件内容如下: transaction: defaultType: XA providerType: Narayana/Atomikos 手动添加 Narayana 相关依赖: jta-5.12.7.Final.jar arjuna-5.12.7.Final.jar common-5.12.7.Final.jar jboss-connector-api_1.7_spec-1.0.0.Final.jar jboss-logging-3.2.1.Final.jar jboss-transaction-api_1.2_spec-1.0.0.Alpha3.jar jboss-transaction-spi-7.6.1.Final.jar narayana-jts-integration-5.12.7.Final.jar shardingsphere-transaction-xa-narayana-x.x.x-SNAPSHOT.jar 使用 BASE 模式 global.yaml 配置文件内容如下: transaction: defaultType: BASE providerType: Seata 搭建 Seata Server,添加相关配置文件,和 Seata 依赖,具体步骤参考 ShardingSphere 集成 Seata 柔性事务</description> </item> <item> <title>数据加密</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/encrypt/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/encrypt/</guid> <description>背景信息 数据加密 YAML 配置方式具有非凡的可读性,通过 YAML 格式,能够快速地理解加密规则之间的依赖关系,ShardingSphere 会根据 YAML 配置,自动完成 ShardingSphereDataSource 对象的创建,减少用户不必要的编码工作。 参数解释 rules: - !ENCRYPT tables: &amp;lt;table_name&amp;gt; (+): # 加密表名称 columns: &amp;lt;column_name&amp;gt; (+): # 加密列名称 cipher: name: # 密文列名称 encryptorName: # 密文列加密算法名称 assistedQuery (?): name: # 查询辅助列名称 encryptorName: # 查询辅助列加密算法名称 likeQuery (?): name: # 模糊查询列名称 encryptorName: # 模糊查询列加密算法名称 # 加密算法配置 encryptors: &amp;lt;encrypt_algorithm_name&amp;gt; (+): # 加解密算法名称 type: # 加解密算法类型 props: # 加解密算法属性配置 # ... 算法类型的详情,请参见内置加密算法列表。 操作步骤 在 YAML 文件中配置数据加密规则,包含数据源、加密规则、全局属性等配置项; 调用 YamlShardingSphereDataSourceFactory 对象的 createDataSource 方法,根据 YAML 文件中的配置信息创建 ShardingSphereDataSource。 配置示例 数据加密 YAML 配置如下:</description> </item> <item> <title>数据脱敏</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/mask/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/mask/</guid> <description>背景信息 数据脱敏 YAML 配置方式良好的可读性,通过 YAML 格式,能够快速地理解脱敏规则之间的依赖关系,ShardingSphere 会根据 YAML 配置,自动完成 ShardingSphereDataSource 对象的创建,减少用户不必要的编码工作。 参数解释 rules: - !MASK tables: &amp;lt;table_name&amp;gt; (+): # 脱敏表名称 columns: &amp;lt;column_name&amp;gt; (+): # 脱敏列名称 maskAlgorithm: # 脱敏算法 # 脱敏算法配置 maskAlgorithms: &amp;lt;mask_algorithm_name&amp;gt; (+): # 脱敏算法名称 type: # 脱敏算法类型 props: # 脱敏算法属性配置 # ... 算法类型的详情,请参见内置脱敏算法列表。 操作步骤 在 YAML 文件中配置数据脱敏规则,包含数据源、脱敏规则、全局属性等配置项; 调用 YamlShardingSphereDataSourceFactory 对象的 createDataSource 方法,根据 YAML 文件中的配置信息创建 ShardingSphereDataSource。 配置示例 数据脱敏 YAML 配置如下: dataSources: unique_ds: dataSourceClassName: com.zaxxer.hikari.HikariDataSource driverClassName: com.mysql.jdbc.Driver jdbcUrl: jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&amp;amp;useSSL=false&amp;amp;useUnicode=true&amp;amp;characterEncoding=UTF-8 username: root password: rules: - !</description> </item> <item> <title>影子库</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/shadow/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/shadow/</guid> <description>背景信息 如果您想在 ShardingSphere-Proxy 中使用 ShardingSphere 影子库功能请参考以下配置。 参数解释 rules: - !SHADOW dataSources: shadowDataSource: productionDataSourceName: # 生产数据源名称 shadowDataSourceName: # 影子数据源名称 tables: &amp;lt;table_name&amp;gt;: dataSourceNames: # 影子表关联影子数据源名称列表 - &amp;lt;shadow_data_source&amp;gt; shadowAlgorithmNames: # 影子表关联影子算法名称列表 - &amp;lt;shadow_algorithm_name&amp;gt; defaultShadowAlgorithmName: # 默认影子算法名称(选配项) shadowAlgorithms: &amp;lt;shadow_algorithm_name&amp;gt; (+): # 影子算法名称 type: # 影子算法类型 props: # 影子算法属性配置 详情请参见内置影子算法列表 操作步骤 在 YAML 文件中配置影子库规则,包含数据源、影子库规则、全局属性等配置项; 调用 YamlShardingSphereDataSourceFactory 对象的 createDataSource 方法,根据 YAML 文件中的配置信息创建 ShardingSphereDataSource。 配置示例 dataSources: ds: url: jdbc:mysql://127.0.0.1:3306/ds?serverTimezone=UTC&amp;amp;useSSL=false username: root password: connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 50 minPoolSize: 1 shadow_ds: url: jdbc:mysql://127.</description> </item> <item> <title>SQL 解析</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sql-parser/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sql-parser/</guid> <description>背景信息 SQL 解析 YAML 配置方式具有可读性高,使用简单的特点。通过 YAML 文件的方式,用户可以将代码与配置分离,并且根据需要方便地修改配置文件。 参数解释 sqlParser: sqlStatementCache: # SQL 语句本地缓存配置项 initialCapacity: # 本地缓存初始容量 maximumSize: # 本地缓存最大容量 parseTreeCache: # 解析树本地缓存配置项 initialCapacity: # 本地缓存初始容量 maximumSize: # 本地缓存最大容量 操作步骤 设置本地缓存配置 设置解析配置 使用解析引擎解析 SQL 配置示例 sqlParser: sqlStatementCache: initialCapacity: 2000 maximumSize: 65535 parseTreeCache: initialCapacity: 128 maximumSize: 1024 相关参考 JAVA API:SQL 解析 </description> </item> <item> <title>SQL 翻译</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sql-translator/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sql-translator/</guid> <description>背景信息 SQL 翻译 YAML 配置方式具有可读性高,使用简单的特点。通过 YAML 文件的方式,用户可以将代码与配置分离,并且根据需要方便地修改配置文件。 参数解释 sqlTranslator: type: # SQL 翻译器类型 useOriginalSQLWhenTranslatingFailed: # SQL 翻译失败是否使用原始 SQL 继续执行 操作步骤 配置翻译类型 type 配置 useOriginalSQLWhenTranslatingFailed 参数,是否在 SQL 翻译失败后使用原始 SQL 继续执行 配置示例 sqlTranslator: type: Native useOriginalSQLWhenTranslatingFailed: true 相关参考 JAVA API:SQL 翻译 </description> </item> <item> <title>混合规则</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/mix/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/mix/</guid> <description>背景信息 ShardingSphere 涵盖了很多功能,例如,分库分片、读写分离、数据加密等。这些功能用户可以单独进行使用,也可以配合一起使用,下面是基于 YAML 的参数解释和配置示例。 参数解释 rules: - !SHARDING tables: &amp;lt;logic_table_name&amp;gt;: # 逻辑表名称: actualDataNodes: # 由逻辑数据源名 + 表名组成(参考 Inline 语法规则) tableStrategy: # 分表策略,同分库策略 standard: shardingColumn: # 分片列名称 shardingAlgorithmName: # 分片算法名称 keyGenerateStrategy: column: # 自增列名称,缺省表示不使用自增主键生成器 keyGeneratorName: # 分布式序列算法名称 defaultDatabaseStrategy: standard: shardingColumn: # 分片列名称 shardingAlgorithmName: # 分片算法名称 shardingAlgorithms: &amp;lt;sharding_algorithm_name&amp;gt;: # 分片算法名称 type: INLINE props: algorithm-expression: # INLINE 表达式 t_order_inline: type: INLINE props: algorithm-expression: # INLINE 表达式 keyGenerators: &amp;lt;key_generate_algorithm_name&amp;gt; (+): # 分布式序列算法名称 type: # 分布式序列算法类型 props: # 分布式序列算法属性配置 - !</description> </item> <item> <title>数据分片路由缓存</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sharding-cache/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sharding-cache/</guid> <description>背景信息 该项功能为实验性功能,需要与数据分片功能同时使用。 数据分片路由缓存会将逻辑 SQL、分片键实际参数值、路由结果放入缓存中,以空间换时间,减少路由逻辑对 CPU 的使用。 建议仅在满足以下条件的情况下启用: 纯 OLTP 场景 ShardingSphere 进程所在机器 CPU 已达到瓶颈 CPU 开销主要在于 ShardingSphere 路由逻辑 所有 SQL 已经最优且每次 SQL 执行都能命中单一分片 在不满足以上条件的情况下使用,可能对 SQL 的执行延时不会有明显改善,同时会增加内存的压力。 参数解释 rules: - !SHARDING tables: shardingAlgorithms: # ... shardingCache: allowedMaxSqlLength: 512 # 允许缓存的 SQL 长度限制 routeCache: initialCapacity: 65536 # 缓存初始容量 maximumSize: 262144 # 缓存最大容量 softValues: true # 是否软引用缓存值 相关参考 核心特性:数据分片 </description> </item> <item> <title>单表</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/single/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/single/</guid> <description>背景信息 单表规则用于指定哪些单表需要被 ShardingSphere 管理,也可设置默认的单表数据源。 参数解释 rules: - !SINGLE tables: # MySQL 风格 - ds_0.t_single # 加载指定单表 - ds_1.* # 加载指定数据源中的全部单表 - &amp;#34;*.*&amp;#34; # 加载全部单表 # PostgreSQL 风格 - ds_0.public.t_config - ds_1.public.* - ds_2.*.* - &amp;#34;*.*.*&amp;#34; defaultDataSource: ds_0 # 默认数据源,仅在执行 CREATE TABLE 创建单表时有效。缺失值为空,表示随机单播路由。 相关参考 单表 </description> </item> <item> <title>联邦查询</title> <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sql-federation/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sql-federation/</guid> <description>背景信息 该功能为实验性功能,暂不适合核心系统生产环境使用。 联邦查询 YAML 配置方式可读性高,当关联查询中的多个表分布在不同的数据库实例上时,通过开启联邦查询可以进行跨库关联查询,以及子查询。 参数解释 sqlFederation: sqlFederationEnabled: # 是否开启联邦查询 allQueryUseSQLFederation: # 是否全部查询 SQL 使用联邦查询 executionPlanCache: # 执行计划缓存 initialCapacity: 2000 # 执行计划缓存初始容量 maximumSize: 65535 # 执行计划缓存最大容量 配置示例 sqlFederation: sqlFederationEnabled: true allQueryUseSQLFederation: false executionPlanCache: initialCapacity: 2000 maximumSize: 65535 相关参考 JAVA API:联邦查询 </description> </item> </channel> </rss>