Skip to content

Commit b0932ee

Browse files
committed
adjust the code
1 parent 3e95cd9 commit b0932ee

4 files changed

Lines changed: 30 additions & 25 deletions

File tree

‎maintainer/barrier.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Barrier struct {
4747
// and logs must stay in the same mode.
4848
mode int64
4949

50-
routeAdmin *routeAdmin
50+
routeAdmission tableRouteAdmission
5151
}
5252

5353
// NewBarrier create a new barrier for the changefeed
@@ -56,7 +56,7 @@ func NewBarrier(spanController *span.Controller,
5656
splitTableEnabled bool,
5757
bootstrapRespMap map[node.ID]*heartbeatpb.MaintainerBootstrapResponse,
5858
mode int64,
59-
routeAdmin *routeAdmin,
59+
routeAdmission tableRouteAdmission,
6060
) *Barrier {
6161
barrier := Barrier{
6262
blockedEvents: NewBlockEventMap(),
@@ -65,7 +65,7 @@ func NewBarrier(spanController *span.Controller,
6565
operatorController: operatorController,
6666
splitTableEnabled: splitTableEnabled,
6767
mode: mode,
68-
routeAdmin: routeAdmin,
68+
routeAdmission: routeAdmission,
6969
}
7070
barrier.handleBootstrapResponse(bootstrapRespMap)
7171
return &barrier
@@ -544,17 +544,17 @@ func (b *Barrier) tryScheduleEvent(event *BarrierEvent) bool {
544544
}
545545

546546
func (b *Barrier) precheckRouteEvent(event *BarrierEvent) (bool, error) {
547-
if b.routeAdmin == nil {
547+
if b.routeAdmission == nil {
548548
return true, nil
549549
}
550-
return b.routeAdmin.precheck(event.routeDDLInfo())
550+
return b.routeAdmission.precheck(event.routeAdmissionInfo())
551551
}
552552

553553
func (b *Barrier) applyRouteEvent(event *BarrierEvent) error {
554-
if b.routeAdmin == nil {
554+
if b.routeAdmission == nil {
555555
return nil
556556
}
557-
return b.routeAdmin.apply(event.routeDDLInfo())
557+
return b.routeAdmission.apply(event.routeAdmissionInfo())
558558
}
559559

560560
// ackEvent creates an ack event

‎maintainer/barrier_event.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ func NewBlockEvent(cfID common.ChangeFeedID,
146146
return event
147147
}
148148

149-
func (be *BarrierEvent) routeDDLInfo() routeDDLInfo {
150-
return routeDDLInfo{
149+
func (be *BarrierEvent) routeAdmissionInfo() routeAdmissionInfo {
150+
return routeAdmissionInfo{
151151
key: getEventKey(be.commitTs, be.isSyncPoint),
152152
commitTs: be.commitTs,
153153
isSyncPoint: be.isSyncPoint,

‎maintainer/route_admin.go‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ type routePendingEvent struct {
5353
prechecked bool
5454
}
5555

56-
type routeDDLInfo struct {
56+
type tableRouteAdmission interface {
57+
precheck(info routeAdmissionInfo) (bool, error)
58+
apply(info routeAdmissionInfo) error
59+
}
60+
61+
type routeAdmissionInfo struct {
5762
key eventKey
5863
commitTs uint64
5964
isSyncPoint bool
@@ -156,7 +161,7 @@ func (a *routeAdmin) applyAdmissionChange(change routeAdmissionChange, mutate bo
156161
return a.registry.ApplyTransition(change.releases, change.admits, mutate)
157162
}
158163

159-
func (a *routeAdmin) precheck(info routeDDLInfo) (bool, error) {
164+
func (a *routeAdmin) precheck(info routeAdmissionInfo) (bool, error) {
160165
if !a.needsCheck(info) {
161166
return true, nil
162167
}
@@ -193,7 +198,7 @@ func (a *routeAdmin) precheck(info routeDDLInfo) (bool, error) {
193198
return true, nil
194199
}
195200

196-
func (a *routeAdmin) apply(info routeDDLInfo) error {
201+
func (a *routeAdmin) apply(info routeAdmissionInfo) error {
197202
if !a.needsCheck(info) {
198203
return nil
199204
}
@@ -222,7 +227,7 @@ func (a *routeAdmin) apply(info routeDDLInfo) error {
222227
return nil
223228
}
224229

225-
func (a *routeAdmin) needsCheck(info routeDDLInfo) bool {
230+
func (a *routeAdmin) needsCheck(info routeAdmissionInfo) bool {
226231
if a == nil || a.registry == nil || info.isSyncPoint {
227232
return false
228233
}
@@ -232,7 +237,7 @@ func (a *routeAdmin) needsCheck(info routeDDLInfo) bool {
232237
return info.blockTables != nil && len(info.blockTables.TableIDs) > 0
233238
}
234239

235-
func (a *routeAdmin) getOrBuildPendingEvent(info routeDDLInfo) (*routePendingEvent, bool, error) {
240+
func (a *routeAdmin) getOrBuildPendingEvent(info routeAdmissionInfo) (*routePendingEvent, bool, error) {
236241
if pending, ok := a.pendingEvents[info.key]; ok {
237242
return pending, true, nil
238243
}
@@ -264,7 +269,7 @@ func (a *routeAdmin) popPendingHead(key eventKey) {
264269
delete(a.pendingEvents, key)
265270
}
266271

267-
func (a *routeAdmin) buildTransition(info routeDDLInfo) (*routeTransition, error) {
272+
func (a *routeAdmin) buildTransition(info routeAdmissionInfo) (*routeTransition, error) {
268273
builder := newRouteTransitionBuilder(info.commitTs)
269274

270275
if info.droppedTables != nil {

‎maintainer/route_admin_test.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestRouteAdminPrecheckReportsConflict(t *testing.T) {
3535
reportedErr = err
3636
}
3737

38-
info := routeDDLInfo{
38+
info := routeAdmissionInfo{
3939
key: getEventKey(10, false),
4040
commitTs: 10,
4141
addedTables: []*heartbeatpb.Table{
@@ -58,7 +58,7 @@ func TestRouteAdminPrecheckReportsConflict(t *testing.T) {
5858
func TestRouteAdminApplyUpdatesRegistry(t *testing.T) {
5959
admin := newTestRouteAdmin(t, routing.SchemaPlaceholder+"_target", routing.TablePlaceholder)
6060

61-
info := routeDDLInfo{
61+
info := routeAdmissionInfo{
6262
key: getEventKey(10, false),
6363
commitTs: 10,
6464
addedTables: []*heartbeatpb.Table{
@@ -85,7 +85,7 @@ func TestRouteAdminReadsNewTableBeforeDispatcherRegistration(t *testing.T) {
8585
store.AppendDDLEvent(3, routeTableInfoDDL(3, "db3", "t"))
8686
store.RequireRegisteredTablesForGetTableInfo()
8787

88-
info := routeDDLInfo{
88+
info := routeAdmissionInfo{
8989
key: getEventKey(10, false),
9090
commitTs: 10,
9191
addedTables: []*heartbeatpb.Table{
@@ -101,7 +101,7 @@ func TestRouteAdminReadsNewTableBeforeDispatcherRegistration(t *testing.T) {
101101
func TestRouteAdminIgnoresDDLSpanInBlockTables(t *testing.T) {
102102
admin := newTestRouteAdmin(t, routing.SchemaPlaceholder+"_target", routing.TablePlaceholder)
103103

104-
info := routeDDLInfo{
104+
info := routeAdmissionInfo{
105105
key: getEventKey(10, false),
106106
commitTs: 10,
107107
blockTables: &heartbeatpb.InfluencedTables{
@@ -124,7 +124,7 @@ func TestRouteAdminIgnoresDDLSpanInBlockTables(t *testing.T) {
124124
func TestRouteAdminDropReleasesBootstrapBinding(t *testing.T) {
125125
admin := newTestRouteAdmin(t, "target", routing.TablePlaceholder)
126126

127-
dropInfo := routeDDLInfo{
127+
dropInfo := routeAdmissionInfo{
128128
key: getEventKey(10, false),
129129
commitTs: 10,
130130
droppedTables: &heartbeatpb.InfluencedTables{
@@ -140,7 +140,7 @@ func TestRouteAdminDropReleasesBootstrapBinding(t *testing.T) {
140140
_, ok := admin.tableSources[1]
141141
require.False(t, ok)
142142

143-
addInfo := routeDDLInfo{
143+
addInfo := routeAdmissionInfo{
144144
key: getEventKey(20, false),
145145
commitTs: 20,
146146
addedTables: []*heartbeatpb.Table{
@@ -161,7 +161,7 @@ func TestRouteAdminTracksSourceAdmissionNotTableID(t *testing.T) {
161161

162162
source := routing.TableKey{Schema: "db1", Table: "t"}
163163

164-
addSameSourceInfo := routeDDLInfo{
164+
addSameSourceInfo := routeAdmissionInfo{
165165
key: getEventKey(10, false),
166166
commitTs: 10,
167167
addedTables: []*heartbeatpb.Table{
@@ -174,7 +174,7 @@ func TestRouteAdminTracksSourceAdmissionNotTableID(t *testing.T) {
174174
require.NoError(t, admin.apply(addSameSourceInfo))
175175
require.Equal(t, 2, admin.sourceRefs[source])
176176

177-
dropOnePhysicalIDInfo := routeDDLInfo{
177+
dropOnePhysicalIDInfo := routeAdmissionInfo{
178178
key: getEventKey(20, false),
179179
commitTs: 20,
180180
droppedTables: &heartbeatpb.InfluencedTables{
@@ -192,7 +192,7 @@ func TestRouteAdminTracksSourceAdmissionNotTableID(t *testing.T) {
192192
_, ok = admin.tableSources[3]
193193
require.True(t, ok)
194194

195-
truncateInfo := routeDDLInfo{
195+
truncateInfo := routeAdmissionInfo{
196196
key: getEventKey(30, false),
197197
commitTs: 30,
198198
droppedTables: &heartbeatpb.InfluencedTables{
@@ -213,7 +213,7 @@ func TestRouteAdminTracksSourceAdmissionNotTableID(t *testing.T) {
213213
_, ok = admin.tableSources[4]
214214
require.True(t, ok)
215215

216-
conflictInfo := routeDDLInfo{
216+
conflictInfo := routeAdmissionInfo{
217217
key: getEventKey(40, false),
218218
commitTs: 40,
219219
addedTables: []*heartbeatpb.Table{

0 commit comments

Comments
 (0)