Fix bug for adding preferred endpoint when non existed prior. (#1692)

This commit is contained in:
Todd authored and GitHub committed 2021-11-12 09:04:48 -07:00
1 parent f41bceda83
commit 5cfcc41f00
2 files changed
+426 -368

No files matched your search

+18 -16
View File
@@ -410,23 +410,25 @@ func (r *Repository) UpdateSet(ctx context.Context, scopeId string, s *HostSet,
}
case endpointOpUpdate:
// Delete all old endpoint entries.
var peps []interface{}
for i := 1; i <= len(currentSet.PreferredEndpoints); i++ {
p := host.AllocPreferredEndpoint()
p.HostSetId, p.Priority = currentSet.GetPublicId(), uint32(i)
peps = append(peps, p)
}
deleteOplogMsgs := make([]*oplog.Message, 0, len(peps))
_, err := w.DeleteItems(ctx, peps, db.WithDebug(true), db.NewOplogMsgs(&deleteOplogMsgs))
if err != nil {
return errors.Wrap(ctx, err, op)
}
if len(currentSet.PreferredEndpoints) > 0 {
// Delete all old endpoint entries.
var peps []interface{}
for i := 1; i <= len(currentSet.PreferredEndpoints); i++ {
p := host.AllocPreferredEndpoint()
p.HostSetId, p.Priority = currentSet.GetPublicId(), uint32(i)
peps = append(peps, p)
}
deleteOplogMsgs := make([]*oplog.Message, 0, len(peps))
_, err := w.DeleteItems(ctx, peps, db.WithDebug(true), db.NewOplogMsgs(&deleteOplogMsgs))
if err != nil {
return errors.Wrap(ctx, err, op)
}
// Only append the oplog message if an operation was actually
// performed.
if len(deleteOplogMsgs) > 0 {
msgs = append(msgs, deleteOplogMsgs...)
// Only append the oplog message if an operation was actually
// performed.
if len(deleteOplogMsgs) > 0 {
msgs = append(msgs, deleteOplogMsgs...)
}
}
// Create the new entries.