-
Notifications
You must be signed in to change notification settings - Fork 201
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
feat: job-execute 支持垂直分库 #3265 #3280
Open
wangyu096
wants to merge
16
commits into
TencentBlueKing:master
Choose a base branch
from
wangyu096:issue_3265
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
jsonwan
reviewed
Nov 6, 2024
try { | ||
synchronized (lock) { | ||
log.debug("Datasource is migrating, wait unit migrated"); | ||
lock.wait(); |
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.
大量线程阻塞在这里,随着请求累积,可能导致Tomcat工作线程耗尽,影响到后续其他请求,建议只阻塞必要的写请求,可提前压测验证观察程序表现。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
背景
所以,先拆分单个 db 为垂直分库模式,把不同的表分散到多个 db 上,降低单个 db 的负载,并为后续水平分库分表数据做好准备。
设计
垂直分库设计
分成固定的三个 db,把job-execute的表分散到三个 DB 上。之所以采用这种固定的方式,原因是:
另外,由于垂直分片的方式仍然有局限性,比如只是扩大了有限的承载能力(几倍),比如表之间的 join关系、事务在垂直分片模式下都会受到限制,所以该方案仅作为过渡方案,等后续水平分库上线之后,该方案将不再支持。
无损迁移方案
常规的迁移方案是数据双写 -> 数据校验补偿 -> 切读写到新集群。由于双写改造工作量比较大,所以在实施垂直分片迁移的时候不采用该方案,而是采用在切换期间短暂阻塞db 读写请求的方式(影响窗口小,大概 10-20s)。这样做的好处就是改造简单一些,然后也是相对无损的,只需要阻塞写请求一小段时间。
准备阶段:
应用层改造,支持运行期间动态切换数据源。
实施阶段:
重点 Review代码:
引入新的动态属性,支持在运行时修改属性值并借助 spring-cloud-kubernetes-config-watcher 和 spring-cloud-bus 的消息通知机制,动态切换数据源 (backend/commons/common/com.tentcent.bk.job.common.toggle.prop)
垂直分片 (backend/commons/common-mysql )
db 无损迁移:PropBasedDynamicDataSource.java ReadWriteLockDbMigrateAspect.java