@@ -7617,6 +7617,7 @@ func TestGetTablets(t *testing.T) {
76177617 cells []string
76187618 unreachableCells []string // Cells that will return a ctx timeout error when trying to get tablets
76197619 tablets []* topodatapb.Tablet
7620+ addTabletOptions * testutil.AddTabletOptions
76207621 req * vtctldatapb.GetTabletsRequest
76217622 expected []* topodatapb.Tablet
76227623 shouldErr bool
@@ -8095,6 +8096,212 @@ func TestGetTablets(t *testing.T) {
80958096 },
80968097 shouldErr : false ,
80978098 },
8099+ {
8100+ name : "tablet alias filtering single stale primary stays unknown" ,
8101+ cells : []string {"zone1" },
8102+ tablets : []* topodatapb.Tablet {
8103+ {
8104+ Alias : & topodatapb.TabletAlias {
8105+ Cell : "zone1" ,
8106+ Uid : 100 ,
8107+ },
8108+ Hostname : "stale.primary" ,
8109+ Keyspace : "testkeyspace" ,
8110+ Shard : "-80" ,
8111+ Type : topodatapb .TabletType_PRIMARY ,
8112+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 14 , 4 , 5 , 0 , time .UTC )),
8113+ },
8114+ {
8115+ Alias : & topodatapb.TabletAlias {
8116+ Cell : "zone1" ,
8117+ Uid : 101 ,
8118+ },
8119+ Hostname : "true.primary" ,
8120+ Keyspace : "testkeyspace" ,
8121+ Shard : "-80" ,
8122+ Type : topodatapb .TabletType_PRIMARY ,
8123+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 16 , 4 , 5 , 0 , time .UTC )),
8124+ },
8125+ },
8126+ addTabletOptions : & testutil.AddTabletOptions {
8127+ AlsoSetShardPrimary : true ,
8128+ ForceSetShardPrimary : true ,
8129+ },
8130+ req : & vtctldatapb.GetTabletsRequest {
8131+ TabletAliases : []* topodatapb.TabletAlias {
8132+ {
8133+ Cell : "zone1" ,
8134+ Uid : 100 ,
8135+ },
8136+ },
8137+ },
8138+ expected : []* topodatapb.Tablet {
8139+ {
8140+ Alias : & topodatapb.TabletAlias {
8141+ Cell : "zone1" ,
8142+ Uid : 100 ,
8143+ },
8144+ Hostname : "stale.primary" ,
8145+ Keyspace : "testkeyspace" ,
8146+ Shard : "-80" ,
8147+ Type : topodatapb .TabletType_UNKNOWN ,
8148+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 14 , 4 , 5 , 0 , time .UTC )),
8149+ },
8150+ },
8151+ shouldErr : false ,
8152+ },
8153+ {
8154+ name : "tablet alias filtering stale primaries across shards stay unknown" ,
8155+ cells : []string {"zone1" },
8156+ tablets : []* topodatapb.Tablet {
8157+ {
8158+ Alias : & topodatapb.TabletAlias {
8159+ Cell : "zone1" ,
8160+ Uid : 100 ,
8161+ },
8162+ Hostname : "stale.primary.a" ,
8163+ Keyspace : "testkeyspace" ,
8164+ Shard : "-80" ,
8165+ Type : topodatapb .TabletType_PRIMARY ,
8166+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 14 , 4 , 5 , 0 , time .UTC )),
8167+ },
8168+ {
8169+ Alias : & topodatapb.TabletAlias {
8170+ Cell : "zone1" ,
8171+ Uid : 101 ,
8172+ },
8173+ Hostname : "true.primary.a" ,
8174+ Keyspace : "testkeyspace" ,
8175+ Shard : "-80" ,
8176+ Type : topodatapb .TabletType_PRIMARY ,
8177+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 16 , 4 , 5 , 0 , time .UTC )),
8178+ },
8179+ {
8180+ Alias : & topodatapb.TabletAlias {
8181+ Cell : "zone1" ,
8182+ Uid : 200 ,
8183+ },
8184+ Hostname : "stale.primary.b" ,
8185+ Keyspace : "testkeyspace" ,
8186+ Shard : "80-" ,
8187+ Type : topodatapb .TabletType_PRIMARY ,
8188+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 15 , 4 , 5 , 0 , time .UTC )),
8189+ },
8190+ {
8191+ Alias : & topodatapb.TabletAlias {
8192+ Cell : "zone1" ,
8193+ Uid : 201 ,
8194+ },
8195+ Hostname : "true.primary.b" ,
8196+ Keyspace : "testkeyspace" ,
8197+ Shard : "80-" ,
8198+ Type : topodatapb .TabletType_PRIMARY ,
8199+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 17 , 4 , 5 , 0 , time .UTC )),
8200+ },
8201+ },
8202+ addTabletOptions : & testutil.AddTabletOptions {
8203+ AlsoSetShardPrimary : true ,
8204+ ForceSetShardPrimary : true ,
8205+ },
8206+ req : & vtctldatapb.GetTabletsRequest {
8207+ TabletAliases : []* topodatapb.TabletAlias {
8208+ {
8209+ Cell : "zone1" ,
8210+ Uid : 100 ,
8211+ },
8212+ {
8213+ Cell : "zone1" ,
8214+ Uid : 200 ,
8215+ },
8216+ },
8217+ },
8218+ expected : []* topodatapb.Tablet {
8219+ {
8220+ Alias : & topodatapb.TabletAlias {
8221+ Cell : "zone1" ,
8222+ Uid : 100 ,
8223+ },
8224+ Hostname : "stale.primary.a" ,
8225+ Keyspace : "testkeyspace" ,
8226+ Shard : "-80" ,
8227+ Type : topodatapb .TabletType_UNKNOWN ,
8228+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 14 , 4 , 5 , 0 , time .UTC )),
8229+ },
8230+ {
8231+ Alias : & topodatapb.TabletAlias {
8232+ Cell : "zone1" ,
8233+ Uid : 200 ,
8234+ },
8235+ Hostname : "stale.primary.b" ,
8236+ Keyspace : "testkeyspace" ,
8237+ Shard : "80-" ,
8238+ Type : topodatapb .TabletType_UNKNOWN ,
8239+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 15 , 4 , 5 , 0 , time .UTC )),
8240+ },
8241+ },
8242+ shouldErr : false ,
8243+ },
8244+ {
8245+ name : "tablet alias filtering does not stale primaries across shards" ,
8246+ cells : []string {"zone1" },
8247+ tablets : []* topodatapb.Tablet {
8248+ {
8249+ Alias : & topodatapb.TabletAlias {
8250+ Cell : "zone1" ,
8251+ Uid : 100 ,
8252+ },
8253+ Keyspace : "testkeyspace" ,
8254+ Shard : "-80" ,
8255+ Type : topodatapb .TabletType_PRIMARY ,
8256+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 14 , 4 , 5 , 0 , time .UTC )),
8257+ },
8258+ {
8259+ Alias : & topodatapb.TabletAlias {
8260+ Cell : "zone1" ,
8261+ Uid : 200 ,
8262+ },
8263+ Keyspace : "testkeyspace" ,
8264+ Shard : "80-" ,
8265+ Type : topodatapb .TabletType_PRIMARY ,
8266+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 15 , 4 , 5 , 0 , time .UTC )),
8267+ },
8268+ },
8269+ req : & vtctldatapb.GetTabletsRequest {
8270+ TabletAliases : []* topodatapb.TabletAlias {
8271+ {
8272+ Cell : "zone1" ,
8273+ Uid : 100 ,
8274+ },
8275+ {
8276+ Cell : "zone1" ,
8277+ Uid : 200 ,
8278+ },
8279+ },
8280+ },
8281+ expected : []* topodatapb.Tablet {
8282+ {
8283+ Alias : & topodatapb.TabletAlias {
8284+ Cell : "zone1" ,
8285+ Uid : 100 ,
8286+ },
8287+ Keyspace : "testkeyspace" ,
8288+ Shard : "-80" ,
8289+ Type : topodatapb .TabletType_PRIMARY ,
8290+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 14 , 4 , 5 , 0 , time .UTC )),
8291+ },
8292+ {
8293+ Alias : & topodatapb.TabletAlias {
8294+ Cell : "zone1" ,
8295+ Uid : 200 ,
8296+ },
8297+ Keyspace : "testkeyspace" ,
8298+ Shard : "80-" ,
8299+ Type : topodatapb .TabletType_PRIMARY ,
8300+ PrimaryTermStartTime : protoutil .TimeToProto (time .Date (2006 , time .January , 2 , 15 , 4 , 5 , 0 , time .UTC )),
8301+ },
8302+ },
8303+ shouldErr : false ,
8304+ },
80988305 {
80998306 name : "tablet alias filter with none found" ,
81008307 tablets : []* topodatapb.Tablet {},
@@ -8264,7 +8471,7 @@ func TestGetTablets(t *testing.T) {
82648471 return NewVtctldServer (vtenv .NewTestEnv (), ts )
82658472 })
82668473
8267- testutil .AddTablets (ctx , t , ts , nil , tt .tablets ... )
8474+ testutil .AddTablets (ctx , t , ts , tt . addTabletOptions , tt .tablets ... )
82688475
82698476 for _ , cell := range tt .cells {
82708477 if slices .Contains (tt .unreachableCells , cell ) {
0 commit comments