mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
fix(edgegroups): avoid a last-write-wins situation when updating edge groups concurrently EE-3732 (#8101)
This commit is contained in:
parent
6dc1841c14
commit
e26a607d28
8 changed files with 266 additions and 65 deletions
|
@ -83,15 +83,12 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
|
|||
return httperror.InternalServerError("Unable to retrieve edge groups from the database", err)
|
||||
}
|
||||
|
||||
for idx := range edgeGroups {
|
||||
edgeGroup := &edgeGroups[idx]
|
||||
endpointIdx := findEndpointIndex(edgeGroup.Endpoints, endpoint.ID)
|
||||
if endpointIdx != -1 {
|
||||
edgeGroup.Endpoints = removeElement(edgeGroup.Endpoints, endpointIdx)
|
||||
err = handler.DataStore.EdgeGroup().UpdateEdgeGroup(edgeGroup.ID, edgeGroup)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to update edge group", err)
|
||||
}
|
||||
for _, edgeGroup := range edgeGroups {
|
||||
err = handler.DataStore.EdgeGroup().UpdateEdgeGroupFunc(edgeGroup.ID, func(g *portainer.EdgeGroup) {
|
||||
g.Endpoints = removeElement(g.Endpoints, endpoint.ID)
|
||||
})
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to update edge group", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,20 +127,14 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
|
|||
return response.Empty(w)
|
||||
}
|
||||
|
||||
func findEndpointIndex(tags []portainer.EndpointID, searchEndpointID portainer.EndpointID) int {
|
||||
for idx, tagID := range tags {
|
||||
if searchEndpointID == tagID {
|
||||
return idx
|
||||
func removeElement(slice []portainer.EndpointID, elem portainer.EndpointID) []portainer.EndpointID {
|
||||
for i, id := range slice {
|
||||
if id == elem {
|
||||
slice[i] = slice[len(slice)-1]
|
||||
|
||||
return slice[:len(slice)-1]
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func removeElement(arr []portainer.EndpointID, index int) []portainer.EndpointID {
|
||||
if index < 0 {
|
||||
return arr
|
||||
}
|
||||
lastTagIdx := len(arr) - 1
|
||||
arr[index] = arr[lastTagIdx]
|
||||
return arr[:lastTagIdx]
|
||||
return slice
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue