Add linearizable support to SQL VSchema management#17401
Add linearizable support to SQL VSchema management#17401mattlord merged 17 commits intovitessio:mainfrom
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
4b4578d to
be1ccd1
Compare
Signed-off-by: Matt Lord <mattalord@gmail.com>
be1ccd1 to
b2e2ba6
Compare
Signed-off-by: Matt Lord <mattalord@gmail.com>
e9319d3 to
1ccc129
Compare
Signed-off-by: Matt Lord <mattalord@gmail.com>
1ccc129 to
e02adaf
Compare
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17401 +/- ##
==========================================
+ Coverage 67.63% 67.64% +0.01%
==========================================
Files 1586 1586
Lines 255566 255629 +63
==========================================
+ Hits 172850 172924 +74
+ Misses 82716 82705 -11 ☔ View full report in Codecov by Sentry. |
This reverts commit cd455a0. Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
| return err | ||
| } | ||
| } else { | ||
| // Use the cached version as we are in read-only mode |
There was a problem hiding this comment.
When do we get to this code path? Later on we are calling vc.vm.UpdateVSchema() which is expected to write back to the topo, correct? Should we just return an error here, if it is going to fail anyway later on?
There was a problem hiding this comment.
When the topo connection is read-only, which would be e.g. when using --keyspaces_to_watch (see #8988). In that case it's fine to use the cached version because we know that the subsequent ApplyVSchemaDDL() call will fail. I could return an error here rather than make the Apply call. I left it this way to leave the flow (and unit test) unchanged.
I agree that it's a little awkward, so I'm happy to instead return an error about the topo being in read-only mode when vc.topoServer == nil if others prefer that.
This is the current error that users see:
go/test/endtoend/vtgate/keyspace_watches/keyspace_watch_test.go: vschemaDDLError = fmt.Sprintf("Error 1105 (HY000): cannot perform Update on keyspaces/%s/VSchema as the topology server connection is read-only",
I'll see if I can maintain that with an earlier failure here.
There was a problem hiding this comment.
@harshit-gangal what do you think? I'll hold off until you have a chance to review. Perhaps the error here doesn't really matter much and I can instead just return:
cannot update the VSchema as the topology server connection is read-only
There was a problem hiding this comment.
fwiw, I think this is fine.
There was a problem hiding this comment.
We should error out upfront.
GuptaManan100
left a comment
There was a problem hiding this comment.
One change needs to be made, but otherwise looks good to me. Approving so that PR can be merged after the change has been made. ❤️
| // keyspace's vschema. | ||
| type KeyspaceVSchemaInfo struct { | ||
| Name string | ||
| *vschemapb.Keyspace | ||
| version Version | ||
| } |
There was a problem hiding this comment.
This struct is a duplicate of an existing one in this same package. There exists KeyspaceInfo in keyspace.go. The struct definition is as follows -
// KeyspaceInfo is a meta struct that contains metadata to give the
// data more context and convenience. This is the main way we interact
// with a keyspace.
type KeyspaceInfo struct {
keyspace string
version Version
*topodatapb.Keyspace
}It pretty much has the same information just with a different nomenclature. I think we should remove this and use that struct directly or vice versa.
|
|
||
| // TestVSchemaSQLAPIConcurrency tests that we prevent lost writes when we have | ||
| // concurrent vschema changes being made via the SQL API. | ||
| func TestVSchemaSQLAPIConcurrency(t *testing.T) { |
| version Version | ||
| } | ||
|
|
||
| func (k *KeyspaceVSchemaInfo) CloneVT() *KeyspaceVSchemaInfo { |
There was a problem hiding this comment.
super nit: why did we name this as CloneVT?
There was a problem hiding this comment.
I wanted to override the embedded vschemapb.Keyspace CloneVT function. I'm fine renaming it to Clone e.g. though.
| // keyspace definition and returns the modified keyspace object. | ||
| func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, alterVschema *sqlparser.AlterVschema) (*vschemapb.Keyspace, error) { | ||
| if ks == nil { | ||
| ks = new(vschemapb.Keyspace) | ||
| func ApplyVSchemaDDL(ksName string, ksvs *topo.KeyspaceVSchemaInfo, alterVschema *sqlparser.AlterVschema) (*topo.KeyspaceVSchemaInfo, error) { | ||
| if ksvs.Tables == nil { | ||
| ksvs.Tables = map[string]*vschemapb.Table{} | ||
| } |
There was a problem hiding this comment.
I believe the GetVSchema should be done inside this method to ensure all the callers of ApplyVSchemaDDL have a common code. Post that they can have a action method of their own which they can pass in.
This will avoid the issue of missing this call outside of ApplyVSchemaDDL
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Description
This PR prevents lost writes when using the VTGate SQL API for VSchema management (see issue).
It also lays the foundation for supporting linearizability guarantees for vschemas within Vitess. Please see the tracking issue for the other known pieces.
Related Issue(s)
Checklist