Skip to content

Commit

Permalink
vttablet tx throttler: healthcheck all cells if cells unspecified
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
  • Loading branch information
timvaillancourt committed Feb 24, 2023
1 parent 1fecb5d commit 6beae70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/txthrottler/tx_throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func tryCreateTxThrottler(config *tabletenv.TabletConfig, topoServer *topo.Serve
if len(config.TxThrottlerHealthCheckCells) > 0 {
// Clone tsv.TxThrottlerHealthCheckCells so that we don't assume tsv.TxThrottlerHealthCheckCells
// is immutable.
healthCheckCells := make([]string, len(config.TxThrottlerHealthCheckCells))
healthCheckCells = make([]string, len(config.TxThrottlerHealthCheckCells))
copy(healthCheckCells, config.TxThrottlerHealthCheckCells)
} else {
ctx, cancel := context.WithTimeout(context.Background(), topo.RemoteOperationTimeout)
Expand Down
30 changes: 29 additions & 1 deletion go/vt/vttablet/tabletserver/txthrottler/tx_throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"vitess.io/vitess/go/vt/discovery"
"vitess.io/vitess/go/vt/topo"
Expand Down Expand Up @@ -58,7 +59,7 @@ func TestEnabledThrottler(t *testing.T) {
defer mockCtrl.Finish()

defer resetTxThrottlerFactories()
ts := memorytopo.NewServer("cell1", "cell2")
ts := memorytopo.NewServer("cell1", "cell2", "cell3")

mockHealthCheck := NewMockHealthCheck(mockCtrl)
hcCall1 := mockHealthCheck.EXPECT().Subscribe()
Expand Down Expand Up @@ -144,3 +145,30 @@ func TestEnabledThrottler(t *testing.T) {
}
throttler.Close()
}

func TestTryCreateTxThrottler(t *testing.T) {
allCells := []string{"cell1", "cell2", "cell3"}
ts := memorytopo.NewServer(allCells...)

// Check specified cells are used for healthchecks
{
config := tabletenv.NewDefaultConfig()
config.EnableTxThrottler = true
config.TxThrottlerHealthCheckCells = []string{"cell1"}

txThrottler, err := tryCreateTxThrottler(config, ts)
assert.Nil(t, err)
assert.Equal(t, config.TxThrottlerHealthCheckCells, txThrottler.config.healthCheckCells)
}
// Check tx throttler uses all known cells for healthchecks
// when TxThrottlerHealthCheckCells is empty/undef
{
config := tabletenv.NewDefaultConfig()
config.EnableTxThrottler = true
config.TxThrottlerHealthCheckCells = []string{} // empty

txThrottler, err := tryCreateTxThrottler(config, ts)
assert.Nil(t, err)
assert.Equal(t, allCells, txThrottler.config.healthCheckCells)
}
}

0 comments on commit 6beae70

Please sign in to comment.