Skip to content

Commit

Permalink
fix transactions for realloc and replace
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwinger233 committed Oct 16, 2020
1 parent 1f6c898 commit be820ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
8 changes: 4 additions & 4 deletions cluster/calcium/realloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ func (c *Calcium) doReallocContainersOnNode(ctx context.Context, ch chan *types.

// if: commit changes of realloc resources
func(ctx context.Context) (err error) {

for _, plan := range planMap {
plan.ApplyChangesOnNode(node, utils.Range(len(containers))...)
}
rollbacks = utils.Range(len(containers))
for _, container := range containers {
originalContainers = append(originalContainers, *container)
}
return c.store.UpdateNodes(ctx, node)
},

// then: update instances' resources
func(ctx context.Context) error {
for _, container := range containers {
originalContainers = append(originalContainers, *container)
}
rollbacks, err = c.doUpdateResourceOnInstances(ctx, ch, node, planMap, containers, hardVbsMap)
return err
},
Expand Down
21 changes: 3 additions & 18 deletions cluster/calcium/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"sync"

"github.com/projecteru2/core/store"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -151,23 +150,9 @@ func (c *Calcium) doReplaceContainer(
ctx,
// if
func(ctx context.Context) error {
return utils.Txn(
ctx,
func(ctx context.Context) error {
return c.doDeployOneWorkload(ctx, node, &opts.DeployOptions, createMessage, index, -1)
},
nil,
func(ctx context.Context) error {
log.Errorf("[doReplaceContainer] Error when create and start a container, %v", createMessage.Error)
if err = c.withNodeLocked(ctx, node.Name, func(node *types.Node) error {
return c.store.UpdateNodeResource(ctx, node, createMessage.CPU, createMessage.Quota, createMessage.Memory, createMessage.Storage, createMessage.VolumePlan.IntoVolumeMap(), store.ActionIncr)
}); err != nil {
log.Errorf("[doReplaceContainer] Reset node resource %s failed %v", node.Name, err)
}
return nil
},
c.config.GlobalTimeout,
)
ctx, cancel := context.WithCancel(ctx)
cancel()
return c.doDeployOneWorkload(ctx, node, &opts.DeployOptions, createMessage, index, -1)
},
// then
func(ctx context.Context) (err error) {
Expand Down

0 comments on commit be820ab

Please sign in to comment.