-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix transaction too large error when use TiDB as storage #5754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/TiDBHistoryDeleteDAO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| 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); | ||
| } | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
.../java/org/apache/skywalking/oap/server/storage/plugin/jdbc/mysql/TiDBStorageProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have a new provider, we need a new maven module for tidb storage, and make it compiled as a separate jar. |
||
|
|
||
| @Override | ||
| public String name() { | ||
| return "tidb"; | ||
| } | ||
|
|
||
| @Override | ||
| public void prepare() throws ServiceNotProvidedException { | ||
| super.prepare(); | ||
| this.registerServiceImplementation(IHistoryDeleteDAO.class, new TiDBHistoryDeleteDAO(this.mysqlClient)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comments about why you need this.