-
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
Reroute 'ALTER VITESS_MIGRATION ... THROTTLE ...' through topo #13511
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ import ( | |
"vitess.io/vitess/go/vt/log" | ||
"vitess.io/vitess/go/vt/schema" | ||
"vitess.io/vitess/go/vt/sqlparser" | ||
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/throttlerapp" | ||
|
||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
"vitess.io/vitess/go/test/endtoend/onlineddl" | ||
|
@@ -539,6 +540,8 @@ func testScheduler(t *testing.T) { | |
t.Run("ALTER both tables, elligible for concurrenct, with throttling", func(t *testing.T) { | ||
onlineddl.ThrottleAllMigrations(t, &vtParams) | ||
defer onlineddl.UnthrottleAllMigrations(t, &vtParams) | ||
onlineddl.CheckThrottledApps(t, &vtParams, throttlerapp.OnlineDDLName, true) | ||
|
||
// ALTER TABLE is allowed to run concurrently when no other ALTER is busy with copy state. Our tables are tiny so we expect to find both migrations running | ||
t1uuid = testOnlineDDLStatement(t, createParams(trivialAlterT1Statement, ddlStrategy+" -allow-concurrent -postpone-completion", "vtgate", "", "", true)) // skip wait | ||
t2uuid = testOnlineDDLStatement(t, createParams(trivialAlterT2Statement, ddlStrategy+" -allow-concurrent -postpone-completion", "vtgate", "", "", true)) // skip wait | ||
|
@@ -555,6 +558,8 @@ func testScheduler(t *testing.T) { | |
onlineddl.CheckMigrationStatus(t, &vtParams, shards, t1uuid, schema.OnlineDDLStatusRunning) | ||
onlineddl.CheckMigrationStatus(t, &vtParams, shards, t2uuid, schema.OnlineDDLStatusQueued, schema.OnlineDDLStatusReady) | ||
}) | ||
onlineddl.CheckThrottledApps(t, &vtParams, throttlerapp.OnlineDDLName, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a "wait-for", because |
||
|
||
t.Run("check ready to complete (before)", func(t *testing.T) { | ||
for _, uuid := range []string{t1uuid, t2uuid} { | ||
rs := onlineddl.ReadMigrations(t, &vtParams, uuid) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,14 @@ import ( | |
|
||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
|
||
"github.com/buger/jsonparser" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
ThrottledAppsTimeout = 60 * time.Second | ||
) | ||
|
||
// VtgateExecQuery runs a query on VTGate using given query params | ||
func VtgateExecQuery(t *testing.T, vtParams *mysql.ConnParams, query string, expectError string) *sqltypes.Result { | ||
t.Helper() | ||
|
@@ -313,16 +316,35 @@ func UnthrottleAllMigrations(t *testing.T, vtParams *mysql.ConnParams) { | |
|
||
// CheckThrottledApps checks for existence or non-existence of an app in the throttled apps list | ||
func CheckThrottledApps(t *testing.T, vtParams *mysql.ConnParams, throttlerApp throttlerapp.Name, expectFind bool) { | ||
query := "show vitess_throttled_apps" | ||
r := VtgateExecQuery(t, vtParams, query, "") | ||
|
||
found := false | ||
for _, row := range r.Named().Rows { | ||
if throttlerApp.Equals(row.AsString("app", "")) { | ||
found = true | ||
ctx, cancel := context.WithTimeout(context.Background(), ThrottledAppsTimeout) | ||
defer cancel() | ||
|
||
ticker := time.NewTicker(time.Second) | ||
defer ticker.Stop() | ||
|
||
for { | ||
query := "show vitess_throttled_apps" | ||
r := VtgateExecQuery(t, vtParams, query, "") | ||
|
||
appFound := false | ||
for _, row := range r.Named().Rows { | ||
if throttlerApp.Equals(row.AsString("app", "")) { | ||
appFound = true | ||
} | ||
} | ||
if appFound == expectFind { | ||
// we're all good | ||
return | ||
} | ||
|
||
select { | ||
case <-ctx.Done(): | ||
assert.Failf(t, "CheckThrottledApps timed out waiting for %v to be in throttled status '%v'", throttlerApp.String(), expectFind) | ||
return | ||
case <-ticker.C: | ||
} | ||
} | ||
assert.Equal(t, expectFind, found, "check app %v in throttled apps: %v", throttlerApp, found) | ||
} | ||
|
||
// WaitForThrottledTimestamp waits for a migration to have a non-empty last_throttled_timestamp | ||
|
@@ -350,33 +372,6 @@ func WaitForThrottledTimestamp(t *testing.T, vtParams *mysql.ConnParams, uuid st | |
return | ||
} | ||
|
||
// WaitForThrottlerStatusEnabled waits for a tablet to report its throttler status as enabled. | ||
func WaitForThrottlerStatusEnabled(t *testing.T, tablet *cluster.Vttablet, timeout time.Duration) { | ||
jsonPath := "IsEnabled" | ||
url := fmt.Sprintf("http://localhost:%d/throttler/status", tablet.HTTPPort) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), throttlerConfigTimeout) | ||
defer cancel() | ||
|
||
ticker := time.NewTicker(time.Second) | ||
defer ticker.Stop() | ||
|
||
for { | ||
body := getHTTPBody(url) | ||
val, err := jsonparser.GetBoolean([]byte(body), jsonPath) | ||
require.NoError(t, err) | ||
if val { | ||
return | ||
} | ||
select { | ||
case <-ctx.Done(): | ||
t.Error("timeout waiting for tablet's throttler status to be enabled") | ||
return | ||
case <-ticker.C: | ||
} | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This here is just code I found was unused. |
||
func getHTTPBody(url string) string { | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,19 +210,23 @@ func UnthrottleApp(clusterInstance *cluster.LocalProcessCluster, throttlerApp th | |
return throttleApp(clusterInstance, throttlerApp, false) | ||
} | ||
|
||
// ThrottleAppAndWaitUntilTabletsConfirm | ||
func ThrottleAppAndWaitUntilTabletsConfirm(t *testing.T, clusterInstance *cluster.LocalProcessCluster, throttlerApp throttlerapp.Name) (string, error) { | ||
res, err := throttleApp(clusterInstance, throttlerApp, true) | ||
if err != nil { | ||
return res, err | ||
} | ||
func WaitUntilTabletsConfirmThrottledApp(t *testing.T, clusterInstance *cluster.LocalProcessCluster, throttlerApp throttlerapp.Name, expectThrottled bool) { | ||
for _, ks := range clusterInstance.Keyspaces { | ||
for _, shard := range ks.Shards { | ||
for _, tablet := range shard.Vttablets { | ||
WaitForThrottledApp(t, tablet, throttlerApp, true, ConfigTimeout) | ||
WaitForThrottledApp(t, tablet, throttlerApp, expectThrottled, ConfigTimeout) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// ThrottleAppAndWaitUntilTabletsConfirm | ||
func ThrottleAppAndWaitUntilTabletsConfirm(t *testing.T, clusterInstance *cluster.LocalProcessCluster, throttlerApp throttlerapp.Name) (string, error) { | ||
res, err := throttleApp(clusterInstance, throttlerApp, true) | ||
if err != nil { | ||
return res, err | ||
} | ||
WaitUntilTabletsConfirmThrottledApp(t, clusterInstance, throttlerApp, true) | ||
return res, nil | ||
} | ||
|
||
|
@@ -232,13 +236,7 @@ func UnthrottleAppAndWaitUntilTabletsConfirm(t *testing.T, clusterInstance *clus | |
if err != nil { | ||
return res, err | ||
} | ||
for _, ks := range clusterInstance.Keyspaces { | ||
for _, shard := range ks.Shards { | ||
for _, tablet := range shard.Vttablets { | ||
WaitForThrottledApp(t, tablet, throttlerApp, false, ConfigTimeout) | ||
} | ||
} | ||
} | ||
WaitUntilTabletsConfirmThrottledApp(t, clusterInstance, throttlerApp, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes in this file are just a simple refactor into a function. Not really related to the overall changes in the PR. |
||
return res, 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.
Adding a "wait-for", because
onlineddl.ThrottleAllMigrations
is now an async flow.