Provides plugins for ShardingSphere pluggable architecture.

Clone this repo:
  1. e3afa95 Merge pull request #45 from strongduanmu/dev-0428 by zhaojinchao · 11 days ago main
  2. b8b1381 fix encrypt algorithm build error by duanzhengqiang · 11 days ago
  3. 30a6e62 Merge pull request #44 from TherChenYang/refactor by Zhengqiang Duan · 3 weeks ago
  4. d201ad9 Use AlgorithmInitializationException Replace ShardingPluginException by LotusMoon · 3 weeks ago
  5. 1d4a72e Merge pull request #41 from strongduanmu/dev-0327 by ZhangCheng · 6 weeks ago

Table of Contents

Overview

ShardingSphere plugin is designed to provide a plugin implementation for ShardingSphere pluggable architecture. You can refer to ShardingSphere Dev Manual to extend the SPI. Developers are welcome to contribute to the implementation of plugins and build a distributed database ecosystem of ShardingSphere.

EN doc CN doc

Instruction

These plugins can be found in ShardingSphere plugin repository. Plugins in ShardingSphere plugin repository would remain the same release plan with ShardingSphere. When using ShardingSphere-JDBC, users only need to add maven dependencies to the project to complete the plugin installation. When using ShardingSphere-Proxy, they need to download the plugin jar package and the jar packages that the plugin may depend on, and then copy them to ShardingSphere-Proxy ext-lib directory.

When developers contribute new plugins, they need to refer to Contributor Guide and first execute ./mvnw clean install -DskipITs -DskipTests -Prelease to package ShardingSphere basic SPI and test components, and then create a new module for plugin development. Newly developed plugin code needs to follow ShardingSphere Code of Conduct.

Plugin Implementation

Feature Plugin

Encrypt Feature Plugin

Like Encrypt Algorithm

  • CharDigestLike Encrypt Algorithm

Type:CHAR_DIGEST_LIKE

Attributes:

NameDataTypeDescription
deltaintCharacter Unicode offset(decimal number)
maskintCharacter encryption mask(decimal number)
startintCiphertext Unicode initial code(decimal number)
dictStringCommon words

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-features-encrypt-like</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>

Standard Encrypt Algorithm

  • RC4 Encrypt Algorithm

Type: RC4

Attributes:

NameDataTypeDescription
rc4-key-valueStringRC4 KEY

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-features-encrypt-rc4</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>
  • SM3 Encrypt Algorithm

Type: SM3

Attributes:

NameDataTypeDescription
sm3-saltStringSM3 SALT (should be blank or 8 bytes long)

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-features-encrypt-sm</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>
  • SM4 Encrypt Algorithm

Type: SM4

Attributes:

NameDataTypeDescription
sm4-keyStringSM4 KEY (should be 16 bytes)
sm4-modeStringSM4 MODE (should be CBC or ECB)
sm4-ivStringSM4 IV (should be specified on CBC, 16 bytes long)
sm4-paddingStringSM4 PADDING (should be PKCS5Padding or PKCS7Padding, NoPadding excepted)

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-features-encrypt-sm</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>

Sharding Feature Plugin

Sharding Algorithm

  • Fixed interval sharding algorithm provided by CosId

A fixed time range sharding algorithm implemented by the tool class based on me.ahoo.cosid:cosid-core. When the sharding key is a JSR-310 containing class or a time-related class, it will be converted to java.time.LocalDateTime before the next sharding. See the discussion at https://github.com/apache/shardingsphere/issues/14047.

Type:COSID_INTERVAL

Attributes:

NameDataTypeDescriptionDefault Value
zone-idStringTime zone, which must follow the contained value of java.time.ZoneId. For example: Asia/Shanghai
logic-name-prefixStringPrefix pattern of sharding data sources or tables
datetime-lowerStringDatetime sharding lower boundary, pattern is consistent with the timestamp format of yyyy-MM-dd HH:mm:ss
datetime-upperStringDatetime sharding upper boundary, pattern is consistent with the timestamp format of yyyy-MM-dd HH:mm:ss
sharding-suffix-patternStringSuffix pattern of sharding data sources or tables, must can be transformed to Java LocalDateTime, must be consistent with datetime-interval-unit. For example: yyyyMM
datetime-interval-unitStringUnit of sharding value interval, must can be transformed to Java ChronoUnit's Enum value. For example: MONTHS
datetime-interval-amountintInterval of sharding value, after which the next shard will be entered

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-features-sharding-cosid</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>
  • Snowflake key-based fixed interval sharding algorithm provided by CosId

Snowflake ID sharding algorithm with fixed time range implemented by tool class based on me.ahoo.cosid:cosid-core. When the sharding key is a JSR-310 containing class or a time-related class, it will be converted to java.time.LocalDateTime before the next sharding. See the discussion at https://github.com/apache/shardingsphere/issues/14047.

Type:COSID_INTERVAL_SNOWFLAKE

Attributes:

NameDataTypeDescriptionDefault Value
zone-idStringTime zone, which must follow the contained value of java.time.ZoneId. For example: Asia/Shanghai
logic-name-prefixStringPrefix pattern of sharding data sources or tables
datetime-lowerStringDatetime sharding lower boundary, pattern is consistent with the timestamp format of yyyy-MM-dd HH:mm:ss
datetime-upperStringDatetime sharding upper boundary, pattern is consistent with the timestamp format of yyyy-MM-dd HH:mm:ss
sharding-suffix-patternStringSuffix pattern of sharding data sources or tables, must can be transformed to Java LocalDateTime, must be consistent with datetime-interval-unit. For example: yyyyMM
datetime-interval-unitStringUnit of sharding value interval, must can be transformed to Java ChronoUnit's Enum value. For example: MONTHS
datetime-interval-amountintInterval of sharding value, after which the next shard will be entered

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-features-sharding-cosid</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>
  • Modulo sharding algorithm provided by CosId

