Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

VDiff External DB#144

Merged
rafael merged 7 commits intovifl-masterfrom
vdiff-external-db
Jan 14, 2020
Merged

VDiff External DB#144
rafael merged 7 commits intovifl-masterfrom
vdiff-external-db

Conversation

@rafael
Copy link

@rafael rafael commented Jan 11, 2020

Description

  • Enables vdiff to connect to an external database. This PR leverages most of the work provided by https://github.com/vitessio/vitess/pull/5367/files.
  • Specifically, vreplication/vdiff.go is a copy of vt/wrangler/vdiff.go that enables vdiff to be run directly from a tablet. The following changes were required to make this work:
    • Discovery mechanism from open source version is removed and there is an assumption that the target tablet is always the tablet where vdiff is running. Source tablet is determined by the same discovery mechanism that vreplication uses to find a source for the stream.
    • vstreamer_client interface was enhanced to be able to run vdiff against an external source.
    • The way diffs are reported were tweaked and they are exposed via an API endpoint in vttablet.
    • It always assumes that there will only be a single vreplication stream.

Asks for reviewer

Rafael Chacon added 6 commits January 5, 2020 16:55
Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
* Prior to this commit, flavorpos was using lexicographical comparison of the gtids.
  Thas was a bug in this context.

Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
When generating masterGTIDSet in file:pos most likely you will have a topology
like the following:

  Source A -> Target B (B has a vreplication stream from A)

From the target perspective, the source A is the master and you want to generate
a gtid that is based on binlog file position of that server.

As an example, let's see this topology:

  Master A -> Source B -> Target C (C has vreplication stream from B)

Prior to this change, masterGTIDSet was returning the binlogfile:pos of A. But
in reality, the Target C wants the position of B.

Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
Copy link

@setassociative setassociative left a comment

Choose a reason for hiding this comment

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

This is an admittedly clumsy read through as it's large and I don't have deep knowledge of the existing vreplication/vdiff code but it feels good to me. Backed by extensive manual + testing I think this is good to merge.


// The db name is set by the Start function called above
agent.VREngine = vreplication.NewEngine(ts, tabletAlias.Cell, mysqld, func() binlogplayer.DBClient {
agent.VREngine = vreplication.NewEngine(ts, tabletAlias.GetCell(), agent.Tablet(), mysqld, func() binlogplayer.DBClient {

Choose a reason for hiding this comment

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

Just to be clear when we agent.Tablet() we get a clone of the proto object at that point -- is there danger that it will change in the background in some meaningful way before we come through and run the vtdiff?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, that is correct. There is no danger, because in this context we always assume that you will be running vdiff from the current tablet, against it's external source.

healthcheckRetryDelay = flag.Duration("vreplication_healthcheck_retry_delay", 5*time.Second, "healthcheck retry delay")
healthcheckTimeout = flag.Duration("vreplication_healthcheck_timeout", 1*time.Minute, "healthcheck retry delay")
retryDelay = flag.Duration("vreplication_retry_delay", 5*time.Second, "delay before retrying a failed binlog connection")
onlyOnceVdiff sync.Once

Choose a reason for hiding this comment

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

it doesn't look like this is used -- is that intentional?

Copy link
Author

Choose a reason for hiding this comment

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

oh good catch. This is from a previous incarnation when I did not have an api to control vdiff. Let me remove.

// Wait for the conn.ExecuteFetch() call to return.
<-done
// Close the connection. Upon Recycle() it will be thrown out.
conn.Close()

Choose a reason for hiding this comment

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

Because you defer conn.Close() at the executeFetchContext call site this will happen twice. Safe to call multiple times but not sure if you want to leave it out of this code path.

Copy link
Author

Choose a reason for hiding this comment

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

This one of the other things I had to copy from other places to make this work against an external database. This comes from: https://github.com/tinyspeck/vitess/blob/master/go/vt/mysqlctl/query.go#L98

* Address PR review + some other cleanup per linter

Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
@rafael rafael merged commit 2ffd3e0 into vifl-master Jan 14, 2020
@rafael rafael deleted the vdiff-external-db branch January 14, 2020 21:59
@rafael rafael mentioned this pull request May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants