diff --git a/go/vt/vtctl/reparentutil/replication_test.go b/go/vt/vtctl/reparentutil/replication_test.go index 01f043ac827..2c875d3252e 100644 --- a/go/vt/vtctl/reparentutil/replication_test.go +++ b/go/vt/vtctl/reparentutil/replication_test.go @@ -289,6 +289,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { tabletToWaitFor *topodatapb.TabletAlias expectedStatusMap map[string]*replicationdatapb.StopReplicationStatus expectedPrimaryStatusMap map[string]*replicationdatapb.PrimaryStatus + expectedTakingBackup map[string]bool expectedTabletsReachable []*topodatapb.Tablet shouldErr bool }{ @@ -345,6 +346,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { After: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-9"}, }, }, + expectedTakingBackup: map[string]bool{"zone1-0000000100": false, "zone1-0000000101": false}, expectedPrimaryStatusMap: map[string]*replicationdatapb.PrimaryStatus{}, expectedTabletsReachable: []*topodatapb.Tablet{{ Type: topodatapb.TabletType_REPLICA, @@ -438,6 +440,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { After: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-9"}, }, }, + expectedTakingBackup: map[string]bool{"zone1-0000000100": false, "zone1-0000000101": false}, expectedPrimaryStatusMap: map[string]*replicationdatapb.PrimaryStatus{}, expectedTabletsReachable: []*topodatapb.Tablet{{ Type: topodatapb.TabletType_REPLICA, @@ -531,6 +534,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { After: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-9"}, }, }, + expectedTakingBackup: map[string]bool{"zone1-0000000100": false, "zone1-0000000101": false}, expectedPrimaryStatusMap: map[string]*replicationdatapb.PrimaryStatus{}, expectedTabletsReachable: []*topodatapb.Tablet{{ Type: topodatapb.TabletType_REPLICA, @@ -603,6 +607,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { Uid: 101, }, }}, + expectedTakingBackup: map[string]bool{"zone1-0000000101": false}, expectedPrimaryStatusMap: map[string]*replicationdatapb.PrimaryStatus{}, shouldErr: false, }, @@ -664,6 +669,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { After: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-9"}, }, }, + expectedTakingBackup: map[string]bool{"zone1-0000000101": false}, expectedPrimaryStatusMap: map[string]*replicationdatapb.PrimaryStatus{ "zone1-0000000100": { Position: "primary-position-100", @@ -731,7 +737,8 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { }, }, }, - ignoredTablets: sets.NewString(), + ignoredTablets: sets.NewString(), + expectedTakingBackup: map[string]bool{"zone1-0000000101": false}, expectedStatusMap: map[string]*replicationdatapb.StopReplicationStatus{ "zone1-0000000101": { Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning)}, @@ -796,6 +803,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { }, }, ignoredTablets: sets.NewString(), + expectedTakingBackup: nil, expectedStatusMap: nil, expectedPrimaryStatusMap: nil, expectedTabletsReachable: nil, @@ -846,8 +854,9 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { }, }, }, - stopReplicasTimeout: time.Millisecond * 5, - ignoredTablets: sets.NewString(), + stopReplicasTimeout: time.Millisecond * 5, + ignoredTablets: sets.NewString(), + expectedTakingBackup: map[string]bool{"zone1-0000000101": false}, expectedStatusMap: map[string]*replicationdatapb.StopReplicationStatus{ "zone1-0000000101": { Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning)}, @@ -910,6 +919,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { After: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-9"}, }, }, + expectedTakingBackup: map[string]bool{"zone1-0000000101": false}, expectedPrimaryStatusMap: map[string]*replicationdatapb.PrimaryStatus{}, expectedTabletsReachable: []*topodatapb.Tablet{{ Type: topodatapb.TabletType_REPLICA, @@ -957,6 +967,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { }, }, ignoredTablets: sets.NewString(), + expectedTakingBackup: nil, expectedStatusMap: nil, expectedPrimaryStatusMap: nil, expectedTabletsReachable: nil, @@ -1001,6 +1012,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { }, }, ignoredTablets: sets.NewString(), + expectedTakingBackup: nil, expectedStatusMap: nil, expectedPrimaryStatusMap: nil, expectedTabletsReachable: nil, @@ -1105,9 +1117,150 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { }, }}, stopReplicasTimeout: time.Minute, + expectedTakingBackup: map[string]bool{"zone1-0000000100": false, "zone1-0000000101": false, "zone1-0000000102": false}, expectedPrimaryStatusMap: map[string]*replicationdatapb.PrimaryStatus{}, shouldErr: false, }, + { + name: "success - but nil replication status after. No segfaulting when determining backup status", + durability: "none", + tmc: &stopReplicationAndBuildStatusMapsTestTMClient{ + stopReplicationAndGetStatusResults: map[string]*struct { + StopStatus *replicationdatapb.StopReplicationStatus + Err error + }{ + "zone1-0000000100": { + StopStatus: &replicationdatapb.StopReplicationStatus{ + Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429100:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning), BackupRunning: true}, + After: nil, + }, + }, + "zone1-0000000101": { + StopStatus: &replicationdatapb.StopReplicationStatus{ + Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning), BackupRunning: true}, + After: nil, + }, + }, + }, + }, + tabletMap: map[string]*topo.TabletInfo{ + "zone1-0000000100": { + Tablet: &topodatapb.Tablet{ + Type: topodatapb.TabletType_REPLICA, + Alias: &topodatapb.TabletAlias{ + Cell: "zone1", + Uid: 100, + }, + }, + }, + "zone1-0000000101": { + Tablet: &topodatapb.Tablet{ + Type: topodatapb.TabletType_REPLICA, + Alias: &topodatapb.TabletAlias{ + Cell: "zone1", + Uid: 101, + }, + }, + }, + }, + ignoredTablets: sets.NewString(), + expectedStatusMap: map[string]*replicationdatapb.StopReplicationStatus{ + "zone1-0000000100": { + Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429100:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning), BackupRunning: true}, + After: nil, + }, + "zone1-0000000101": { + Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning), BackupRunning: true}, + After: nil, + }, + }, + expectedTakingBackup: map[string]bool{"zone1-0000000100": true, "zone1-0000000101": true}, + expectedPrimaryStatusMap: map[string]*replicationdatapb.PrimaryStatus{}, + expectedTabletsReachable: []*topodatapb.Tablet{{ + Type: topodatapb.TabletType_REPLICA, + Alias: &topodatapb.TabletAlias{ + Cell: "zone1", + Uid: 100, + }, + }, { + Type: topodatapb.TabletType_REPLICA, + Alias: &topodatapb.TabletAlias{ + Cell: "zone1", + Uid: 101, + }, + }}, + shouldErr: false, + }, + { + name: "Handle nil After replication status for determining backup status", + durability: "none", + tmc: &stopReplicationAndBuildStatusMapsTestTMClient{ + stopReplicationAndGetStatusResults: map[string]*struct { + StopStatus *replicationdatapb.StopReplicationStatus + Err error + }{ + "zone1-0000000100": { + StopStatus: &replicationdatapb.StopReplicationStatus{ + Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429100:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning), BackupRunning: true}, + After: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429100:1-9"}, + }, + }, + "zone1-0000000101": { + StopStatus: &replicationdatapb.StopReplicationStatus{ + Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning), BackupRunning: false}, + After: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-9"}, + }, + }, + }, + }, + tabletMap: map[string]*topo.TabletInfo{ + "zone1-0000000100": { + Tablet: &topodatapb.Tablet{ + Type: topodatapb.TabletType_REPLICA, + Alias: &topodatapb.TabletAlias{ + Cell: "zone1", + Uid: 100, + }, + }, + }, + "zone1-0000000101": { + Tablet: &topodatapb.Tablet{ + Type: topodatapb.TabletType_REPLICA, + Alias: &topodatapb.TabletAlias{ + Cell: "zone1", + Uid: 101, + }, + }, + }, + }, + ignoredTablets: sets.NewString(), + expectedStatusMap: map[string]*replicationdatapb.StopReplicationStatus{ + "zone1-0000000100": { + Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429100:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning), BackupRunning: true}, + After: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429100:1-9"}, + }, + "zone1-0000000101": { + Before: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-5", IoState: int32(mysql.ReplicationStateRunning), SqlState: int32(mysql.ReplicationStateRunning), BackupRunning: false}, + After: &replicationdatapb.Status{Position: "MySQL56/3E11FA47-71CA-11E1-9E33-C80AA9429101:1-9"}, + }, + }, + expectedTakingBackup: map[string]bool{"zone1-0000000100": false, "zone1-0000000101": false}, + expectedPrimaryStatusMap: map[string]*replicationdatapb.PrimaryStatus{}, + expectedTabletsReachable: []*topodatapb.Tablet{{ + Type: topodatapb.TabletType_REPLICA, + Alias: &topodatapb.TabletAlias{ + Cell: "zone1", + Uid: 100, + }, + }, { + Type: topodatapb.TabletType_REPLICA, + Alias: &topodatapb.TabletAlias{ + Cell: "zone1", + Uid: 101, + }, + }}, + shouldErr: false, + }, } for _, tt := range tests { @@ -1129,6 +1282,7 @@ func Test_stopReplicationAndBuildStatusMaps(t *testing.T) { for idx, tablet := range res.reachableTablets { assert.True(t, topoproto.IsTabletInList(tablet, tt.expectedTabletsReachable), "TabletsReached[%d] not found - %s", idx, topoproto.TabletAliasString(tablet.Alias)) } + assert.Equal(t, tt.expectedTakingBackup, res.tabletsBackupState) }) } }