This is an automated email from the ASF dual-hosted git repository. tanjian pushed a commit to branch tidb_provider in repository https://gitbox.apache.org/repos/asf/skywalking.git
commit 7187c7e54451547f24f82c4a555fb7b9db48765c Author: JaredTan95 <jian....@daocloud.io> AuthorDate: Sat Nov 14 20:37:25 2020 +0800 add tidb storage provider module. --- docs/en/setup/backend/backend-storage.md | 15 +- oap-server/server-bootstrap/pom.xml | 5 + .../src/main/resources/application.yml | 13 ++ oap-server/server-storage-plugin/pom.xml | 1 + .../plugin/jdbc/mysql/MySQLStorageConfig.java | 2 +- .../plugin/jdbc/mysql/TiDBHistoryDeleteDAO.java | 56 ------- .../plugin/jdbc/mysql/TiDBStorageProvider.java | 25 --- ...alking.oap.server.library.module.ModuleProvider | 3 +- .../storage-tidb-plugin/pom.xml | 41 +++++ .../plugin/jdbc/tidb/TiDBHistoryDeleteDAO.java | 76 +++++++++ .../plugin/jdbc/tidb/TiDBStorageConfig.java} | 21 +-- .../plugin/jdbc/tidb/TiDBStorageProvider.java | 177 +++++++++++++++++++++ ...alking.oap.server.library.module.ModuleProvider | 4 +- 13 files changed, 328 insertions(+), 111 deletions(-) diff --git a/docs/en/setup/backend/backend-storage.md b/docs/en/setup/backend/backend-storage.md index a189afc..70297be 100644 --- a/docs/en/setup/backend/backend-storage.md +++ b/docs/en/setup/backend/backend-storage.md @@ -223,22 +223,25 @@ All connection related settings including link url, username and password are in Here are some of the settings, please follow [HikariCP](https://github.com/brettwooldridge/HikariCP) connection pool document for all the settings. ## TiDB -Currently tested TiDB in version 2.0.9, and Mysql Client driver in version 8.0.13. -Active TiDB as storage, set storage provider to **mysql**. +Tested TiDB Server 4.0.8 version and Mysql Client driver 8.0.13 version currently. +Active TiDB as storage, set storage provider to **tidb**. ```yaml storage: - selector: ${SW_STORAGE:mysql} - mysql: + selector: ${SW_STORAGE:tidb} + tidb: properties: - jdbcUrl: ${SW_JDBC_URL:"jdbc:mysql://localhost:3306/swtest"} + jdbcUrl: ${SW_JDBC_URL:"jdbc:mysql://localhost:4000/swtest"} dataSource.user: ${SW_DATA_SOURCE_USER:root} - dataSource.password: ${SW_DATA_SOURCE_PASSWORD:root@1234} + dataSource.password: ${SW_DATA_SOURCE_PASSWORD:""} dataSource.cachePrepStmts: ${SW_DATA_SOURCE_CACHE_PREP_STMTS:true} dataSource.prepStmtCacheSize: ${SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_SIZE:250} dataSource.prepStmtCacheSqlLimit: ${SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_LIMIT:2048} dataSource.useServerPrepStmts: ${SW_DATA_SOURCE_USE_SERVER_PREP_STMTS:true} + dataSource.useAffectedRows: ${SW_DATA_SOURCE_USE_AFFECTED_ROWS:true} metadataQueryMaxSize: ${SW_STORAGE_MYSQL_QUERY_MAX_SIZE:5000} + maxSizeOfArrayColumn: ${SW_STORAGE_MAX_SIZE_OF_ARRAY_COLUMN:20} + numOfSearchableValuesPerTag: ${SW_STORAGE_NUM_OF_SEARCHABLE_VALUES_PER_TAG:2} ``` All connection related settings including link url, username and password are in `application.yml`. These settings can refer to the configuration of *MySQL* above. diff --git a/oap-server/server-bootstrap/pom.xml b/oap-server/server-bootstrap/pom.xml index 954426b..6c8fb3a 100644 --- a/oap-server/server-bootstrap/pom.xml +++ b/oap-server/server-bootstrap/pom.xml @@ -157,6 +157,11 @@ <artifactId>storage-influxdb-plugin</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.skywalking</groupId> + <artifactId>storage-tidb-plugin</artifactId> + <version>${project.version}</version> + </dependency> <!-- storage module --> <!-- queryBuild module --> diff --git a/oap-server/server-bootstrap/src/main/resources/application.yml b/oap-server/server-bootstrap/src/main/resources/application.yml index 5cc427e..050e3ee 100755 --- a/oap-server/server-bootstrap/src/main/resources/application.yml +++ b/oap-server/server-bootstrap/src/main/resources/application.yml @@ -171,6 +171,19 @@ storage: metadataQueryMaxSize: ${SW_STORAGE_MYSQL_QUERY_MAX_SIZE:5000} maxSizeOfArrayColumn: ${SW_STORAGE_MAX_SIZE_OF_ARRAY_COLUMN:20} numOfSearchableValuesPerTag: ${SW_STORAGE_NUM_OF_SEARCHABLE_VALUES_PER_TAG:2} + tidb: + properties: + jdbcUrl: ${SW_JDBC_URL:"jdbc:mysql://localhost:4000/tidbswtest"} + dataSource.user: ${SW_DATA_SOURCE_USER:root} + dataSource.password: ${SW_DATA_SOURCE_PASSWORD:""} + dataSource.cachePrepStmts: ${SW_DATA_SOURCE_CACHE_PREP_STMTS:true} + dataSource.prepStmtCacheSize: ${SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_SIZE:250} + dataSource.prepStmtCacheSqlLimit: ${SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_LIMIT:2048} + dataSource.useServerPrepStmts: ${SW_DATA_SOURCE_USE_SERVER_PREP_STMTS:true} + dataSource.useAffectedRows: ${SW_DATA_SOURCE_USE_AFFECTED_ROWS:true} + metadataQueryMaxSize: ${SW_STORAGE_MYSQL_QUERY_MAX_SIZE:5000} + maxSizeOfArrayColumn: ${SW_STORAGE_MAX_SIZE_OF_ARRAY_COLUMN:20} + numOfSearchableValuesPerTag: ${SW_STORAGE_NUM_OF_SEARCHABLE_VALUES_PER_TAG:2} influxdb: # InfluxDB configuration url: ${SW_STORAGE_INFLUXDB_URL:http://localhost:8086} diff --git a/oap-server/server-storage-plugin/pom.xml b/oap-server/server-storage-plugin/pom.xml index 1c2c38b..16b7d1d 100644 --- a/oap-server/server-storage-plugin/pom.xml +++ b/oap-server/server-storage-plugin/pom.xml @@ -34,6 +34,7 @@ <module>storage-zipkin-plugin</module> <module>storage-jaeger-plugin</module> <module>storage-influxdb-plugin</module> + <module>storage-tidb-plugin</module> </modules> </project> \ No newline at end of file diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLStorageConfig.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLStorageConfig.java index eb9b1ae..bf0cccb 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLStorageConfig.java +++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLStorageConfig.java @@ -25,7 +25,7 @@ import org.apache.skywalking.oap.server.library.module.ModuleConfig; @Setter @Getter -public final class MySQLStorageConfig extends ModuleConfig { +public class MySQLStorageConfig extends ModuleConfig { private int metadataQueryMaxSize = 5000; /** * Inherit from {@link org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.H2StorageConfig#getMaxSizeOfArrayColumn()} diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/TiDBHistoryDeleteDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/TiDBHistoryDeleteDAO.java deleted file mode 100644 index eac392b..0000000 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/TiDBHistoryDeleteDAO.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql; - -import org.apache.skywalking.oap.server.core.storage.model.Model; -import org.apache.skywalking.oap.server.library.client.jdbc.JDBCClientException; -import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient; -import org.apache.skywalking.oap.server.storage.plugin.jdbc.SQLBuilder; -import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2HistoryDeleteDAO; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; - -public class TiDBHistoryDeleteDAO extends H2HistoryDeleteDAO { - - public TiDBHistoryDeleteDAO(JDBCHikariCPClient client) { - super(client); - } - - @Override - public void deleteHistory(Model model, String timeBucketColumnName, int ttl) throws IOException { - SQLBuilder dataDeleteSQL = new SQLBuilder("delete from " + model.getName() + " where ") - .append(timeBucketColumnName).append("<= ? and ") - .append(timeBucketColumnName).append(">= ?") - .append(" limit 10000"); - long minTimeBucket = 0; - DateTime minDate = new DateTime(1900, 1, 1, 0, 0); - - try (Connection connection = client.getConnection()) { - long deadline; - if (model.isRecord()) { - deadline = Long.valueOf(new DateTime().plusDays(0 - ttl).toString("yyyyMMddHHmmss")); - } else { - switch (model.getDownsampling()) { - case Minute: - deadline = Long.valueOf(new DateTime().plusDays(0 - ttl).toString("yyyyMMddHHmm")); - minTimeBucket = Long.valueOf(minDate.toString("yyyyMMddHHmm")); - break; - case Hour: - deadline = Long.valueOf(new DateTime().plusDays(0 - ttl).toString("yyyyMMddHH")); - minTimeBucket = Long.valueOf(minDate.toString("yyyyMMddHH")); - break; - case Day: - deadline = Long.valueOf(new DateTime().plusDays(0 - ttl).toString("yyyyMMdd")); - minTimeBucket = Long.valueOf(minDate.toString("yyyyMMdd")); - break; - default: - return; - } - } - while(client.executeUpdate(connection, dataDeleteSQL.toString(), deadline, minTimeBucket) > 0) {} - } catch (JDBCClientException | SQLException e) { - throw new IOException(e.getMessage(), e); - } - } -} diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/TiDBStorageProvider.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/TiDBStorageProvider.java deleted file mode 100644 index 2ac2dce..0000000 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/TiDBStorageProvider.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql; - -import lombok.extern.slf4j.Slf4j; -import org.apache.skywalking.oap.server.core.storage.IHistoryDeleteDAO; -import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException; - -/** - * TiDB storage enhanced and came from MySQLStorageProvider to support TiDB. - * - * caution: need add "useAffectedRows=true" to jdbc url. - */ -@Slf4j -public class TiDBStorageProvider extends MySQLStorageProvider { - - @Override - public String name() { - return "tidb"; - } - - @Override - public void prepare() throws ServiceNotProvidedException { - super.prepare(); - this.registerServiceImplementation(IHistoryDeleteDAO.class, new TiDBHistoryDeleteDAO(this.mysqlClient)); - } -} diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider index d9b7df5..c8fa0b9 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider +++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider @@ -17,5 +17,4 @@ # org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.H2StorageProvider -org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLStorageProvider -org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.TiDBStorageProvider \ No newline at end of file +org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLStorageProvider \ No newline at end of file diff --git a/oap-server/server-storage-plugin/storage-tidb-plugin/pom.xml b/oap-server/server-storage-plugin/storage-tidb-plugin/pom.xml new file mode 100644 index 0000000..e989385 --- /dev/null +++ b/oap-server/server-storage-plugin/storage-tidb-plugin/pom.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>server-storage-plugin</artifactId> + <groupId>org.apache.skywalking</groupId> + <version>8.3.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>storage-tidb-plugin</artifactId> + <packaging>jar</packaging> + + + <dependencies> + <dependency> + <groupId>org.apache.skywalking</groupId> + <artifactId>server-core</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.skywalking</groupId> + <artifactId>library-client</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.skywalking</groupId> + <artifactId>storage-jdbc-hikaricp-plugin</artifactId> + <version>${project.version}</version> + </dependency> + +<!-- <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>8.0.13</version> + </dependency>--> + </dependencies> +</project> \ No newline at end of file diff --git a/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/tidb/TiDBHistoryDeleteDAO.java b/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/tidb/TiDBHistoryDeleteDAO.java new file mode 100644 index 0000000..eae6cff --- /dev/null +++ b/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/tidb/TiDBHistoryDeleteDAO.java @@ -0,0 +1,76 @@ +/* + * 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. + * + */ + +package org.apache.skywalking.oap.server.storage.plugin.jdbc.tidb; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; +import org.apache.skywalking.oap.server.core.storage.IHistoryDeleteDAO; +import org.apache.skywalking.oap.server.core.storage.model.Model; +import org.apache.skywalking.oap.server.library.client.jdbc.JDBCClientException; +import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.SQLBuilder; +import org.joda.time.DateTime; + +public class TiDBHistoryDeleteDAO implements IHistoryDeleteDAO { + + private final JDBCHikariCPClient client; + + public TiDBHistoryDeleteDAO(JDBCHikariCPClient client) { + this.client = client; + } + + @Override + public void deleteHistory(Model model, String timeBucketColumnName, int ttl) throws IOException { + SQLBuilder dataDeleteSQL = new SQLBuilder("delete from " + model.getName() + " where ") + .append(timeBucketColumnName).append("<= ? and ") + .append(timeBucketColumnName).append(">= ?") + .append(" limit 10000"); + long minTimeBucket = 0; + DateTime minDate = new DateTime(1900, 1, 1, 0, 0); + + try (Connection connection = client.getConnection()) { + long deadline; + if (model.isRecord()) { + deadline = Long.parseLong(new DateTime().plusDays(0 - ttl).toString("yyyyMMddHHmmss")); + } else { + switch (model.getDownsampling()) { + case Minute: + deadline = Long.parseLong(new DateTime().plusDays(0 - ttl).toString("yyyyMMddHHmm")); + minTimeBucket = Long.parseLong(minDate.toString("yyyyMMddHHmm")); + break; + case Hour: + deadline = Long.parseLong(new DateTime().plusDays(0 - ttl).toString("yyyyMMddHH")); + minTimeBucket = Long.parseLong(minDate.toString("yyyyMMddHH")); + break; + case Day: + deadline = Long.parseLong(new DateTime().plusDays(0 - ttl).toString("yyyyMMdd")); + minTimeBucket = Long.parseLong(minDate.toString("yyyyMMdd")); + break; + default: + return; + } + } + while (client.executeUpdate(connection, dataDeleteSQL.toString(), deadline, minTimeBucket) > 0) { + } + } catch (JDBCClientException | SQLException e) { + throw new IOException(e.getMessage(), e); + } + } +} diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLStorageConfig.java b/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/tidb/TiDBStorageConfig.java similarity index 53% copy from oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLStorageConfig.java copy to oap-server/server-storage-plugin/storage-tidb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/tidb/TiDBStorageConfig.java index eb9b1ae..197187c 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/MySQLStorageConfig.java +++ b/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/tidb/TiDBStorageConfig.java @@ -16,28 +16,13 @@ * */ -package org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql; +package org.apache.skywalking.oap.server.storage.plugin.jdbc.tidb; -import java.util.Properties; import lombok.Getter; import lombok.Setter; -import org.apache.skywalking.oap.server.library.module.ModuleConfig; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLStorageConfig; @Setter @Getter -public final class MySQLStorageConfig extends ModuleConfig { - private int metadataQueryMaxSize = 5000; - /** - * Inherit from {@link org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.H2StorageConfig#getMaxSizeOfArrayColumn()} - * - * @since 8.2.0 - */ - private int maxSizeOfArrayColumn = 20; - /** - * Inherit from {@link org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.H2StorageConfig#getNumOfSearchableValuesPerTag()} - * - * @since 8.2.0 - */ - private int numOfSearchableValuesPerTag = 2; - private Properties properties; +public class TiDBStorageConfig extends MySQLStorageConfig { } diff --git a/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/tidb/TiDBStorageProvider.java b/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/tidb/TiDBStorageProvider.java new file mode 100644 index 0000000..30d4fa8 --- /dev/null +++ b/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/tidb/TiDBStorageProvider.java @@ -0,0 +1,177 @@ +/* + * 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. + * + */ + +package org.apache.skywalking.oap.server.storage.plugin.jdbc.tidb; + +import lombok.extern.slf4j.Slf4j; +import org.apache.skywalking.oap.server.core.Const; +import org.apache.skywalking.oap.server.core.CoreModule; +import org.apache.skywalking.oap.server.core.config.ConfigService; +import org.apache.skywalking.oap.server.core.storage.IBatchDAO; +import org.apache.skywalking.oap.server.core.storage.IHistoryDeleteDAO; +import org.apache.skywalking.oap.server.core.storage.StorageDAO; +import org.apache.skywalking.oap.server.core.storage.StorageException; +import org.apache.skywalking.oap.server.core.storage.StorageModule; +import org.apache.skywalking.oap.server.core.storage.cache.INetworkAddressAliasDAO; +import org.apache.skywalking.oap.server.core.storage.management.UITemplateManagementDAO; +import org.apache.skywalking.oap.server.core.storage.model.ModelCreator; +import org.apache.skywalking.oap.server.core.storage.profile.IProfileTaskLogQueryDAO; +import org.apache.skywalking.oap.server.core.storage.profile.IProfileTaskQueryDAO; +import org.apache.skywalking.oap.server.core.storage.profile.IProfileThreadSnapshotQueryDAO; +import org.apache.skywalking.oap.server.core.storage.query.IAggregationQueryDAO; +import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO; +import org.apache.skywalking.oap.server.core.storage.query.IBrowserLogQueryDAO; +import org.apache.skywalking.oap.server.core.storage.query.ILogQueryDAO; +import org.apache.skywalking.oap.server.core.storage.query.IMetadataQueryDAO; +import org.apache.skywalking.oap.server.core.storage.query.IMetricsQueryDAO; +import org.apache.skywalking.oap.server.core.storage.query.ITopNRecordsQueryDAO; +import org.apache.skywalking.oap.server.core.storage.query.ITopologyQueryDAO; +import org.apache.skywalking.oap.server.core.storage.query.ITraceQueryDAO; +import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient; +import org.apache.skywalking.oap.server.library.module.ModuleConfig; +import org.apache.skywalking.oap.server.library.module.ModuleDefine; +import org.apache.skywalking.oap.server.library.module.ModuleProvider; +import org.apache.skywalking.oap.server.library.module.ModuleStartException; +import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2BatchDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2HistoryDeleteDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2MetadataQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2MetricsQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2NetworkAddressAliasDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2ProfileTaskLogQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2ProfileTaskQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2ProfileThreadSnapshotQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2StorageDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2TopNRecordsQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2TopologyQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2UITemplateManagementDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLAggregationQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLAlarmQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLLogQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLTableInstaller; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLTraceQueryDAO; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MysqlBrowserLogQueryDAO; + +/** + * TiDB storage enhanced and came from MySQLStorageProvider to support TiDB. + * + * caution: need add "useAffectedRows=true" to jdbc url. + */ +@Slf4j +public class TiDBStorageProvider extends ModuleProvider { + + private TiDBStorageConfig config; + private JDBCHikariCPClient mysqlClient; + + public TiDBStorageProvider() { + config = new TiDBStorageConfig(); + } + + @Override + public String name() { + return "tidb"; + } + + @Override + public Class<? extends ModuleDefine> module() { + return StorageModule.class; + } + + @Override + public ModuleConfig createConfigBeanIfAbsent() { + return config; + } + + @Override + public void prepare() throws ServiceNotProvidedException { + mysqlClient = new JDBCHikariCPClient(config.getProperties()); + + this.registerServiceImplementation(IBatchDAO.class, new H2BatchDAO(mysqlClient)); + this.registerServiceImplementation( + StorageDAO.class, + new H2StorageDAO( + getManager(), mysqlClient, config.getMaxSizeOfArrayColumn(), config.getNumOfSearchableValuesPerTag()) + ); + this.registerServiceImplementation( + INetworkAddressAliasDAO.class, new H2NetworkAddressAliasDAO(mysqlClient)); + + this.registerServiceImplementation(ITopologyQueryDAO.class, new H2TopologyQueryDAO(mysqlClient)); + this.registerServiceImplementation(IMetricsQueryDAO.class, new H2MetricsQueryDAO(mysqlClient)); + this.registerServiceImplementation( + ITraceQueryDAO.class, + new MySQLTraceQueryDAO( + getManager(), + mysqlClient, + config.getMaxSizeOfArrayColumn(), + config.getNumOfSearchableValuesPerTag() + ) + ); + this.registerServiceImplementation(IBrowserLogQueryDAO.class, new MysqlBrowserLogQueryDAO(mysqlClient)); + this.registerServiceImplementation( + IMetadataQueryDAO.class, new H2MetadataQueryDAO(mysqlClient, config.getMetadataQueryMaxSize())); + this.registerServiceImplementation(IAggregationQueryDAO.class, new MySQLAggregationQueryDAO(mysqlClient)); + this.registerServiceImplementation(IAlarmQueryDAO.class, new MySQLAlarmQueryDAO(mysqlClient)); + this.registerServiceImplementation( + IHistoryDeleteDAO.class, new H2HistoryDeleteDAO(mysqlClient)); + this.registerServiceImplementation(ITopNRecordsQueryDAO.class, new H2TopNRecordsQueryDAO(mysqlClient)); + this.registerServiceImplementation(ILogQueryDAO.class, new MySQLLogQueryDAO(mysqlClient)); + + this.registerServiceImplementation(IProfileTaskQueryDAO.class, new H2ProfileTaskQueryDAO(mysqlClient)); + this.registerServiceImplementation(IProfileTaskLogQueryDAO.class, new H2ProfileTaskLogQueryDAO(mysqlClient)); + this.registerServiceImplementation( + IProfileThreadSnapshotQueryDAO.class, new H2ProfileThreadSnapshotQueryDAO(mysqlClient)); + this.registerServiceImplementation(UITemplateManagementDAO.class, new H2UITemplateManagementDAO(mysqlClient)); + + this.registerServiceImplementation(IHistoryDeleteDAO.class, new TiDBHistoryDeleteDAO(mysqlClient)); + } + + @Override + public void start() throws ServiceNotProvidedException, ModuleStartException { + final ConfigService configService = getManager().find(CoreModule.NAME) + .provider() + .getService(ConfigService.class); + final int numOfSearchableTags = configService.getSearchableTracesTags().split(Const.COMMA).length; + if (numOfSearchableTags * config.getNumOfSearchableValuesPerTag() > config.getMaxSizeOfArrayColumn()) { + throw new ModuleStartException("Size of searchableTracesTags[" + numOfSearchableTags + + "] * numOfSearchableValuesPerTag[" + config.getNumOfSearchableValuesPerTag() + + "] > maxSizeOfArrayColumn[" + config.getMaxSizeOfArrayColumn() + + "]. Potential out of bound in the runtime."); + } + + try { + mysqlClient.connect(); + + MySQLTableInstaller installer = new MySQLTableInstaller( + mysqlClient, getManager(), config.getMaxSizeOfArrayColumn(), config.getNumOfSearchableValuesPerTag() + ); + getManager().find(CoreModule.NAME).provider().getService(ModelCreator.class).addModelListener(installer); + } catch (StorageException e) { + throw new ModuleStartException(e.getMessage(), e); + } + } + + @Override + public void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException { + + } + + @Override + public String[] requiredModules() { + return new String[] {CoreModule.NAME}; + } +} diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider b/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider similarity index 77% copy from oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider copy to oap-server/server-storage-plugin/storage-tidb-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider index d9b7df5..cfe7e5f 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider +++ b/oap-server/server-storage-plugin/storage-tidb-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider @@ -16,6 +16,4 @@ # # -org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.H2StorageProvider -org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.MySQLStorageProvider -org.apache.skywalking.oap.server.storage.plugin.jdbc.mysql.TiDBStorageProvider \ No newline at end of file +org.apache.skywalking.oap.server.storage.plugin.jdbc.tidb.TiDBStorageProvider \ No newline at end of file