From e3fda9a22fa19ab6c65f1f730ae37d4408ab522a Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:12:16 +0300 Subject: [PATCH 1/2] Remove expired/unthrottled rules from topo rather than set them to 0 expiration duration Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/schemamanager/tablet_executor.go | 14 ++++++-------- go/vt/vtctl/grpcvtctldserver/server.go | 14 ++++++-------- go/vt/vtgate/vcursor_impl.go | 15 +++++++-------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/go/vt/schemamanager/tablet_executor.go b/go/vt/schemamanager/tablet_executor.go index 68270e0babc..c6befa4e743 100644 --- a/go/vt/schemamanager/tablet_executor.go +++ b/go/vt/schemamanager/tablet_executor.go @@ -249,14 +249,12 @@ func (exec *TabletExecutor) executeAlterMigrationThrottle(ctx context.Context, a throttlerConfig.ThrottledApps = make(map[string]*topodatapb.ThrottledAppRule) } if req.ThrottledApp != nil && req.ThrottledApp.Name != "" { - // TODO(shlomi) in v22: replace the following line with the commented out block - throttlerConfig.ThrottledApps[req.ThrottledApp.Name] = req.ThrottledApp - // timeNow := time.Now() - // if protoutil.TimeFromProto(req.ThrottledApp.ExpiresAt).After(timeNow) { - // throttlerConfig.ThrottledApps[req.ThrottledApp.Name] = req.ThrottledApp - // } else { - // delete(throttlerConfig.ThrottledApps, req.ThrottledApp.Name) - // } + timeNow := time.Now() + if protoutil.TimeFromProto(req.ThrottledApp.ExpiresAt).After(timeNow) { + throttlerConfig.ThrottledApps[req.ThrottledApp.Name] = req.ThrottledApp + } else { + delete(throttlerConfig.ThrottledApps, req.ThrottledApp.Name) + } } return throttlerConfig diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index e280a410e02..3c1a2dd537e 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -2096,14 +2096,12 @@ func (s *VtctldServer) UpdateThrottlerConfig(ctx context.Context, req *vtctldata throttlerConfig.CheckAsCheckSelf = false } if req.ThrottledApp != nil && req.ThrottledApp.Name != "" { - // TODO(shlomi) in v22: replace the following line with the commented out block - throttlerConfig.ThrottledApps[req.ThrottledApp.Name] = req.ThrottledApp - // timeNow := time.Now() - // if protoutil.TimeFromProto(req.ThrottledApp.ExpiresAt).After(timeNow) { - // throttlerConfig.ThrottledApps[req.ThrottledApp.Name] = req.ThrottledApp - // } else { - // delete(throttlerConfig.ThrottledApps, req.ThrottledApp.Name) - // } + timeNow := time.Now() + if protoutil.TimeFromProto(req.ThrottledApp.ExpiresAt).After(timeNow) { + throttlerConfig.ThrottledApps[req.ThrottledApp.Name] = req.ThrottledApp + } else { + delete(throttlerConfig.ThrottledApps, req.ThrottledApp.Name) + } } return throttlerConfig } diff --git a/go/vt/vtgate/vcursor_impl.go b/go/vt/vtgate/vcursor_impl.go index e9b1d3d7712..b916f171e05 100644 --- a/go/vt/vtgate/vcursor_impl.go +++ b/go/vt/vtgate/vcursor_impl.go @@ -30,6 +30,7 @@ import ( "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/mysql/config" "vitess.io/vitess/go/mysql/sqlerror" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/callerid" "vitess.io/vitess/go/vt/discovery" @@ -1343,14 +1344,12 @@ func (vc *vcursorImpl) ThrottleApp(ctx context.Context, throttledAppRule *topoda throttlerConfig.ThrottledApps = make(map[string]*topodatapb.ThrottledAppRule) } if req.ThrottledApp != nil && req.ThrottledApp.Name != "" { - // TODO(shlomi) in v22: replace the following line with the commented out block - throttlerConfig.ThrottledApps[req.ThrottledApp.Name] = req.ThrottledApp - // timeNow := time.Now() - // if protoutil.TimeFromProto(req.ThrottledApp.ExpiresAt).After(timeNow) { - // throttlerConfig.ThrottledApps[req.ThrottledApp.Name] = req.ThrottledApp - // } else { - // delete(throttlerConfig.ThrottledApps, req.ThrottledApp.Name) - // } + timeNow := time.Now() + if protoutil.TimeFromProto(req.ThrottledApp.ExpiresAt).After(timeNow) { + throttlerConfig.ThrottledApps[req.ThrottledApp.Name] = req.ThrottledApp + } else { + delete(throttlerConfig.ThrottledApps, req.ThrottledApp.Name) + } } return throttlerConfig } From 6018f43e26cdd5ec6aae80d21ab83d9b3ca0c90d Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:30:11 +0200 Subject: [PATCH 2/2] adapt test Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go b/go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go index f96069c81b8..e8297f0fa8f 100644 --- a/go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go +++ b/go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go @@ -429,7 +429,7 @@ func TestThrottleViaApplySchema(t *testing.T) { require.NotNil(t, keyspace.Keyspace.ThrottlerConfig.ThrottledApps) // ThrottledApps will actually be empty at this point, but more specifically we want to see that "online-ddl" is not there. appRule, ok := keyspace.Keyspace.ThrottlerConfig.ThrottledApps[throttlerapp.OnlineDDLName.String()] - assert.True(t, ok, "app rule: %v", appRule) + assert.False(t, ok, "app rule: %v", appRule) }) }