-
Notifications
You must be signed in to change notification settings - Fork 791
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
Implement sharded SQL driver to support using multiple SQL databases #4504
Conversation
0d76744
to
259a231
Compare
259a231
to
b80e030
Compare
536937b
to
bed3e7b
Compare
@@ -70,7 +70,7 @@ func (mdb *db) CreateSchemaVersionTables() error { | |||
// ReadSchemaVersion returns the current schema version for the keyspace | |||
func (mdb *db) ReadSchemaVersion(database string) (string, error) { | |||
var version string | |||
err := mdb.driver.Get(sqlplugin.DbAllShards, &version, readSchemaVersionQuery, database) | |||
err := mdb.driver.Get(sqlplugin.DbDefaultShard, &version, readSchemaVersionQuery, database) |
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.
why change this?
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.
Because there is difficulty implementing All shards
in current driver interface. I let it read from a single shard(database) for now and was planning to improve it as a follow-up: #4509
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.
If you like I can also try to implement it here -- there are different ways of doing it -- the simpliest way is to send the queries to all shards and make sure all of them return the same value(deep equal).
Other ideas: 1) allow setting shardID when sending query, or return a set of reset instead of a single one. -- both would require a refactor on the code path.
I feel like it's better do it in a separate PR. What do you think ?
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.
Sure, let's do it in a separate PR.
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.
This looks great, can't wait to try it out!
common/config/persistence.go
Outdated
return fmt.Errorf("sql persistence config: connectAddr can only be configured ini multipleDatabasesConfig when UseMultipleDatabases is true ") | ||
} | ||
if ds.SQL.User != "" { | ||
return fmt.Errorf("sql persistence config: user can only be configured ini multipleDatabasesConfig when UseMultipleDatabases is true ") |
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.
typo: ini
-> in
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.
good catch. Thanks!
return fmt.Errorf("sql persistence config: password can only be configured ini multipleDatabasesConfig when UseMultipleDatabases is true ") | ||
} | ||
if ds.SQL.NumShards <= 1 || len(ds.SQL.MultipleDatabasesConfig) != ds.SQL.NumShards { | ||
return fmt.Errorf("sql persistence config: nShards must be greater than one and equal to the length of multipleDatabasesConfig") |
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.
nit: I wonder if we need NumShards
or can just rely on length of MultipleDatabasesConfig
instead?
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.
NumShards
is needed in the case that Cadence uses a sharded SQL solution(like Uber's docStore, or CockroachDB/DorisDB), so we can't remove it(in that case, they don't have MultipleDatabasesConfig
.)
I was thinking to give NumShards
a default number of length of MultipleDatabasesConfig
when not set. But the doc is going to be a little confusing -- when MultipleDatabasesConfig
set the default value is length of it, when not set the default value is 1.
On the other side, NumShards
is a critical config that having it explicitly will help understanding it when reviewing the config(rather than counting the length the of array).
So I am not sure whether we should complicate that. But open to more ideas.
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.
I merged it now as it's a nit comment.
But feel free to give suggestion as I will open next PR to tests and keep improving it.
What changed?
Implement sharded SQL driver to support using multiple SQL databases
Why?
Support using multiple SQL databases for larger scale of Cadence
How did you test it?
working on adding more tests
Local testing is okay:
Potential risks
Low risks. It's an optional feature. No behavior change to existing setup.
Release notes
Documentation Changes