-
Notifications
You must be signed in to change notification settings - Fork 64
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
feature: Datasource 抽象 #170
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #170 +/- ##
==========================================
+ Coverage 81.82% 82.51% +0.69%
==========================================
Files 33 36 +3
Lines 2657 2699 +42
==========================================
+ Hits 2174 2227 +53
+ Misses 404 388 -16
- Partials 79 84 +5
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
- 在 internal 下面直接创建一个 datasource。datasource 用于 sharding,但是并不归属于 sharding;
- 在 internal/datasource 里面定义接口
- 在 internal/datasource 里面提供三个实现:单一 DB,主从,Cluster DB
- 将已有的 slaves 的包挪过去对应的主从实现的子包里面
以下是要尝试一下,我预期中的:
- 让 eorm.DB 里面持有一个 datasource,而后在 eorm 层面上我们只有 DB 这个概念。也就是说,通过 eorm.DB 里面维持不同的 datasource 实现,那么它可以统一表达任意类型的 DB
- 在上一条成立的前提下,引入一个 OpenDS(ds datasource.Datasource) 的方法
- 在上一条成立的前提下,重构已有的代码,将 eorm 层面上对 datasource实现依赖的,都修改为对 DB 的依赖
我认为,在 ORM 层面上,应该不关心底层的 datasource 究竟是单一数据库,还是主从,还是分库分表的。虽然看起来难以彻底做到,但是至少朝着这里面去前进。
eorm.DB 内部维持一个 datasource 字段,然后让 DB 实现 session。 Session 接口组合你的 Datasource 接口 |
这么搞普通的查询用不了主从数据库了,因为都必须实现 |
所以我说有一个普通的 DB 对应的 Datasource 实现。总共三个 |
datasource.DB 和 eorm.DB,你不要搞混了,这个是两个。后者是前者的装饰器 |
应该说,eorm.DB 是 datasource.Datasource 的装饰器,提供了 core 的那个功能 |
对于事物的实现,我理解应该说在 erom.DB 里维护?但集群怎么保证事物呢 |
还是说 只要保证 sharding 后的目标主库写入数据就行,还有这么一来是否非分库分表就不能使用集群cluster |
主从和单一的,你直接搞,和正常的事务没什么区别。分库分表的,这个要另外开 issue。分库分表的事务是一个跟棘手的事情,比这个 Datasource 棘手 |
''' |
我草!46 个文件,要命了! |
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.
我明天试试能不能删掉 cluster_db,看上去你这里没有用到。
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.
mark
你的 Golang-CI 崩了呀! |
ci lint 和 排序的那个pr的合入有很大关系,要问 zwl 同学了 |
你更新一下你的pre-push/pre-commit及setup.sh, golangci-lint版本之前有问题所以干脆和github action一样用@latest版本,重新安装一下golangci-lint |
是的 |
internal/datasource/masterslave/slaves/roundrobin/roundrobin.go
Outdated
Show resolved
Hide resolved
internal/datasource/masterslave/slaves/roundrobin/roundrobin.go
Outdated
Show resolved
Hide resolved
我一直觉得这个单元测试覆盖率简直有毒,不知道怎么算的 |
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.
一个个你确定解决了的 conversation 你就点一下 resolve。不然你可能漏了...
return ms.Exec(ctx, query) | ||
} | ||
|
||
//func (*clusterDB) BeginTx(_ context.Context, _ *sql.TxOptions) (datasource.Tx, error) { |
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.
不用的代码就删掉
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.
mark
后续我再来微调 |
No description provided.