@@ -62,7 +62,13 @@ func withoutOrchestrator() coordinatorOption {
6262 }
6363}
6464
65- func newFirecrackerCoordinator (orch * ctriface.Orchestrator , snapsCapacityMiB int64 , isSparseSnaps bool , isFullLocal bool , opts ... coordinatorOption ) * coordinator {
65+ func newFirecrackerCoordinator (
66+ orch * ctriface.Orchestrator ,
67+ snapsCapacityMiB int64 ,
68+ isSparseSnaps bool ,
69+ isFullLocal bool ,
70+ opts ... coordinatorOption ) * coordinator {
71+
6672 c := & coordinator {
6773 activeInstances : make (map [string ]* FuncInstance ),
6874 orch : orch ,
@@ -114,7 +120,7 @@ func (c *coordinator) startVM(ctx context.Context, image string, revision string
114120func (c * coordinator ) stopVM (ctx context.Context , containerID string ) error {
115121 c .Lock ()
116122
117- fi , present := c .activeInstances [containerID ]
123+ funcInst , present := c .activeInstances [containerID ]
118124 if present {
119125 delete (c .activeInstances , containerID )
120126 }
@@ -127,28 +133,28 @@ func (c *coordinator) stopVM(ctx context.Context, containerID string) error {
127133 }
128134
129135 if c .orch == nil || ! c .orch .GetSnapshotsEnabled () {
130- return c .orchStopVM (ctx , fi )
136+ return c .orchStopVM (ctx , funcInst )
131137 }
132138
133- id := fi .vmID
139+ id := funcInst .vmID
134140 if c .isFullLocal {
135- id = fi .revisionId
141+ id = funcInst .revisionId
136142 }
137143
138- if fi .snapBooted {
144+ if funcInst .snapBooted {
139145 defer c .snapshotManager .ReleaseSnapshot (id )
140146 } else {
141147 // Create snapshot
142- err := c .orchCreateSnapshot (ctx , fi )
148+ err := c .orchCreateSnapshot (ctx , funcInst )
143149 if err != nil {
144150 log .Printf ("Err creating snapshot %s\n " , err )
145151 }
146152 }
147153
148154 if c .isFullLocal {
149- return c .orchStopVM (ctx , fi )
155+ return c .orchStopVM (ctx , funcInst )
150156 } else {
151- return c .orchOffloadVM (ctx , fi )
157+ return c .orchOffloadVM (ctx , funcInst )
152158 }
153159}
154160
@@ -161,18 +167,18 @@ func (c *coordinator) isActive(containerID string) bool {
161167 return ok
162168}
163169
164- func (c * coordinator ) insertActive (containerID string , fi * FuncInstance ) error {
170+ func (c * coordinator ) insertActive (containerID string , funcInst * FuncInstance ) error {
165171 c .Lock ()
166172 defer c .Unlock ()
167173
168- logger := log .WithFields (log.Fields {"containerID" : containerID , "vmID" : fi .vmID })
174+ logger := log .WithFields (log.Fields {"containerID" : containerID , "vmID" : funcInst .vmID })
169175
170176 if fi , present := c .activeInstances [containerID ]; present {
171177 logger .Errorf ("entry for container already exists with vmID %s" + fi .vmID )
172178 return errors .New ("entry for container already exists" )
173179 }
174180
175- c .activeInstances [containerID ] = fi
181+ c .activeInstances [containerID ] = funcInst
176182 return nil
177183}
178184
@@ -206,12 +212,18 @@ func (c *coordinator) orchStartVM(ctx context.Context, image, revision string, m
206212
207213 coldStartTimeMs := metrics .ToMs (time .Since (tStartCold ))
208214
209- fi := NewFuncInstance (vmID , image , revision , resp , false , memSizeMib , vCPUCount , coldStartTimeMs )
215+ funcInst := NewFuncInstance (vmID , image , revision , resp , false , memSizeMib , vCPUCount , coldStartTimeMs )
210216 logger .Debug ("successfully created fresh instance" )
211- return fi , err
217+ return funcInst , err
212218}
213219
214- func (c * coordinator ) orchStartVMSnapshot (ctx context.Context , snap * snapshotting.Snapshot , memSizeMib , vCPUCount uint32 , vmID string ) (* FuncInstance , error ) {
220+ func (c * coordinator ) orchStartVMSnapshot (
221+ ctx context.Context ,
222+ snap * snapshotting.Snapshot ,
223+ memSizeMib ,
224+ vCPUCount uint32 ,
225+ vmID string ) (* FuncInstance , error ) {
226+
215227 tStartCold := time .Now ()
216228 logger := log .WithFields (
217229 log.Fields {
@@ -242,29 +254,35 @@ func (c *coordinator) orchStartVMSnapshot(ctx context.Context, snap *snapshottin
242254 }
243255
244256 coldStartTimeMs := metrics .ToMs (time .Since (tStartCold ))
245- fi := NewFuncInstance (vmID , snap .GetImage (), snap .GetId (), resp , true , memSizeMib , vCPUCount , coldStartTimeMs )
257+ funcInst := NewFuncInstance (vmID , snap .GetImage (), snap .GetId (), resp , true , memSizeMib , vCPUCount , coldStartTimeMs )
246258 logger .Debug ("successfully loaded instance from snapshot" )
247259
248- return fi , err
260+ return funcInst , err
249261}
250262
251- func (c * coordinator ) orchCreateSnapshot (ctx context.Context , fi * FuncInstance ) error {
263+ func (c * coordinator ) orchCreateSnapshot (ctx context.Context , funcInst * FuncInstance ) error {
252264 logger := log .WithFields (
253265 log.Fields {
254- "vmID" : fi .vmID ,
255- "image" : fi .image ,
266+ "vmID" : funcInst .vmID ,
267+ "image" : funcInst .image ,
256268 },
257269 )
258270
259- id := fi .vmID
271+ id := funcInst .vmID
260272 if c .isFullLocal {
261- id = fi .revisionId
273+ id = funcInst .revisionId
262274 }
263275
264- removeContainerSnaps , snap , err := c .snapshotManager .InitSnapshot (id , fi .image , fi .coldStartTimeMs , fi .memSizeMib , fi .vCPUCount , c .isSparseSnaps )
276+ removeContainerSnaps , snap , err := c .snapshotManager .InitSnapshot (
277+ id ,
278+ funcInst .image ,
279+ funcInst .coldStartTimeMs ,
280+ funcInst .memSizeMib ,
281+ funcInst .vCPUCount ,
282+ c .isSparseSnaps )
265283
266284 if err != nil {
267- fi .logger .Warn (fmt .Sprint (err ))
285+ funcInst .logger .Warn (fmt .Sprint (err ))
268286 return nil
269287 }
270288
@@ -281,46 +299,46 @@ func (c *coordinator) orchCreateSnapshot(ctx context.Context, fi *FuncInstance)
281299
282300 logger .Debug ("creating instance snapshot before stopping" )
283301
284- err = c .orch .PauseVM (ctxTimeout , fi .vmID )
302+ err = c .orch .PauseVM (ctxTimeout , funcInst .vmID )
285303 if err != nil {
286304 logger .WithError (err ).Error ("failed to pause VM" )
287305 return nil
288306 }
289307
290- err = c .orch .CreateSnapshot (ctxTimeout , fi .vmID , snap , c .isFullLocal )
308+ err = c .orch .CreateSnapshot (ctxTimeout , funcInst .vmID , snap , c .isFullLocal )
291309 if err != nil {
292- fi .logger .WithError (err ).Error ("failed to create snapshot" )
310+ funcInst .logger .WithError (err ).Error ("failed to create snapshot" )
293311 return nil
294312 }
295313
296314 if err := c .snapshotManager .CommitSnapshot (id ); err != nil {
297- fi .logger .WithError (err ).Error ("failed to commit snapshot" )
315+ funcInst .logger .WithError (err ).Error ("failed to commit snapshot" )
298316 return err
299317 }
300318
301319 return nil
302320}
303321
304- func (c * coordinator ) orchOffloadVM (ctx context.Context , fi * FuncInstance ) error {
322+ func (c * coordinator ) orchOffloadVM (ctx context.Context , funcInst * FuncInstance ) error {
305323 if c .withoutOrchestrator {
306324 return nil
307325 }
308326
309- if err := c .orch .OffloadVM (ctx , fi .vmID , c .isFullLocal ); err != nil {
310- fi .logger .WithError (err ).Error ("failed to offload VM" )
327+ if err := c .orch .OffloadVM (ctx , funcInst .vmID , c .isFullLocal ); err != nil {
328+ funcInst .logger .WithError (err ).Error ("failed to offload VM" )
311329 return err
312330 }
313331
314332 return nil
315333}
316334
317- func (c * coordinator ) orchStopVM (ctx context.Context , fi * FuncInstance ) error {
335+ func (c * coordinator ) orchStopVM (ctx context.Context , funcInst * FuncInstance ) error {
318336 if c .withoutOrchestrator {
319337 return nil
320338 }
321339
322- if err := c .orch .StopSingleVM (ctx , fi .vmID , c .isFullLocal ); err != nil {
323- fi .logger .WithError (err ).Error ("failed to stop VM for instance" )
340+ if err := c .orch .StopSingleVM (ctx , funcInst .vmID , c .isFullLocal ); err != nil {
341+ funcInst .logger .WithError (err ).Error ("failed to stop VM for instance" )
324342 return err
325343 }
326344
0 commit comments