Modulo sharding algorithm implemented by the tool class based on me.ahoo.cosid:cosid-core. See the discussion at https://github.com/apache/shardingsphere/issues/14047 .

Type: COSID_MOD

Attributes:

NameDataTypeDescription
modintSharding count
logic-name-prefixStringPrefix pattern of sharding data sources or tables

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-features-sharding-cosid</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>

Infra Plugin

Infra Algorithm Plugin

Distributed Key Generator

  • Nano ID

Type:NANOID

Configurable Property:none

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-infra-algorithm-key-generator-nanoid</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>
  • CosId

Type: COSID

Attributes:

NameDataTypeDescriptionDefault Value
id-nameStringID generator name__share__
as-stringboolWhether to generate a string type ID: Convert long type ID to Base-62 String type (Long.MAX_VALUE maximum string length is 11 digits), and ensure the ordering of string IDsfalse

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-infra-algorithm-key-generator-cosid</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>
  • CosId-Snowflake

Type: COSID_SNOWFLAKE

Attributes:

NameDataTypeDescriptionDefault Value
epochStringEPOCH of Snowflake ID Algorithm1477929600000
as-stringboolWhether to generate a string type ID: Convert long type ID to Base-62 String type (Long.MAX_VALUE maximum string length is 11 digits), and ensure the ordering of string IDsfalse

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-infra-algorithm-key-generator-cosid</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>

Message Digest Plugin

  • SM3

Type: SM3

Attributes:

NameDataTypeDescriptionDefault Value
sm3-saltStringSALT used by SM3 (null or 8 Bytes)empty string

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-infra-algorithm-message-digest-sm3</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>

Connection Pool Plugin

ShardingSphere-Proxy supports common data source connection pools: HikariCP, C3P0, DBCP.

The connection pool can be specified through the parameter dataSourceClassName. When not specified, the default data source connection pool is HikariCP.

  • C3P0 Connection Pool

Sample:

dataSources:
  ds_0:
    dataSourceClassName: com.mchange.v2.c3p0.ComboPooledDataSource
    url: jdbc:mysql://localhost:3306/ds_2
    username: root
    password:

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-infra-data-source-pool-c3p0</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>
  • DBCP Connection Pool

Sample:

dataSources:
  ds_0:
    dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource
    url: jdbc:mysql://localhost:3306/ds_3
    username: root
    password:

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-infra-data-source-pool-dbcp</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>

URL Loader Plugin

Shardingsphere-JDBC supports user-defined URL loader plugin, allowing users to load YAML configuration during the initial startup phase through custom methods. For example, YAML configuration information can be stored using relative paths, absolute paths, Apollo.

  • Apollo URL Loader

Type: Apollo

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-infra-url-apollo</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>

Using Apollo to store JDBC YAML configuration, as shown below:

# Declare the use of Apollo as the storage method for configuration in the ShardingSphere-JDBC driver URL, and specify the Apollo Namespace storing the YAML as `test_namespace`.
jdbc:shardingsphere:apollo:test_namespace

Kernel Plugin

SQL Translator Plugin

  • JooQ SQL translator

Type: JOOQ

Attributes:

None

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-kernel-sql-translator-jooq</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>

JDBC Adaptor Plugin

JDBC Driver Config Plugin

ShardingSphere-JDBC provides a JDBC Driver, which can be used only through configuration changes without rewriting the code.

  • Apollo Driver Config

Load JDBC URL of the yaml configuration file in the specified namespace of apollo:

jdbc:shardingsphere:apollo:TEST.test_namespace

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-jdbc-driver-apollo</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>

Mode Plugin

Mode Cluster Repository Plugin

  • Nacos Repository

Type: Nacos

Mode: Cluster

Attributes:

NameTypeDescriptionDefault Value
clusterIpStringUnique identifier in clusterHost IP
retryIntervalMillisecondslongMilliseconds of retry interval500
maxRetriesintMax retries for client to check data availability3
timeToLiveSecondsintSeconds of ephemeral instance live30

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-mode-cluster-repository-nacos</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>
  • Consul Repository

Due to the limitation of the Maven module of com.ecwid.consul:consul-api:1.4.5, users cannot connect to the Consul Agent through the gRPC port.

The serverLists property of the Consul implementation is by design and can only be connected to a single Consul Agent via an HTTP endpoint. serverLists uses relaxed URL matching principles.

  1. When serverLists is empty, it will be resolved to the Consul Agent instance of http://127.0.0.1:8500.
  2. When serverLists is hostName, it will be resolved to the Consul Agent instance of http://hostName:8500.
  3. When serverLists is hostName:port, it will be resolved to the Consul Agent instance of http://hostName:port.
  4. When serverLists is http://hostName:port, it will be resolved to the Consul Agent instance of http://hostName:port.
  5. When serverLists is https://hostName:port, it will be resolved to the Consul Agent instance of https://hostName:port.

Type: Consul

Mode: Cluster

Attributes:

NameTypeDescriptionDefault Value
timeToLiveSecondsStringSeconds of ephemeral instance live30s
blockQueryTimeToSecondslongSeconds of query timeout60

Maven dependency:

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-plugin-mode-cluster-repository-consul</artifactId>
    <version>${RELEASE.VERSION}</version>
</dependency>