-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Simplifying topo implementations. #3402
Conversation
This is moving up the code that was exactly the same from all topos up to the topo.Server object. This is now possible, since all topo implementations had the same code. The Tee code needs to be fixed so the backend code works correctly with the Backend interface, will do that in the next commit. BUG=30274258
Just want to make sure the version code works, as it is different for the topo.Backend methods than it was for the *Keyspace methods.
And fixing related issues.
In the process, converting the discovery topology watcher code to use a regular memorytopo, instead of a custom topo.
fa41e97
to
1771fa7
Compare
No need to have the interface now that we only have one implementation. Moved everything into vtctld/explorer.go.
@sougou ready for review. Probably one commit at a time is easier. (will create an internal CL for it too) |
And this: +938 −3,855 yes! |
@@ -282,6 +284,7 @@ func (client *fakeTabletManagerClient) ExecuteFetchAsDba(ctx context.Context, ta | |||
return client.TabletManagerClient.ExecuteFetchAsDba(ctx, tablet, usePool, query, maxRows, disableBinlogs, reloadSchema) | |||
} | |||
|
|||
// FIXME(alainjobart) replace with a memorytopo. |
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 you did this in some tests and didn't do in others?
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 thought this would be too much for a single PR, but I guess it's huge already.
Pushed a commit with a fix for this, working on the rest now.
go/vt/topo/helpers/copy.go
Outdated
@@ -80,7 +80,9 @@ func CopyKeyspaces(ctx context.Context, fromTS, toTS topo.Impl) { | |||
|
|||
// CopyShards will create the shards in the destination topo. | |||
func CopyShards(ctx context.Context, fromTS, toTS topo.Impl) { |
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 you didn't make all functions to accept topo.Server instead of topo.Impl?
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.
Done.
|
||
// UpdateShardReplicationFields updates the fields inside a topo.ShardReplication object. | ||
func (ts Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspace, shard string, update func(*topodatapb.ShardReplication) error) error { | ||
nodePath := path.Join(KeyspacesPath, keyspace, ShardsPath, shard, ShardReplicationFile) |
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.
Shouldn't you convert the shard name to lowercase in all these functions?
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 don't think we need to do that any more, it was a leftover from old code.
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.
You mean now all the code everywhere uses only shard names in lower case and there is no possibility to pass shard names through a flag (or read it from topology)?
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.
You can pass shard names through a flag, but if you use the wrong case, it will just fail (with unknown shard error). Same as for keyspaces, if you use the wrong case, it will fail. That's just more consistent.
But in most cases, we go through ValidateShard (see above) which already does the ToLower. So all storage is already lower case.
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.
A bit more on this: all code path that alter the topo go through ValidateShard, or TabletComplete, which will both fix the shard name to lower case for keyranges. So we really guarantee everything is lower case for keyranges (like a0-b0). For non-keyranges, we will just keep the case, for all topo implementations alike.
|
||
// UpdateSrvKeyspace saves a new SrvKeyspace. It is a blind write. | ||
func (ts Server) UpdateSrvKeyspace(ctx context.Context, cell, keyspace string, srvKeyspace *topodatapb.SrvKeyspace) error { | ||
nodePath := srvKeyspaceFileName(keyspace) |
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.
Should you replace "keyspaces" in srvKeyspaceFileName above with KeyspacesPath for consistency?
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.
Done.
go/vt/topo/test/keyspace.go
Outdated
@@ -91,44 +91,30 @@ func checkKeyspace(t *testing.T, ts topo.Impl) { | |||
t.Errorf("GetKeyspaces: want %v, got %v", []string{"test_keyspace", "test_keyspace2"}, keyspaces) | |||
} | |||
|
|||
// re-read and update. | |||
storedK, storedVersion, err := ts.GetKeyspace(ctx, "test_keyspace2") | |||
// Re-read and update. Have to lock it. |
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 have to lock it? Without the explanation the comment is not very useful.
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.
UpdateKeyspace checks for the lock. Updated comment.
|
||
// unconditional update | ||
storedK.ShardingColumnType = topodatapb.KeyspaceIdType_BYTES | ||
_, err = ts.UpdateKeyspace(ctx, "test_keyspace2", storedK, -1) |
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 one more update here. Why did you remove it?
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.
We don't do keyspace unconditional updates, so I removed the test case for it. The new API doesn't surface version=nil here.
@@ -34,7 +34,9 @@ var timeUntilLockIsTaken = 10 * time.Millisecond | |||
// checkKeyspaceLock checks we can take a keyspace lock as expected. | |||
func checkKeyspaceLock(t *testing.T, ts topo.Impl) { | |||
ctx := context.Background() | |||
if err := ts.CreateKeyspace(ctx, "test_keyspace", &topodatapb.Keyspace{}); err != nil { | |||
// FIXME(alainjobart) when everywhere, just pass topo.Server as ts. |
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 it's not everywhere yet?
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.
Next on my list is to push the Lock API down to the topo.Backend interface. Will be a different PR though, this one is big already. But coming up next.
Name: "stln1", | ||
}, | ||
}, | ||
}, |
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 did you remove the vschema definition here?
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.
The new higher level API checks it is correct, and this one wasn't.
go/vt/vtctld/explorer.go
Outdated
} | ||
|
||
// Result is what the backendExplorer returns. It represents one directory node. | ||
// It is exported to the JSON encoder can print it. |
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 sentence has two verbs.
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.
Fixed.
Less hacking of the topo.Impl that way. Also checking for error text in errors, so we know we're catching the right error.
Main thing is the consistent use of topo.Server in topo/helpers.
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.
Addressed all comments, PTAL.
Probably easier to just look at the last two commits.
go/vt/topo/helpers/copy.go
Outdated
@@ -80,7 +80,9 @@ func CopyKeyspaces(ctx context.Context, fromTS, toTS topo.Impl) { | |||
|
|||
// CopyShards will create the shards in the destination topo. | |||
func CopyShards(ctx context.Context, fromTS, toTS topo.Impl) { |
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.
Done.
|
||
// UpdateShardReplicationFields updates the fields inside a topo.ShardReplication object. | ||
func (ts Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspace, shard string, update func(*topodatapb.ShardReplication) error) error { | ||
nodePath := path.Join(KeyspacesPath, keyspace, ShardsPath, shard, ShardReplicationFile) |
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 don't think we need to do that any more, it was a leftover from old code.
|
||
// UpdateSrvKeyspace saves a new SrvKeyspace. It is a blind write. | ||
func (ts Server) UpdateSrvKeyspace(ctx context.Context, cell, keyspace string, srvKeyspace *topodatapb.SrvKeyspace) error { | ||
nodePath := srvKeyspaceFileName(keyspace) |
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.
Done.
go/vt/topo/test/keyspace.go
Outdated
@@ -91,44 +91,30 @@ func checkKeyspace(t *testing.T, ts topo.Impl) { | |||
t.Errorf("GetKeyspaces: want %v, got %v", []string{"test_keyspace", "test_keyspace2"}, keyspaces) | |||
} | |||
|
|||
// re-read and update. | |||
storedK, storedVersion, err := ts.GetKeyspace(ctx, "test_keyspace2") | |||
// Re-read and update. Have to lock it. |
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.
UpdateKeyspace checks for the lock. Updated comment.
|
||
// unconditional update | ||
storedK.ShardingColumnType = topodatapb.KeyspaceIdType_BYTES | ||
_, err = ts.UpdateKeyspace(ctx, "test_keyspace2", storedK, -1) |
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.
We don't do keyspace unconditional updates, so I removed the test case for it. The new API doesn't surface version=nil here.
@@ -34,7 +34,9 @@ var timeUntilLockIsTaken = 10 * time.Millisecond | |||
// checkKeyspaceLock checks we can take a keyspace lock as expected. | |||
func checkKeyspaceLock(t *testing.T, ts topo.Impl) { | |||
ctx := context.Background() | |||
if err := ts.CreateKeyspace(ctx, "test_keyspace", &topodatapb.Keyspace{}); err != nil { | |||
// FIXME(alainjobart) when everywhere, just pass topo.Server as ts. |
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.
Next on my list is to push the Lock API down to the topo.Backend interface. Will be a different PR though, this one is big already. But coming up next.
Name: "stln1", | ||
}, | ||
}, | ||
}, |
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.
The new higher level API checks it is correct, and this one wasn't.
go/vt/vtctld/explorer.go
Outdated
} | ||
|
||
// Result is what the backendExplorer returns. It represents one directory node. | ||
// It is exported to the JSON encoder can print it. |
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.
Fixed.
And thanks @pivanof for the review, this is a lot of cleanup. 👍 |
} | ||
// This will create the Keyspace, Shard and Tablet record. | ||
// Since this is a replica tablet, the Shard will have no master. | ||
if err := wr.InitTablet(ctx, tablet /*allowMasterOverride=*/, false /*createShardAndKeyspace=*/, true /*allowUpdate*/, false); err != nil { |
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.
The commas are on the wrong side of comments here. They should be on the left, because the comment is related to the value on the right.
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 always get hit by this, gofmt has different format that C. Fixed.
go/vt/topo/helpers/tee_test.go
Outdated
// create a tee and check it implements the interface | ||
tee := NewTee(fromTS, toTS, true) | ||
// create a tee and check it implements the interface. | ||
tee := NewTee(fromTS.Impl, toTS.Impl, 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.
Should actually NewTee accept Server instead of Impl and return Server as well?
|
||
// UpdateShardReplicationFields updates the fields inside a topo.ShardReplication object. | ||
func (ts Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspace, shard string, update func(*topodatapb.ShardReplication) error) error { | ||
nodePath := path.Join(KeyspacesPath, keyspace, ShardsPath, shard, ShardReplicationFile) |
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.
You mean now all the code everywhere uses only shard names in lower case and there is no possibility to pass shard names through a flag (or read it from topology)?
go/vt/topo/test/replication.go
Outdated
@@ -27,9 +27,10 @@ import ( | |||
|
|||
// checkShardReplication tests ShardReplication objects | |||
func checkShardReplication(t *testing.T, ts topo.Impl) { |
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.
It feels like this function needs to accept Server instead of Impl as well.
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.
Done.
@pivanof addressed latest comments, with commit. One comment was lost in there, but I saw it somewhere:
I think so, but I also have on my list to refactor some of that code, so I'll do it then, if you don't mind. Right now, the tee is at the Impl level, it should either be at Backend, or Server, as Impl is going to disappear. So this code will need to change at some point again. |
…client mount command more standard (vitessio#3402) * backport of 3398 * Fix conflict Signed-off-by: Matt Lord <mattalord@gmail.com> --------- Signed-off-by: Matt Lord <mattalord@gmail.com> Co-authored-by: Matt Lord <mattalord@gmail.com>
Now that all implementations are based on the topo.Backend sub-interface, this is possible.
BUG=30274258