Skip to content
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

Merged
merged 11 commits into from
Nov 22, 2017
Merged

Conversation

alainjobart
Copy link
Contributor

@alainjobart alainjobart commented Nov 17, 2017

Now that all implementations are based on the topo.Backend sub-interface, this is possible.

BUG=30274258

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.
In the process, converting the discovery topology watcher code to use a
regular memorytopo, instead of a custom topo.
@alainjobart alainjobart changed the title [WIP] Simplifying topo implementations. Simplifying topo implementations. Nov 19, 2017
@alainjobart
Copy link
Contributor Author

@sougou ready for review. Probably one commit at a time is easier.

(will create an internal CL for it too)

@alainjobart
Copy link
Contributor Author

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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)?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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.
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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",
},
},
},
Copy link
Contributor

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?

Copy link
Contributor Author

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.

}

// Result is what the backendExplorer returns. It represents one directory node.
// It is exported to the JSON encoder can print it.
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor Author

@alainjobart alainjobart left a 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.

@@ -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) {
Copy link
Contributor Author

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)
Copy link
Contributor Author

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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.
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.
Copy link
Contributor Author

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",
},
},
},
Copy link
Contributor Author

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.

}

// Result is what the backendExplorer returns. It represents one directory node.
// It is exported to the JSON encoder can print it.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@alainjobart
Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

// 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)
Copy link
Contributor

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)
Copy link
Contributor

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)?

@@ -27,9 +27,10 @@ import (

// checkShardReplication tests ShardReplication objects
func checkShardReplication(t *testing.T, ts topo.Impl) {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@alainjobart
Copy link
Contributor Author

@pivanof addressed latest comments, with commit.

One comment was lost in there, but I saw it somewhere:

Should actually NewTee accept Server instead of Impl and return Server as well?

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.

@alainjobart alainjobart merged commit e784ac3 into vitessio:master Nov 22, 2017
frouioui pushed a commit to planetscale/vitess that referenced this pull request Mar 26, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants