Skip to content

Commit

Permalink
Keep retrying mysql port if it is 0 in Vttablets (#12986)
Browse files Browse the repository at this point in the history
* feat: keep retrying mysql port if it is 0

Signed-off-by: Manan Gupta <manan@planetscale.com>

* feat: add unit test for the changes

Signed-off-by: Manan Gupta <manan@planetscale.com>

---------

Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 authored May 2, 2023
1 parent caa8655 commit c5dced7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletmanager/tm_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ func (tm *TabletManager) findMysqlPort(retryInterval time.Duration) {
for {
time.Sleep(retryInterval)
mport, err := tm.MysqlDaemon.GetMysqlPort()
if err != nil {
if err != nil || mport == 0 {
continue
}
log.Infof("Identified mysql port: %v", mport)
Expand Down
17 changes: 13 additions & 4 deletions go/vt/vttablet/tabletmanager/tm_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,10 @@ func TestStartCheckMysql(t *testing.T) {
assert.Equal(t, "foo", ti.MysqlHostname)
}

// TestStartFindMysqlPort tests the functionality of findMySQLPort on tablet startup
func TestStartFindMysqlPort(t *testing.T) {
defer func(saved time.Duration) { mysqlPortRetryInterval = saved }(mysqlPortRetryInterval)
mysqlPortRetryInterval = 1 * time.Millisecond
mysqlPortRetryInterval = 50 * time.Millisecond

ctx := context.Background()
cell := "cell1"
Expand All @@ -446,16 +447,24 @@ func TestStartFindMysqlPort(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, int32(0), ti.MysqlPort)

fmd.MysqlPort.Store(3306)
go func() {
// We want to simulate the mysql daemon returning 0 for the port
// for some time before returning the correct value.
// We expect the vttablet to ignore the 0 value and eventually find the 3306 value.
time.Sleep(200 * time.Millisecond)
fmd.MysqlPort.Store(0)
time.Sleep(200 * time.Millisecond)
fmd.MysqlPort.Store(3306)
}()
for i := 0; i < 10; i++ {
ti, err := ts.GetTablet(ctx, tm.tabletAlias)
require.NoError(t, err)
if ti.MysqlPort == 3306 {
return
}
time.Sleep(5 * time.Millisecond)
time.Sleep(50 * time.Millisecond)
}
assert.Fail(t, "mysql port was not updated")
assert.Fail(t, "mysql port was not updated.", "Final value - %v", ti.MysqlPort)
}

// Init tablet fixes replication data when safe
Expand Down

0 comments on commit c5dced7

Please sign in to comment.