{"action":"created","comment":{"url":"https://api.github.com/repos/youtube/vitess/pulls/comments/126273933","pull_request_review_id":48748576,"id":126273933,"diff_hunk":"@@ -0,0 +1,258 @@\n+/*\n+Copyright 2017 Google Inc.\n+\n+Licensed under the Apache License, Version 2.0 (the \"License\");\n+you may not use this file except in compliance with the License.\n+You may obtain a copy of the License at\n+\n+    http://www.apache.org/licenses/LICENSE-2.0\n+\n+Unless required by applicable law or agreed to in writing, software\n+distributed under the License is distributed on an \"AS IS\" BASIS,\n+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+See the License for the specific language governing permissions and\n+limitations under the License.\n+*/\n+\n+package mysql\n+\n+import (\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"strconv\"\n+\t\"strings\"\n+\n+\t\"github.com/youtube/vitess/go/sqltypes\"\n+\t\"golang.org/x/net/context\"\n+)\n+\n+var (\n+\t// ErrNotSlave means there is no slave status.\n+\t// Returned by ShowSlaveStatus().\n+\tErrNotSlave = errors.New(\"no slave status\")\n+)\n+\n+// flavor is the abstract interface for a flavor.\n+// Flavors are auto-detected upon connection using the server version.\n+// We have two major implementations (the main difference is the GTID\n+// handling):\n+// 1. Oracle MySQL 5.6, 5.7, 8.0, ...\n+// 2. MariaDB 10.X\n+type flavor interface {\n+\t// masterGTIDSet returns the current GTIDSet of a server.\n+\tmasterGTIDSet(c *Conn) (GTIDSet, error)\n+\n+\t// sendBinlogDumpCommand sends the packet required to start\n+\t// dumping binlogs from the specified location.\n+\tsendBinlogDumpCommand(c *Conn, slaveID uint32, startPos Position) error\n+\n+\t// resetReplicationCommands returns the commands to completely reset\n+\t// replication on the host.\n+\tresetReplicationCommands() []string\n+\n+\t// setSlavePositionCommands returns the commands to set the\n+\t// replication position at which the slave will resume.\n+\tsetSlavePositionCommands(pos Position) []string\n+\n+\t// changeMasterArg returns the specific parameter to add to\n+\t// a change master command.\n+\tchangeMasterArg() string\n+\n+\t// status returns the result of 'SHOW SLAVE STATUS',\n+\t// with parsed replication position.\n+\tstatus(c *Conn) (SlaveStatus, error)\n+\n+\t// waitUntilPositionCommand returns the SQL command to issue\n+\t// to wait until the given position, until the context\n+\t// expires.  The command returns -1 if it times out. It\n+\t// returns NULL if GTIDs are not enabled.\n+\twaitUntilPositionCommand(ctx context.Context, pos Position) (string, error)\n+\n+\t// makeBinlogEvent takes a raw packet from the MySQL binlog\n+\t// stream connection and returns a BinlogEvent through which\n+\t// the packet can be examined.\n+\tmakeBinlogEvent(buf []byte) BinlogEvent\n+\n+\t// enableBinlogPlaybackCommand and disableBinlogPlaybackCommand return an\n+\t// optional command to run to enable or disable binlog\n+\t// playback. This is used internally in Google, as the\n+\t// timestamp cannot be set by regular clients.\n+\tenableBinlogPlaybackCommand() string\n+\tdisableBinlogPlaybackCommand() string\n+}\n+\n+// mariaDBReplicationHackPrefix is the prefix of a version for MariaDB 10.0\n+// versions, to work around replication bugs.\n+const mariaDBReplicationHackPrefix = \"5.5.5-\"\n+\n+// mariaDBVersionString is present in\n+const mariaDBVersionString = \"MariaDB\"\n+\n+// fillFlavor fills in c.Flavor based on c.ServerVersion.\n+// This is the same logic as the ConnectorJ java client. We try to recognize\n+// MariaDB as much as we can, but default to MySQL.\n+//\n+// MariaDB note: the server version returned here might look like:\n+// 5.5.5-10.0.21-MariaDB-...\n+// If that is the case, we are removing the 5.5.5- prefix.\n+// Note on such servers, 'select version()' would return 10.0.21-MariaDB-...\n+// as well (not matching what c.ServerVersion is, but matching after we remove\n+// the prefix).\n+func (c *Conn) fillFlavor() {\n+\tif strings.HasPrefix(c.ServerVersion, mariaDBReplicationHackPrefix) {\n+\t\tc.ServerVersion = c.ServerVersion[len(mariaDBReplicationHackPrefix):]\n+\t\tc.flavor = mariadbFlavor{}\n+\t\treturn\n+\t}\n+\n+\tif strings.Index(c.ServerVersion, mariaDBVersionString) != -1 {\n+\t\tc.flavor = mariadbFlavor{}\n+\t\treturn\n+\t}\n+\n+\tc.flavor = mysqlFlavor{}\n+}\n+\n+//\n+// The following methods are dependent on the flavor.\n+// Only valid for client connections (will panic for server connections).\n+//\n+\n+// IsMariaDB returns true iff the other side of the client connection\n+// is identified as MariaDB. Most applications should not care, but\n+// this is useful in tests.\n+func (c *Conn) IsMariaDB() bool {\n+\t_, ok := c.flavor.(mariadbFlavor)\n+\treturn ok\n+}\n+\n+// MasterPosition returns the current master replication position.\n+func (c *Conn) MasterPosition() (Position, error) {\n+\tgtidSet, err := c.flavor.masterGTIDSet(c)\n+\tif err != nil {\n+\t\treturn Position{}, err\n+\t}\n+\treturn Position{\n+\t\tGTIDSet: gtidSet,\n+\t}, nil\n+}\n+\n+// SendBinlogDumpCommand sends the flavor-specific version of\n+// the COM_BINLOG_DUMP command to start dumping raw binlog\n+// events over a slave connection, starting at a given GTID.\n+func (c *Conn) SendBinlogDumpCommand(slaveID uint32, startPos Position) error {\n+\treturn c.flavor.sendBinlogDumpCommand(c, slaveID, startPos)\n+}\n+\n+// ResetReplicationCommands returns the commands to completely reset\n+// replication on the host.\n+func (c *Conn) ResetReplicationCommands() []string {","path":"go/mysql/flavor.go","position":149,"original_position":149,"commit_id":"964a0cab22d6d1053ba4af4744d57e37e91e0ca0","original_commit_id":"964a0cab22d6d1053ba4af4744d57e37e91e0ca0","user":{"login":"sougou","id":589370,"avatar_url":"https://avatars2.githubusercontent.com/u/589370?v=3","gravatar_id":"","url":"https://api.github.com/users/sougou","html_url":"https://github.com/sougou","followers_url":"https://api.github.com/users/sougou/followers","following_url":"https://api.github.com/users/sougou/following{/other_user}","gists_url":"https://api.github.com/users/sougou/gists{/gist_id}","starred_url":"https://api.github.com/users/sougou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sougou/subscriptions","organizations_url":"https://api.github.com/users/sougou/orgs","repos_url":"https://api.github.com/users/sougou/repos","events_url":"https://api.github.com/users/sougou/events{/privacy}","received_events_url":"https://api.github.com/users/sougou/received_events","type":"User","site_admin":false},"body":"One worry about this approach is that the Conn API may get crowded due to these flavor-specific abstractions. But this is still better than what we had before.\r\n\r\nIn the long run, we can consider supporting these through vitess-specific SQL statements (like `RESET REPLICATION`) that get translated into flavor-specific commands under the covers.","created_at":"2017-07-08T04:01:19Z","updated_at":"2017-07-08T04:10:30Z","html_url":"https://github.com/youtube/vitess/pull/2977#discussion_r126273933","pull_request_url":"https://api.github.com/repos/youtube/vitess/pulls/2977","_links":{"self":{"href":"https://api.github.com/repos/youtube/vitess/pulls/comments/126273933"},"html":{"href":"https://github.com/youtube/vitess/pull/2977#discussion_r126273933"},"pull_request":{"href":"https://api.github.com/repos/youtube/vitess/pulls/2977"}}},"pull_request":{"url":"https://api.github.com/repos/youtube/vitess/pulls/2977","id":129049900,"html_url":"https://github.com/youtube/vitess/pull/2977","diff_url":"https://github.com/youtube/vitess/pull/2977.diff","patch_url":"https://github.com/youtube/vitess/pull/2977.patch","issue_url":"https://api.github.com/repos/youtube/vitess/issues/2977","number":2977,"state":"open","locked":false,"title":"Auto-detect MySQL flavor.","user":{"login":"alainjobart","id":4625714,"avatar_url":"https://avatars0.githubusercontent.com/u/4625714?v=3","gravatar_id":"","url":"https://api.github.com/users/alainjobart","html_url":"https://github.com/alainjobart","followers_url":"https://api.github.com/users/alainjobart/followers","following_url":"https://api.github.com/users/alainjobart/following{/other_user}","gists_url":"https://api.github.com/users/alainjobart/gists{/gist_id}","starred_url":"https://api.github.com/users/alainjobart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alainjobart/subscriptions","organizations_url":"https://api.github.com/users/alainjobart/orgs","repos_url":"https://api.github.com/users/alainjobart/repos","events_url":"https://api.github.com/users/alainjobart/events{/privacy}","received_events_url":"https://api.github.com/users/alainjobart/received_events","type":"User","site_admin":false},"body":"The main change is that we get the flavor from an opened client connection to the server, instead of knowing it beforehand (or even guessing it). Then the flavor interface and code is in go/mysql now. This seems a lot cleaner and overall less lines of code.","created_at":"2017-07-05T20:38:42Z","updated_at":"2017-07-08T04:10:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"74e3fd4678ebc255ce31faba354471c94a437982","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/youtube/vitess/pulls/2977/commits","review_comments_url":"https://api.github.com/repos/youtube/vitess/pulls/2977/comments","review_comment_url":"https://api.github.com/repos/youtube/vitess/pulls/comments{/number}","comments_url":"https://api.github.com/repos/youtube/vitess/issues/2977/comments","statuses_url":"https://api.github.com/repos/youtube/vitess/statuses/964a0cab22d6d1053ba4af4744d57e37e91e0ca0","head":{"label":"alainjobart:flavor","ref":"flavor","sha":"964a0cab22d6d1053ba4af4744d57e37e91e0ca0","user":{"login":"alainjobart","id":4625714,"avatar_url":"https://avatars0.githubusercontent.com/u/4625714?v=3","gravatar_id":"","url":"https://api.github.com/users/alainjobart","html_url":"https://github.com/alainjobart","followers_url":"https://api.github.com/users/alainjobart/followers","following_url":"https://api.github.com/users/alainjobart/following{/other_user}","gists_url":"https://api.github.com/users/alainjobart/gists{/gist_id}","starred_url":"https://api.github.com/users/alainjobart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alainjobart/subscriptions","organizations_url":"https://api.github.com/users/alainjobart/orgs","repos_url":"https://api.github.com/users/alainjobart/repos","events_url":"https://api.github.com/users/alainjobart/events{/privacy}","received_events_url":"https://api.github.com/users/alainjobart/received_events","type":"User","site_admin":false},"repo":{"id":37342150,"name":"vitess","full_name":"alainjobart/vitess","owner":{"login":"alainjobart","id":4625714,"avatar_url":"https://avatars0.githubusercontent.com/u/4625714?v=3","gravatar_id":"","url":"https://api.github.com/users/alainjobart","html_url":"https://github.com/alainjobart","followers_url":"https://api.github.com/users/alainjobart/followers","following_url":"https://api.github.com/users/alainjobart/following{/other_user}","gists_url":"https://api.github.com/users/alainjobart/gists{/gist_id}","starred_url":"https://api.github.com/users/alainjobart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alainjobart/subscriptions","organizations_url":"https://api.github.com/users/alainjobart/orgs","repos_url":"https://api.github.com/users/alainjobart/repos","events_url":"https://api.github.com/users/alainjobart/events{/privacy}","received_events_url":"https://api.github.com/users/alainjobart/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alainjobart/vitess","description":"vitess provides servers and tools which facilitate scaling of MySQL databases for large scale web services.","fork":true,"url":"https://api.github.com/repos/alainjobart/vitess","forks_url":"https://api.github.com/repos/alainjobart/vitess/forks","keys_url":"https://api.github.com/repos/alainjobart/vitess/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alainjobart/vitess/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alainjobart/vitess/teams","hooks_url":"https://api.github.com/repos/alainjobart/vitess/hooks","issue_events_url":"https://api.github.com/repos/alainjobart/vitess/issues/events{/number}","events_url":"https://api.github.com/repos/alainjobart/vitess/events","assignees_url":"https://api.github.com/repos/alainjobart/vitess/assignees{/user}","branches_url":"https://api.github.com/repos/alainjobart/vitess/branches{/branch}","tags_url":"https://api.github.com/repos/alainjobart/vitess/tags","blobs_url":"https://api.github.com/repos/alainjobart/vitess/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alainjobart/vitess/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alainjobart/vitess/git/refs{/sha}","trees_url":"https://api.github.com/repos/alainjobart/vitess/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alainjobart/vitess/statuses/{sha}","languages_url":"https://api.github.com/repos/alainjobart/vitess/languages","stargazers_url":"https://api.github.com/repos/alainjobart/vitess/stargazers","contributors_url":"https://api.github.com/repos/alainjobart/vitess/contributors","subscribers_url":"https://api.github.com/repos/alainjobart/vitess/subscribers","subscription_url":"https://api.github.com/repos/alainjobart/vitess/subscription","commits_url":"https://api.github.com/repos/alainjobart/vitess/commits{/sha}","git_commits_url":"https://api.github.com/repos/alainjobart/vitess/git/commits{/sha}","comments_url":"https://api.github.com/repos/alainjobart/vitess/comments{/number}","issue_comment_url":"https://api.github.com/repos/alainjobart/vitess/issues/comments{/number}","contents_url":"https://api.github.com/repos/alainjobart/vitess/contents/{+path}","compare_url":"https://api.github.com/repos/alainjobart/vitess/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alainjobart/vitess/merges","archive_url":"https://api.github.com/repos/alainjobart/vitess/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alainjobart/vitess/downloads","issues_url":"https://api.github.com/repos/alainjobart/vitess/issues{/number}","pulls_url":"https://api.github.com/repos/alainjobart/vitess/pulls{/number}","milestones_url":"https://api.github.com/repos/alainjobart/vitess/milestones{/number}","notifications_url":"https://api.github.com/repos/alainjobart/vitess/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alainjobart/vitess/labels{/name}","releases_url":"https://api.github.com/repos/alainjobart/vitess/releases{/id}","deployments_url":"https://api.github.com/repos/alainjobart/vitess/deployments","created_at":"2015-06-12T20:07:42Z","updated_at":"2017-02-04T13:19:45Z","pushed_at":"2017-07-07T18:58:12Z","git_url":"git://github.com/alainjobart/vitess.git","ssh_url":"git@github.com:alainjobart/vitess.git","clone_url":"https://github.com/alainjobart/vitess.git","svn_url":"https://github.com/alainjobart/vitess","homepage":null,"size":86616,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"youtube:master","ref":"master","sha":"6bb52c16687e2b1b5226180312fe6dfe8d37ce65","user":{"login":"youtube","id":4052902,"avatar_url":"https://avatars3.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"repo":{"id":11008207,"name":"vitess","full_name":"youtube/vitess","owner":{"login":"youtube","id":4052902,"avatar_url":"https://avatars3.githubusercontent.com/u/4052902?v=3","gravatar_id":"","url":"https://api.github.com/users/youtube","html_url":"https://github.com/youtube","followers_url":"https://api.github.com/users/youtube/followers","following_url":"https://api.github.com/users/youtube/following{/other_user}","gists_url":"https://api.github.com/users/youtube/gists{/gist_id}","starred_url":"https://api.github.com/users/youtube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youtube/subscriptions","organizations_url":"https://api.github.com/users/youtube/orgs","repos_url":"https://api.github.com/users/youtube/repos","events_url":"https://api.github.com/users/youtube/events{/privacy}","received_events_url":"https://api.github.com/users/youtube/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/youtube/vitess","description":"Vitess is a database clustering system for horizontal scaling of MySQL.","fork":false,"url":"https://api.github.com/repos/youtube/vitess","forks_url":"https://api.github.com/repos/youtube/vitess/forks","keys_url":"https://api.github.com/repos/youtube/vitess/keys{/key_id}","collaborators_url":"https://api.github.com/repos/youtube/vitess/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/youtube/vitess/teams","hooks_url":"https://api.github.com/repos/youtube/vitess/hooks","issue_events_url":"https://api.github.com/repos/youtube/vitess/issues/events{/number}","events_url":"https://api.github.com/repos/youtube/vitess/events","assignees_url":"https://api.github.com/repos/youtube/vitess/assignees{/user}","branches_url":"https://api.github.com/repos/youtube/vitess/branches{/branch}","tags_url":"https://api.github.com/repos/youtube/vitess/tags","blobs_url":"https://api.github.com/repos/youtube/vitess/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/youtube/vitess/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/youtube/vitess/git/refs{/sha}","trees_url":"https://api.github.com/repos/youtube/vitess/git/trees{/sha}","statuses_url":"https://api.github.com/repos/youtube/vitess/statuses/{sha}","languages_url":"https://api.github.com/repos/youtube/vitess/languages","stargazers_url":"https://api.github.com/repos/youtube/vitess/stargazers","contributors_url":"https://api.github.com/repos/youtube/vitess/contributors","subscribers_url":"https://api.github.com/repos/youtube/vitess/subscribers","subscription_url":"https://api.github.com/repos/youtube/vitess/subscription","commits_url":"https://api.github.com/repos/youtube/vitess/commits{/sha}","git_commits_url":"https://api.github.com/repos/youtube/vitess/git/commits{/sha}","comments_url":"https://api.github.com/repos/youtube/vitess/comments{/number}","issue_comment_url":"https://api.github.com/repos/youtube/vitess/issues/comments{/number}","contents_url":"https://api.github.com/repos/youtube/vitess/contents/{+path}","compare_url":"https://api.github.com/repos/youtube/vitess/compare/{base}...{head}","merges_url":"https://api.github.com/repos/youtube/vitess/merges","archive_url":"https://api.github.com/repos/youtube/vitess/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/youtube/vitess/downloads","issues_url":"https://api.github.com/repos/youtube/vitess/issues{/number}","pulls_url":"https://api.github.com/repos/youtube/vitess/pulls{/number}","milestones_url":"https://api.github.com/repos/youtube/vitess/milestones{/number}","notifications_url":"https://api.github.com/repos/youtube/vitess/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/youtube/vitess/labels{/name}","releases_url":"https://api.github.com/repos/youtube/vitess/releases{/id}","deployments_url":"https://api.github.com/repos/youtube/vitess/deployments","created_at":"2013-06-27T21:20:28Z","updated_at":"2017-07-07T22:20:20Z","pushed_at":"2017-07-08T03:19:43Z","git_url":"git://github.com/youtube/vitess.git","ssh_url":"git@github.com:youtube/vitess.git","clone_url":"https://github.com/youtube/vitess.git","svn_url":"https://github.com/youtube/vitess","homepage":"http://vitess.io","size":87537,"stargazers_count":4756,"watchers_count":4756,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":614,"mirror_url":null,"open_issues_count":97,"forks":614,"open_issues":97,"watchers":4756,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/youtube/vitess/pulls/2977"},"html":{"href":"https://github.com/youtube/vitess/pull/2977"},"issue":{"href":"https://api.github.com/repos/youtube/vitess/issues/2977"},"comments":{"href":"https://api.github.com/repos/youtube/vitess/issues/2977/comments"},"review_comments":{"href":"https://api.github.com/repos/youtube/vitess/pulls/2977/comments"},"review_comment":{"href":"https://api.github.com/repos/youtube/vitess/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/youtube/vitess/pulls/2977/commits"},"statuses":{"href":"https://api.github.com/repos/youtube/vitess/statuses/964a0cab22d6d1053ba4af4744d57e37e91e0ca0"}}}}
{"actor":{"display_login":"sougou"}}