@@ -49,21 +49,22 @@ func (c *Calcium) doReallocOnNode(ctx context.Context, nodename string, containe
49
49
return utils .Txn (
50
50
ctx ,
51
51
52
- // if commit changes
52
+ // if update workload resources
53
53
func (ctx context.Context ) (err error ) {
54
+ return c .doReallocContainersOnInstance (ctx , node , plans , container )
55
+ },
56
+ // then commit changes
57
+ func (ctx context.Context ) error {
54
58
for _ , plan := range plans {
55
59
plan .ApplyChangesOnNode (node , 1 )
56
60
}
57
61
return c .store .UpdateNodes (ctx , node )
58
62
},
59
-
60
- // then update workload resources
61
- func (ctx context.Context ) error {
62
- return c .doReallocContainersOnInstance (ctx , node , plans , container )
63
- },
64
-
65
63
// rollback to origin
66
- func (ctx context.Context ) error {
64
+ func (ctx context.Context , failureByCond bool ) error {
65
+ if failureByCond {
66
+ return nil
67
+ }
67
68
for _ , plan := range plans {
68
69
plan .RollbackChangesOnNode (node , 1 )
69
70
}
@@ -94,7 +95,22 @@ func (c *Calcium) doReallocContainersOnInstance(ctx context.Context, node *types
94
95
return utils .Txn (
95
96
ctx ,
96
97
97
- // if: update container meta
98
+ // if: update container resources
99
+ func (ctx context.Context ) error {
100
+ r := & enginetypes.VirtualizationResource {
101
+ CPU : r .CPU ,
102
+ Quota : r .CPUQuotaLimit ,
103
+ NUMANode : r .NUMANode ,
104
+ Memory : r .MemoryLimit ,
105
+ Volumes : r .VolumeLimit .ToStringSlice (false , false ),
106
+ VolumePlan : r .VolumePlanLimit .ToLiteral (),
107
+ VolumeChanged : r .VolumeChanged ,
108
+ Storage : r .StorageLimit ,
109
+ }
110
+ return errors .WithStack (node .Engine .VirtualizationUpdateResource (ctx , container .ID , r ))
111
+ },
112
+
113
+ // then: update container meta
98
114
func (ctx context.Context ) error {
99
115
container .CPUQuotaRequest = r .CPUQuotaRequest
100
116
container .CPUQuotaLimit = r .CPUQuotaLimit
@@ -110,23 +126,11 @@ func (c *Calcium) doReallocContainersOnInstance(ctx context.Context, node *types
110
126
return errors .WithStack (c .store .UpdateContainer (ctx , container ))
111
127
},
112
128
113
- // then: update container resources
114
- func (ctx context.Context ) error {
115
- r := & enginetypes.VirtualizationResource {
116
- CPU : r .CPU ,
117
- Quota : r .CPUQuotaLimit ,
118
- NUMANode : r .NUMANode ,
119
- Memory : r .MemoryLimit ,
120
- Volumes : r .VolumeLimit .ToStringSlice (false , false ),
121
- VolumePlan : r .VolumePlanLimit .ToLiteral (),
122
- VolumeChanged : r .VolumeChanged ,
123
- Storage : r .StorageLimit ,
124
- }
125
- return errors .WithStack (node .Engine .VirtualizationUpdateResource (ctx , container .ID , r ))
126
- },
127
-
128
129
// rollback: container meta
129
- func (ctx context.Context ) error {
130
+ func (ctx context.Context , failureByCond bool ) error {
131
+ if failureByCond {
132
+ return nil
133
+ }
130
134
return errors .WithStack (c .store .UpdateContainer (ctx , & originalContainer ))
131
135
},
132
136
0 commit comments