Skip to content

Commit 2eba9ef

Browse files
elhimovdmyger
authored andcommitted
cartridge: fix discovery to avoid missing aliases
Implementation of cartridge bootstrap in `tt` needs to know aliases of all instances to work properly. Aliases of instances are managed with `membership` module which spreads out certain instance alias across the rest of instances using `gossip` protocol. At the very start of an instance only that instance "knows" its alias, others get this knowledge with some delay. That means in turn that the topology obtained from the different instances might differ in terms of aliases. Prior to this patch topology from a single instance was used and if at that moment this instance haven't collected information about all the aliases, bootstrap failed. Now if any alias is missing we are trying to get it from the topologies obtained from the other instances until all aliases are resolved. The patch fixes flaky test so there is not need to introduce new tests. Closes #TNTP-3709
1 parent dc35274 commit 2eba9ef

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

cli/replicaset/cartridge.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,16 @@ func (c *CartridgeApplication) discovery() (Replicasets, error) {
245245
}
246246
if topology.IsBootstrapped {
247247
if newTopology.IsBootstrapped {
248+
updateInstancesAliases(newTopology.Replicasets, topology.Replicasets)
248249
topology = newTopology
249250
}
250251
} else {
251252
topology = newTopology
252253
}
253254

254255
// Stop if we already found a valid topology.
255-
return topology.IsBootstrapped && !topology.IsCritical, nil
256+
return topology.IsBootstrapped && !topology.IsCritical &&
257+
!hasMissingInstancesAliases(topology.Replicasets), nil
256258
},
257259
))
258260
if err != nil {
@@ -271,6 +273,37 @@ func (c *CartridgeApplication) discovery() (Replicasets, error) {
271273
return recalculateMasters(replicasets), err
272274
}
273275

276+
// hasMissingInstancesAliases checks if any instance has empty alias.
277+
func hasMissingInstancesAliases(replicasets []Replicaset) bool {
278+
for _, rs := range replicasets {
279+
for _, inst := range rs.Instances {
280+
if len(inst.Alias) == 0 {
281+
return true
282+
}
283+
}
284+
}
285+
return false
286+
}
287+
288+
// updateInstancesAliases tries to update missing instances aliases with another instances data.
289+
func updateInstancesAliases(replicasets, other []Replicaset) {
290+
instAliases := make(map[string]string, 0)
291+
for _, rs := range other {
292+
for _, inst := range rs.Instances {
293+
instAliases[inst.UUID] = inst.Alias
294+
}
295+
}
296+
for i, rs := range replicasets {
297+
for ii, inst := range rs.Instances {
298+
if len(inst.Alias) == 0 {
299+
if alias, ok := instAliases[inst.UUID]; ok && len(alias) > 0 {
300+
replicasets[i].Instances[ii].Alias = alias
301+
}
302+
}
303+
}
304+
}
305+
}
306+
274307
// Promote promotes an instance in the cartridge application.
275308
func (c *CartridgeApplication) Promote(ctx PromoteCtx) error {
276309
replicasets, err := c.Discovery(UseCache)

0 commit comments

Comments
 (0)