Skip to content
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

Add MakePrimary support to TxThrottler #17404

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
5 changes: 3 additions & 2 deletions go/vt/vttablet/tabletserver/query_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1862,8 +1862,9 @@ func (m mockTxThrottler) Open() (err error) {
return nil
}

func (m mockTxThrottler) Close() {
}
func (m mockTxThrottler) Close() {}
func (m mockTxThrottler) MakePrimary() {}
func (m mockTxThrottler) MakeNonPrimary() {}

func (m mockTxThrottler) Throttle(priority int, workload string) (result bool) {
return m.throttle
Expand Down
8 changes: 7 additions & 1 deletion go/vt/vttablet/tabletserver/state_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ type (
txThrottler interface {
Open() error
Close()
MakePrimary()
MakeNonPrimary()
}

onlineDDLExecutor interface {
Expand Down Expand Up @@ -457,6 +459,7 @@ func (sm *stateManager) servePrimary() error {
sm.hs.MakePrimary(true)
sm.se.MakePrimary(true)
sm.rt.MakePrimary()
sm.txThrottler.MakePrimary()
sm.tracker.Open()
// We instantly kill all stateful queries to allow for
// te to quickly transition into RW, but olap and stateless
Expand All @@ -483,6 +486,7 @@ func (sm *stateManager) unservePrimary() error {
sm.se.MakePrimary(false)
sm.hs.MakePrimary(false)
sm.rt.MakePrimary()
sm.txThrottler.MakePrimary()
sm.setState(topodatapb.TabletType_PRIMARY, StateNotServing)
return nil
}
Expand All @@ -499,6 +503,7 @@ func (sm *stateManager) serveNonPrimary(wantTabletType topodatapb.TabletType) er
sm.tracker.Close()
sm.se.MakeNonPrimary()
sm.hs.MakeNonPrimary()
sm.txThrottler.MakeNonPrimary()

if err := sm.connect(wantTabletType, true); err != nil {
return err
Expand All @@ -517,6 +522,7 @@ func (sm *stateManager) unserveNonPrimary(wantTabletType topodatapb.TabletType)

sm.se.MakeNonPrimary()
sm.hs.MakeNonPrimary()
sm.txThrottler.MakeNonPrimary()

if err := sm.connect(wantTabletType, false); err != nil {
return err
Expand All @@ -539,7 +545,7 @@ func (sm *stateManager) connect(tabletType topodatapb.TabletType, serving bool)
if err := sm.qe.Open(); err != nil {
return err
}
return sm.txThrottler.Open()
return nil
}

func (sm *stateManager) unserveCommon() {
Expand Down
89 changes: 52 additions & 37 deletions go/vt/vttablet/tabletserver/state_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ func TestStateManagerServePrimary(t *testing.T) {
assert.Equal(t, testNow, sm.ptsTimestamp)

verifySubcomponent(t, 1, sm.watcher, testStateClosed)

verifySubcomponent(t, 2, sm.se, testStateOpen)
verifySubcomponent(t, 3, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 4, sm.qe, testStateOpen)
verifySubcomponent(t, 5, sm.txThrottler, testStateOpen)
verifySubcomponent(t, 6, sm.rt, testStatePrimary)
verifySubcomponent(t, 5, sm.rt, testStatePrimary)
verifySubcomponent(t, 6, sm.txThrottler, testStatePrimary)
verifySubcomponent(t, 7, sm.tracker, testStateOpen)
verifySubcomponent(t, 8, sm.te, testStatePrimary)
verifySubcomponent(t, 9, sm.messager, testStateOpen)
Expand All @@ -109,10 +108,10 @@ func TestStateManagerServeNonPrimary(t *testing.T) {
verifySubcomponent(t, 4, sm.tracker, testStateClosed)
assert.True(t, sm.se.(*testSchemaEngine).nonPrimary)

verifySubcomponent(t, 5, sm.se, testStateOpen)
verifySubcomponent(t, 6, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 7, sm.qe, testStateOpen)
verifySubcomponent(t, 8, sm.txThrottler, testStateOpen)
verifySubcomponent(t, 5, sm.txThrottler, testStateNonPrimary)
verifySubcomponent(t, 6, sm.se, testStateOpen)
verifySubcomponent(t, 7, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 8, sm.qe, testStateOpen)
verifySubcomponent(t, 9, sm.te, testStateNonPrimary)
verifySubcomponent(t, 10, sm.rt, testStateNonPrimary)
verifySubcomponent(t, 11, sm.watcher, testStateOpen)
Expand All @@ -139,9 +138,9 @@ func TestStateManagerUnservePrimary(t *testing.T) {
verifySubcomponent(t, 8, sm.se, testStateOpen)
verifySubcomponent(t, 9, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 10, sm.qe, testStateOpen)
verifySubcomponent(t, 11, sm.txThrottler, testStateOpen)

verifySubcomponent(t, 12, sm.rt, testStatePrimary)
verifySubcomponent(t, 11, sm.rt, testStatePrimary)
verifySubcomponent(t, 12, sm.txThrottler, testStatePrimary)

assert.Equal(t, topodatapb.TabletType_PRIMARY, sm.target.TabletType)
assert.Equal(t, StateNotServing, sm.state)
Expand All @@ -162,10 +161,10 @@ func TestStateManagerUnserveNonPrimary(t *testing.T) {
verifySubcomponent(t, 6, sm.tracker, testStateClosed)
assert.True(t, sm.se.(*testSchemaEngine).nonPrimary)

verifySubcomponent(t, 7, sm.se, testStateOpen)
verifySubcomponent(t, 8, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 9, sm.qe, testStateOpen)
verifySubcomponent(t, 10, sm.txThrottler, testStateOpen)
verifySubcomponent(t, 7, sm.txThrottler, testStateNonPrimary)
verifySubcomponent(t, 8, sm.se, testStateOpen)
verifySubcomponent(t, 9, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 10, sm.qe, testStateOpen)

verifySubcomponent(t, 11, sm.rt, testStateNonPrimary)
verifySubcomponent(t, 12, sm.watcher, testStateOpen)
Expand Down Expand Up @@ -300,10 +299,10 @@ func TestStateManagerSetServingTypeNoChange(t *testing.T) {
verifySubcomponent(t, 4, sm.tracker, testStateClosed)
assert.True(t, sm.se.(*testSchemaEngine).nonPrimary)

verifySubcomponent(t, 5, sm.se, testStateOpen)
verifySubcomponent(t, 6, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 7, sm.qe, testStateOpen)
verifySubcomponent(t, 8, sm.txThrottler, testStateOpen)
verifySubcomponent(t, 5, sm.txThrottler, testStateNonPrimary)
verifySubcomponent(t, 6, sm.se, testStateOpen)
verifySubcomponent(t, 7, sm.vstreamer, testStateOpen)
verifySubcomponent(t, 8, sm.qe, testStateOpen)
verifySubcomponent(t, 9, sm.te, testStateNonPrimary)
verifySubcomponent(t, 10, sm.rt, testStateNonPrimary)
verifySubcomponent(t, 11, sm.watcher, testStateOpen)
Expand Down Expand Up @@ -819,7 +818,7 @@ func (te *testSchemaEngine) EnsureConnectionAndDB(topodatapb.TabletType, bool) e
}

func (te *testSchemaEngine) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}
Expand All @@ -833,7 +832,7 @@ func (te *testSchemaEngine) MakePrimary(serving bool) {
}

func (te *testSchemaEngine) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -844,17 +843,17 @@ type testReplTracker struct {
}

func (te *testReplTracker) MakePrimary() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStatePrimary
}

func (te *testReplTracker) MakeNonPrimary() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateNonPrimary
}

func (te *testReplTracker) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -869,7 +868,7 @@ type testQueryEngine struct {
}

func (te *testQueryEngine) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}
Expand All @@ -883,7 +882,7 @@ func (te *testQueryEngine) IsMySQLReachable() error {
}

func (te *testQueryEngine) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -892,17 +891,17 @@ type testTxEngine struct {
}

func (te *testTxEngine) AcceptReadWrite() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStatePrimary
}

func (te *testTxEngine) AcceptReadOnly() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateNonPrimary
}

func (te *testTxEngine) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -913,12 +912,12 @@ type testSubcomponent struct {
}

func (te *testSubcomponent) Open() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
}

func (te *testSubcomponent) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -927,28 +926,44 @@ type testTxThrottler struct {
}

func (te *testTxThrottler) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}

func (te *testTxThrottler) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

func (te *testTxThrottler) MakePrimary() {
te.order = addOrder()
te.state = testStatePrimary
}

func (te *testTxThrottler) MakeNonPrimary() {
te.order = addOrder()
te.state = testStateNonPrimary
}

func addOrder() int64 {
newVal := order.Add(1)

return newVal
}

type testOnlineDDLExecutor struct {
testOrderState
}

func (te *testOnlineDDLExecutor) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}

func (te *testOnlineDDLExecutor) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -957,13 +972,13 @@ type testLagThrottler struct {
}

func (te *testLagThrottler) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}

func (te *testLagThrottler) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}

Expand All @@ -972,12 +987,12 @@ type testTableGC struct {
}

func (te *testTableGC) Open() error {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateOpen
return nil
}

func (te *testTableGC) Close() {
te.order = order.Add(1)
te.order = addOrder()
te.state = testStateClosed
}
Loading
Loading