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] 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 }