Skip to content

Commit ad2cc69

Browse files
committed
Add documentation for P6Spy support
1 parent 2c9996e commit ad2cc69

File tree

16 files changed

+465
-134
lines changed

16 files changed

+465
-134
lines changed

docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ java.beans.Introspector was unintentionally initialized at build time. To see wh
4747
<plugin>
4848
<groupId>org.graalvm.buildtools</groupId>
4949
<artifactId>native-maven-plugin</artifactId>
50-
<version>0.10.3</version>
50+
<version>0.10.4</version>
5151
<extensions>true</extensions>
5252
<configuration>
5353
<buildArgs>
@@ -85,12 +85,12 @@ java.beans.Introspector was unintentionally initialized at build time. To see wh
8585

8686
```groovy
8787
plugins {
88-
id 'org.graalvm.buildtools.native' version '0.10.3'
88+
id 'org.graalvm.buildtools.native' version '0.10.4'
8989
}
9090
9191
dependencies {
9292
implementation 'org.apache.shardingsphere:shardingsphere-jdbc:${shardingsphere.version}'
93-
implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.3', classifier: 'repository', ext: 'zip')
93+
implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.4', classifier: 'repository', ext: 'zip')
9494
}
9595
9696
graalvmNative {

docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ and the documentation of GraalVM Native Build Tools shall prevail.
4949
<plugin>
5050
<groupId>org.graalvm.buildtools</groupId>
5151
<artifactId>native-maven-plugin</artifactId>
52-
<version>0.10.3</version>
52+
<version>0.10.4</version>
5353
<extensions>true</extensions>
5454
<configuration>
5555
<buildArgs>
@@ -89,12 +89,12 @@ Reference https://github.com/graalvm/native-build-tools/issues/572 .
8989

9090
```groovy
9191
plugins {
92-
id 'org.graalvm.buildtools.native' version '0.10.3'
92+
id 'org.graalvm.buildtools.native' version '0.10.4'
9393
}
9494
9595
dependencies {
9696
implementation 'org.apache.shardingsphere:shardingsphere-jdbc:${shardingsphere.version}'
97-
implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.3', classifier: 'repository', ext: 'zip')
97+
implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.4', classifier: 'repository', ext: 'zip')
9898
}
9999
100100
graalvmNative {

docs/document/content/user-manual/shardingsphere-jdbc/unsupported.cn.md renamed to docs/document/content/user-manual/shardingsphere-jdbc/unsupported/_index.cn.md

File renamed without changes.

docs/document/content/user-manual/shardingsphere-jdbc/unsupported.en.md renamed to docs/document/content/user-manual/shardingsphere-jdbc/unsupported/_index.en.md

File renamed without changes.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
+++
2+
title = "P6Spy"
3+
weight = 6
4+
+++
5+
6+
## 背景信息
7+
8+
ShardingSphere 通过 `org.apache.shardingsphere:shardingsphere-infra-database-p6spy` 模块,
9+
`com.p6spy.engine.spy.P6SpyDriver` 提供部分支持。
10+
11+
## 前提条件
12+
13+
要在 ShardingSphere 的配置文件为 MySQL Server 数据节点使用 P6Spy, 可能的 Maven 依赖关系如下,
14+
15+
```xml
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.apache.shardingsphere</groupId>
19+
<artifactId>shardingsphere-jdbc</artifactId>
20+
<version>${shardingsphere.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>p6spy</groupId>
24+
<artifactId>p6spy</artifactId>
25+
<version>3.9.1</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.mysql</groupId>
29+
<artifactId>mysql-connector-j</artifactId>
30+
<version>9.1.0</version>
31+
</dependency>
32+
</dependencies>
33+
```
34+
35+
## 配置示例
36+
37+
### 启动 MySQL Server
38+
39+
编写 Docker Compose 文件来启动 MySQL Server。
40+
41+
```yaml
42+
services:
43+
mysql:
44+
image: mysql:9.1.0
45+
environment:
46+
MYSQL_ROOT_PASSWORD: example
47+
volumes:
48+
- ./mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
49+
ports:
50+
- "3306:3306"
51+
```
52+
53+
`./docker-entrypoint-initdb.d` 文件夹包含文件为 `init.sh`,内容如下,
54+
55+
```shell
56+
#!/bin/bash
57+
set -e
58+
59+
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" <<EOSQL
60+
CREATE DATABASE demo_ds_0;
61+
CREATE DATABASE demo_ds_1;
62+
CREATE DATABASE demo_ds_2;
63+
EOSQL
64+
65+
for i in "demo_ds_0" "demo_ds_1" "demo_ds_2"
66+
do
67+
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" "$i" <<'EOSQL'
68+
CREATE TABLE IF NOT EXISTS t_order (
69+
order_id BIGINT NOT NULL AUTO_INCREMENT,
70+
order_type INT(11),
71+
user_id INT NOT NULL,
72+
address_id BIGINT NOT NULL,
73+
status VARCHAR(50),
74+
PRIMARY KEY (order_id)
75+
);
76+
EOSQL
77+
done
78+
```
79+
80+
### 在业务项目创建 ShardingSphere 数据源
81+
82+
在业务项目引入前提条件涉及的依赖后,在业务项目的 classpath 上编写 ShardingSphere 数据源的配置文件`demo.yaml`,
83+
84+
```yaml
85+
dataSources:
86+
ds_0:
87+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
88+
driverClassName: com.mysql.cj.jdbc.Driver
89+
jdbcUrl: jdbc:p6spy:mysql://localhost:3306/demo_ds_0?sslMode=REQUIRED
90+
username: root
91+
password: example
92+
ds_1:
93+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
94+
driverClassName: com.mysql.cj.jdbc.Driver
95+
jdbcUrl: jdbc:p6spy:mysql://localhost:3306/demo_ds_1?sslMode=REQUIRED
96+
username: root
97+
password: example
98+
ds_2:
99+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
100+
driverClassName: com.mysql.cj.jdbc.Driver
101+
jdbcUrl: jdbc:p6spy:mysql://localhost:3306/demo_ds_2?sslMode=REQUIRED
102+
username: root
103+
password: example
104+
rules:
105+
- !SHARDING
106+
tables:
107+
t_order:
108+
actualDataNodes:
109+
keyGenerateStrategy:
110+
column: order_id
111+
keyGeneratorName: snowflake
112+
defaultDatabaseStrategy:
113+
standard:
114+
shardingColumn: user_id
115+
shardingAlgorithmName: inline
116+
shardingAlgorithms:
117+
inline:
118+
type: INLINE
119+
props:
120+
algorithm-expression: ds_${user_id % 2}
121+
keyGenerators:
122+
snowflake:
123+
type: SNOWFLAKE
124+
```
125+
126+
### 享受集成
127+
128+
创建 ShardingSphere 的数据源以享受集成,
129+
130+
```java
131+
import com.zaxxer.hikari.HikariConfig;
132+
import com.zaxxer.hikari.HikariDataSource;
133+
import java.sql.Connection;
134+
import java.sql.SQLException;
135+
import java.sql.Statement;
136+
public class ExampleUtils {
137+
void test() throws SQLException {
138+
HikariConfig config = new HikariConfig();
139+
config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml");
140+
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
141+
try (HikariDataSource dataSource = new HikariDataSource(config);
142+
Connection connection = dataSource.getConnection();
143+
Statement statement = connection.createStatement()) {
144+
statement.execute("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (1, 1, 1, 'INSERT_TEST')");
145+
statement.executeQuery("SELECT * FROM t_order");
146+
statement.execute("alter table t_order delete where order_id=1");
147+
}
148+
}
149+
}
150+
```
151+
152+
## 使用限制
153+
154+
目前仅支持为 MySQL JDBC Driver 配置 P6Spy。
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
+++
2+
title = "P6Spy"
3+
weight = 6
4+
+++
5+
6+
## Background Information
7+
8+
ShardingSphere provides partial support for `com.p6spy.engine.spy.P6SpyDriver` through the
9+
`org.apache.shardingsphere:shardingsphere-infra-database-p6spy` module.
10+
11+
## Prerequisites
12+
13+
To use P6Spy for MySQL Server data nodes in ShardingSphere's configuration file,
14+
the possible Maven dependencies are as follows,
15+
16+
```xml
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.apache.shardingsphere</groupId>
20+
<artifactId>shardingsphere-jdbc</artifactId>
21+
<version>${shardingsphere.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>p6spy</groupId>
25+
<artifactId>p6spy</artifactId>
26+
<version>3.9.1</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.mysql</groupId>
30+
<artifactId>mysql-connector-j</artifactId>
31+
<version>9.1.0</version>
32+
</dependency>
33+
</dependencies>
34+
```
35+
36+
## Configuration Example
37+
38+
### Start MySQL Server
39+
40+
Write a Docker Compose file to start MySQL Server.
41+
42+
```yaml
43+
services:
44+
mysql:
45+
image: mysql:9.1.0
46+
environment:
47+
MYSQL_ROOT_PASSWORD: example
48+
volumes:
49+
- ./mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
50+
ports:
51+
- "3306:3306"
52+
```
53+
54+
The `./docker-entrypoint-initdb.d` folder contains the file `init.sh`, the content is as follows,
55+
56+
```shell
57+
#!/bin/bash
58+
set -e
59+
60+
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" <<EOSQL
61+
CREATE DATABASE demo_ds_0;
62+
CREATE DATABASE demo_ds_1;
63+
CREATE DATABASE demo_ds_2;
64+
EOSQL
65+
66+
for i in "demo_ds_0" "demo_ds_1" "demo_ds_2"
67+
do
68+
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" "$i" <<'EOSQL'
69+
CREATE TABLE IF NOT EXISTS t_order (
70+
order_id BIGINT NOT NULL AUTO_INCREMENT,
71+
order_type INT(11),
72+
user_id INT NOT NULL,
73+
address_id BIGINT NOT NULL,
74+
status VARCHAR(50),
75+
PRIMARY KEY (order_id)
76+
);
77+
EOSQL
78+
done
79+
```
80+
81+
### Create ShardingSphere data source in business project
82+
83+
After the business project introduces the dependencies involved in the prerequisites,
84+
write the ShardingSphere data source configuration file `demo.yaml` on the classpath of the business project.
85+
86+
```yaml
87+
dataSources:
88+
ds_0:
89+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
90+
driverClassName: com.mysql.cj.jdbc.Driver
91+
jdbcUrl: jdbc:p6spy:mysql://localhost:3306/demo_ds_0?sslMode=REQUIRED
92+
username: root
93+
password: example
94+
ds_1:
95+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
96+
driverClassName: com.mysql.cj.jdbc.Driver
97+
jdbcUrl: jdbc:p6spy:mysql://localhost:3306/demo_ds_1?sslMode=REQUIRED
98+
username: root
99+
password: example
100+
ds_2:
101+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
102+
driverClassName: com.mysql.cj.jdbc.Driver
103+
jdbcUrl: jdbc:p6spy:mysql://localhost:3306/demo_ds_2?sslMode=REQUIRED
104+
username: root
105+
password: example
106+
rules:
107+
- !SHARDING
108+
tables:
109+
t_order:
110+
actualDataNodes:
111+
keyGenerateStrategy:
112+
column: order_id
113+
keyGeneratorName: snowflake
114+
defaultDatabaseStrategy:
115+
standard:
116+
shardingColumn: user_id
117+
shardingAlgorithmName: inline
118+
shardingAlgorithms:
119+
inline:
120+
type: INLINE
121+
props:
122+
algorithm-expression: ds_${user_id % 2}
123+
keyGenerators:
124+
snowflake:
125+
type: SNOWFLAKE
126+
```
127+
128+
### Enjoy integration
129+
130+
Create a ShardingSphere data source to enjoy integration,
131+
132+
```java
133+
import com.zaxxer.hikari.HikariConfig;
134+
import com.zaxxer.hikari.HikariDataSource;
135+
import java.sql.Connection;
136+
import java.sql.SQLException;
137+
import java.sql.Statement;
138+
public class ExampleUtils {
139+
void test() throws SQLException {
140+
HikariConfig config = new HikariConfig();
141+
config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml");
142+
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
143+
try (HikariDataSource dataSource = new HikariDataSource(config);
144+
Connection connection = dataSource.getConnection();
145+
Statement statement = connection.createStatement()) {
146+
statement.execute("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (1, 1, 1, 'INSERT_TEST')");
147+
statement.executeQuery("SELECT * FROM t_order");
148+
statement.execute("alter table t_order delete where order_id=1");
149+
}
150+
}
151+
}
152+
```
153+
154+
## Usage Limitations
155+
156+
Currently only supports configuring P6Spy for MySQL JDBC Driver.

0 commit comments

Comments
 (0)