Skip to content

Commit

Permalink
More corrections/tweaks
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Jun 1, 2023
1 parent bbbb351 commit 48e71a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go/test/endtoend/throttler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func WaitForThrottlerStatusEnabled(t *testing.T, tablet *cluster.Vttablet, enabl
tabletBody := getHTTPBody(tabletURL)
class := strings.ToLower(gjson.Get(tabletBody, "0.Class").String())
value := strings.ToLower(gjson.Get(tabletBody, "0.Value").String())
if class == "unhappy" && strings.Contains(value, "primary: not serving") {
if class == "unhappy" && strings.Contains(value, "not serving") {
log.Infof("tablet %s is Not Serving, so ignoring throttler status as the throttler will not be Opened", tablet.Alias)
return
}
Expand Down
18 changes: 11 additions & 7 deletions go/vt/vttablet/tabletserver/throttle/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func NewThrottler(env tabletenv.Env, srvTopoServer srvtopo.Server, ts *topo.Serv
// CheckIsReady checks if this throttler is ready to serve. If not, it
// returns an error.
func (throttler *Throttler) CheckIsReady() error {
if throttler.IsOpen() && throttler.IsEnabled() {
if throttler.IsRunning() {
// all good
return nil
}
Expand Down Expand Up @@ -318,24 +318,24 @@ func (throttler *Throttler) normalizeThrottlerConfig(thottlerConfig *topodatapb.
}

func (throttler *Throttler) WatchSrvKeyspaceCallback(srvks *topodatapb.SrvKeyspace, err error) bool {
throttler.initMutex.Lock()
defer throttler.initMutex.Unlock()
log.Infof("Throttler: WatchSrvKeyspaceCallback called with: %+v", srvks)
if err != nil {
log.Errorf("WatchSrvKeyspaceCallback error: %v", err)
return false
}
throttlerConfig := throttler.normalizeThrottlerConfig(srvks.ThrottlerConfig)

if throttler.IsOpen() {
// Throttler is open/running and we should apply the config change
if throttler.IsEnabled() {
// Throttler is enabled and we should apply the config change
// through Operate() or else we get into race conditions.
go func() {
log.Infof("Throttler: submitting a throttler config apply message with: %+v", throttlerConfig)
throttler.throttlerConfigChan <- throttlerConfig
}()
} else {
// Throttler is not open/running, we should apply directly.
throttler.initMutex.Lock()
defer throttler.initMutex.Unlock()
// Throttler is not enabled, we should apply directly.
throttler.applyThrottlerConfig(context.Background(), throttlerConfig)
}

Expand Down Expand Up @@ -460,7 +460,7 @@ func (throttler *Throttler) Open() error {
defer retryTicker.Stop()
for {
if !throttler.IsOpen() {
// Throttler is not open/running so no need to keep retrying.
// Throttler is not open so no need to keep retrying.
log.Errorf("Throttler.retryReadAndApplyThrottlerConfig(): throttler no longer seems to be open, exiting")
return
}
Expand Down Expand Up @@ -582,6 +582,10 @@ func (throttler *Throttler) isDormant() bool {
return time.Since(lastCheckTime) > dormantPeriod
}

func (throttler *Throttler) IsRunning() bool {
return throttler.IsOpen() && throttler.IsEnabled()
}

// Operate is the main entry point for the throttler operation and logic. It will
// run the probes, collect metrics, refresh inventory, etc.
func (throttler *Throttler) Operate(ctx context.Context) {
Expand Down

0 comments on commit 48e71a5

Please sign in to comment.