| <?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/common-config/builtin-algorithm/</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/common-config/builtin-algorithm/index.xml" rel="self" type="application/rss+xml" /> |
| <item> |
| <title>元数据持久化仓库</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/metadata-repository/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/metadata-repository/</guid> |
| <description>背景信息 Apache ShardingSphere 为不同的运行模式提供了不同的元数据持久化方式,用户在配置运行模式的同时可以选择合适的方式来存储元数据。 |
| 参数解释 数据库持久化 provider 的可选值为 H2,MySQL,EmbeddedDerby,DerbyNetworkServer,HSQLDB。 由于第三方的 Vulnerability Report 时常误报 H2 Database,避免在 ShardingSphere Standalone Mode 使用 H2 Database 可能是一种选择。 讨论 provider 不为默认值 H2 的情况。 |
| 若 provider 设置为 MySQL,则要求存在已就绪的 MySQL Server。classpath 应包含 com.mysql:mysql-connector-j:9.0.0 的 Maven 依赖。 若 provider 设置为 EmbeddedDerby,则 Derby 数据库引擎将在与应用程序相同的 JVM 内运行。 classpath 应包含 org.apache.derby:derby:10.17.1.0 和 org.apache.derby:derbytools:10.17.1.0 的 Maven 依赖, 且要求编译或运行下游项目的 JDK 版本大于或等于 JDK19。可能的配置如下。 mode: type: Standalone repository: type: JDBC props: provider: EmbeddedDerby jdbc_url: jdbc:derby:memory:config;create=true username: 若 provider 设置为 DerbyNetworkServer,则要求存在已就绪的 Derby Network Server。 Derby Network Server 不存在可用的 Docker Image,用户可能需要手动启动 Derby Network Server。 classpath 应包含 org.</description> |
| </item> |
| |
| <item> |
| <title>分片算法</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/sharding/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/sharding/</guid> |
| <description>背景信息 ShardingSphere 内置提供了多种分片算法,按照类型可以划分为自动分片算法、标准分片算法、复合分片算法和 Hint 分片算法,能够满足用户绝大多数业务场景的需要。此外,考虑到业务场景的复杂性,内置算法也提供了自定义分片算法的方式,用户可以通过编写 Java 代码来完成复杂的分片逻辑。 需要注意的是,自动分片算法的分片逻辑由 ShardingSphere 自动管理,需要通过配置 autoTables 分片规则进行使用。 |
| 参数解释 自动分片算法 取模分片算法 类型:MOD |
| 可配置属性: |
| 属性名称 数据类型 说明 sharding-count int 分片数量 哈希取模分片算法 类型:HASH_MOD |
| 可配置属性: |
| 属性名称 数据类型 说明 sharding-count int 分片数量 基于分片容量的范围分片算法 类型:VOLUME_RANGE |
| 可配置属性: |
| 属性名称 数据类型 说明 range-lower long 范围下界,超过边界的数据会报错 range-upper long 范围上界,超过边界的数据会报错 sharding-volume long 分片容量 基于分片边界的范围分片算法 类型:BOUNDARY_RANGE</description> |
| </item> |
| |
| <item> |
| <title>分布式序列算法</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/keygen/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/keygen/</guid> |
| <description>背景信息 传统数据库软件开发中,主键自动生成技术是基本需求。而各个数据库对于该需求也提供了相应的支持,比如 MySQL 的自增键,Oracle 的自增序列等。 数据分片后,不同数据节点生成全局唯一主键是非常棘手的问题。同一个逻辑表内的不同实际表之间的自增键由于无法互相感知而产生重复主键。 虽然可通过约束自增主键初始值和步长的方式避免碰撞,但需引入额外的运维规则,使解决方案缺乏完整性和可扩展性。 |
| 目前有许多第三方解决方案可以完美解决这个问题,如 UUID 等依靠特定算法自生成不重复键,或者通过引入主键生成服务等。为了方便用户使用、满足不同用户不同使用场景的需求, Apache ShardingSphere 不仅提供了内置的分布式主键生成器,例如 UUID、SNOWFLAKE,还抽离出分布式主键生成器的接口,方便用户自行实现自定义的自增主键生成器。 |
| 参数解释 雪花算法 类型:SNOWFLAKE |
| 可配置属性: |
| 属性名称 数据类型 说明 默认值 worker-id (?) long 工作机器唯一标识 0 max-vibration-offset (?) int 最大抖动上限值,范围[0, 4096)。注:若使用此算法生成值作分片值,建议配置此属性。此算法在不同毫秒内所生成的 key 取模 2^n (2^n一般为分库或分表数) 之后结果总为 0 或 1。为防止上述分片问题,建议将此属性值配置为 (2^n)-1 1 max-tolerate-time-difference-milliseconds (?) long 最大容忍时钟回退时间,单位:毫秒 10 毫秒 注意:worker-id 为选配项 |
| 在单机模式下支持用户自定义配置,如果用户不配置使用默认值为0。 在集群模式下会由系统自动生成,相同的命名空间下不会生成重复的值。 UUID 类型:UUID</description> |
| </item> |
| |
| <item> |
| <title>负载均衡算法</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/load-balance/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/load-balance/</guid> |
| <description>背景信息 ShardingSphere 内置提供了多种负载均衡算法,具体包括了轮询算法、随机访问算法和权重访问算法,能够满足用户绝大多数业务场景的需要。此外,考虑到业务场景的复杂性,内置算法也提供了扩展方式,用户可以基于 SPI 接口实现符合自己业务需要的负载均衡算法。 |
| 参数解释 轮询负载均衡算法 类型:ROUND_ROBIN |
| 随机负载均衡算法 类型:RANDOM |
| 权重负载均衡算法 类型:WEIGHT |
| 可配置属性: |
| 属性名称 数据类型 说明 ${replica-name} double 属性名使用读库名称,参数填写读库对应的权重值。权重参数范围最小值 &gt; 0,合计 &lt;= Double.MAX_VALUE。 操作步骤 使用读写分离时,在 loadBalancers 属性下配置对应的负载均衡算法即可; 配置示例 rules: - !READWRITE_SPLITTING dataSourceGroups: readwrite_ds: writeDataSourceName: write_ds readDataSourceNames: - read_ds_0 - read_ds_1 loadBalancerName: random transactionalReadQueryStrategy: PRIMARY loadBalancers: random: type: RANDOM props: 相关参考 核心特性:读写分离 开发者指南:读写分离 </description> |
| </item> |
| |
| <item> |
| <title>加密算法</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/encrypt/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/encrypt/</guid> |
| <description>背景信息 加密算法是 Apache ShardingSphere 的加密功能使用的算法,ShardingSphere 内置了多种算法,可以让用户方便使用。 |
| 参数解释 标准加密算法 AES 加密算法 类型:AES |
| 可配置属性: |
| 名称 数据类型 说明 aes-key-value String AES 使用的 KEY digest-algorithm-name String AES KEY 的摘要算法 辅助查询加密算法 MD5 辅助查询加密算法 类型:MD5 |
| 可配置属性: |
| 名称 数据类型 说明 salt String 盐值(可选) 操作步骤 在加密规则中配置加密器 为加密器指定加密算法类型 配置示例 rules: - !ENCRYPT tables: t_user: columns: username: cipher: name: username encryptorName: name_encryptor assistedQuery: name: assisted_username encryptorName: assisted_encryptor encryptors: name_encryptor: type: AES props: aes-key-value: 123456abc digest-algorithm-name: SHA-1 assisted_encryptor: type: MD5 props: salt: 123456 相关参考 核心特性:数据加密 开发者指南:数据加密 </description> |
| </item> |
| |
| <item> |
| <title>影子算法</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/shadow/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/shadow/</guid> |
| <description>背景信息 影子库功能对执行的 SQL 语句进行影子判定。影子判定支持两种类型算法,用户可根据实际业务需求选择一种或者组合使用。 |
| 参数解释 列影子算法 列值匹配算法 类型:VALUE_MATCH |
| 属性名称 数据类型 说明 column String 影子列 operation String SQL 操作类型(INSERT, UPDATE, DELETE, SELECT) value String 影子列匹配的值 列正则表达式匹配算法 类型:REGEX_MATCH |
| 属性名称 数据类型 说明 column String 匹配列 operation String SQL 操作类型(INSERT, UPDATE, DELETE, SELECT) regex String 影子列匹配正则表达式 Hint 影子算法 SQL HINT 影子算法 类型:SQL_HINT</description> |
| </item> |
| |
| <item> |
| <title>SQL 翻译</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/sql-translator/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/sql-translator/</guid> |
| <description>原生 SQL 翻译器 类型:NATIVE |
| 可配置属性: |
| 无 |
| 默认使用的 SQL 翻译器,但目前暂未实现</description> |
| </item> |
| |
| <item> |
| <title>分片审计算法</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/audit/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/audit/</guid> |
| <description>背景信息 分片审计功能是针对数据库分片场景下对执行的 SQL 语句进行审计操作。分片审计既可以进行拦截操作,拦截系统配置的非法 SQL 语句,也可以是对 SQL 语句进行统计操作。 |
| 参数解释 DML_SHARDING_CONDITIONS 算法 类型:DML_SHARDING_CONDITIONS |
| 操作步骤 配置数据分片规则时设置分配审计生成策略 配置示例 DML_SHARDING_CONDITIONS auditors: sharding_key_required_auditor: type: DML_SHARDING_CONDITIONS </description> |
| </item> |
| |
| <item> |
| <title>脱敏算法</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/mask/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/mask/</guid> |
| <description>背景信息 脱敏算法是 Apache ShardingSphere 的脱敏功能使用的算法,ShardingSphere 内置了多种算法,可以让用户方便使用。 |
| 参数解释 哈希脱敏算法 MD5 脱敏算法 类型:MD5 |
| 可配置属性: |
| 名称 数据类型 说明 salt String 盐值(可选) 遮盖脱敏算法 保留前 N 后 M 脱敏算法 类型:KEEP_FIRST_N_LAST_M |
| 可配置属性: |
| 名称 数据类型 说明 first-n int 前 n 位 last-m int 后 n 位 replace-char String 替换字符 保留自 X 至 Y 脱敏算法 类型:KEEP_FROM_X_TO_Y</description> |
| </item> |
| |
| <item> |
| <title>行表达式</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/expr/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/expr/</guid> |
| <description>使用 Groovy 语法的行表达式 在配置中使用 ${ expression } 或 $-&gt;{ expression } 标识 Groovy 表达式即可。 Groovy 表达式使用的是 Groovy 的语法,Groovy 能够支持的所有操作,行表达式均能够支持。 ${begin..end} 表示范围区间; ${[unit1, unit2, unit_x]} 表示枚举值。 行表达式中如果出现连续多个 ${ expression } 或 $-&gt;{ expression } 表达式,整个表达式最终的结果将会根据每个子表达式的结果进行笛卡尔组合。 |
| 类型:GROOVY |
| 用例: |
| &lt;GROOVY&gt;t_order_${1..3} 将被转化为 t_order_1, t_order_2, t_order_3 &lt;GROOVY&gt;${['online', 'offline']}_table${1..3} 将被转化为 online_table1, online_table2, online_table3, offline_table1, offline_table2, offline_table3 使用标准列表的行表达式 LITERAL 实现将不对表达式部分做任何符号的转化,从标准列表的输入直接获得标准列表的输出。此有助于解决 GraalVM Native Image 下不便于使用 Groovy 表达式的问题。 |
| 类型:LITERAL |
| 用例: |
| &lt;LITERAL&gt;t_order_1, t_order_2, t_order_3 将被转化为 t_order_1, t_order_2, t_order_3 &lt;LITERAL&gt;t_order_${1.</description> |
| </item> |
| |
| </channel> |
| </rss> |