Fix bug for adding preferred endpoint when non existed prior. (#1692)
This commit is contained in:
2 files changed
+426
-368
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user