Skip to content

Commit 164637c

Browse files
committed
storage: avoid layer lookup in applyDiffFromStagingDirectory()
That caller in create() already had the layer created in memory so another lookup roundtrip is unnecessary here. Signed-off-by: Paul Holzinger <[email protected]>
1 parent 5f3c6c6 commit 164637c

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

storage/layers.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ type rwLayerStore interface {
339339
CleanupStagingDirectory(stagingDirectory string) error
340340

341341
// applyDiffFromStagingDirectory uses diffOutput.Target to create the diff.
342-
applyDiffFromStagingDirectory(id string, diffOutput *drivers.DriverWithDifferOutput, options *drivers.ApplyDiffWithDifferOpts) error
342+
applyDiffFromStagingDirectory(layer *Layer, diffOutput *drivers.DriverWithDifferOutput, options *drivers.ApplyDiffWithDifferOpts) error
343343

344344
// DifferTarget gets the location where files are stored for the layer.
345345
DifferTarget(id string) (string, error)
@@ -1574,7 +1574,7 @@ func (r *layerStore) create(id string, parentLayer *Layer, names []string, mount
15741574
return nil, -1, err
15751575
}
15761576
} else if slo != nil {
1577-
if err := r.applyDiffFromStagingDirectory(layer.ID, slo.DiffOutput, slo.DiffOptions); err != nil {
1577+
if err := r.applyDiffFromStagingDirectory(layer, slo.DiffOutput, slo.DiffOptions); err != nil {
15781578
cleanupFailureContext = "applying staged directory diff"
15791579
return nil, -1, err
15801580
}
@@ -2552,15 +2552,11 @@ func (r *layerStore) DifferTarget(id string) (string, error) {
25522552
}
25532553

25542554
// Requires startWriting.
2555-
func (r *layerStore) applyDiffFromStagingDirectory(id string, diffOutput *drivers.DriverWithDifferOutput, options *drivers.ApplyDiffWithDifferOpts) error {
2555+
func (r *layerStore) applyDiffFromStagingDirectory(layer *Layer, diffOutput *drivers.DriverWithDifferOutput, options *drivers.ApplyDiffWithDifferOpts) error {
25562556
ddriver, ok := r.driver.(drivers.DriverWithDiffer)
25572557
if !ok {
25582558
return ErrNotSupported
25592559
}
2560-
layer, ok := r.lookup(id)
2561-
if !ok {
2562-
return ErrLayerUnknown
2563-
}
25642560
if options == nil {
25652561
options = &drivers.ApplyDiffWithDifferOpts{
25662562
ApplyDiffOpts: drivers.ApplyDiffOpts{
@@ -2621,9 +2617,9 @@ func (r *layerStore) applyDiffFromStagingDirectory(id string, diffOutput *driver
26212617
}
26222618
}
26232619
for k, v := range diffOutput.BigData {
2624-
if err := r.SetBigData(id, k, bytes.NewReader(v)); err != nil {
2625-
if err2 := r.deleteWhileHoldingLock(id); err2 != nil {
2626-
logrus.Errorf("While recovering from a failure to set big data, error deleting layer %#v: %v", id, err2)
2620+
if err := r.SetBigData(layer.ID, k, bytes.NewReader(v)); err != nil {
2621+
if err2 := r.deleteWhileHoldingLock(layer.ID); err2 != nil {
2622+
logrus.Errorf("While recovering from a failure to set big data, error deleting layer %#v: %v", layer.ID, err2)
26272623
}
26282624
return err
26292625
}

storage/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3177,7 +3177,7 @@ func (s *store) ApplyStagedLayer(args ApplyStagedLayerOptions) (*Layer, error) {
31773177
// This code path exists only for cmd/containers/storage.applyDiffUsingStagingDirectory; we have tests that
31783178
// assume layer creation and applying a staged layer are separate steps. Production pull code always uses the
31793179
// other path, where layer creation is atomic.
3180-
return layer, rlstore.applyDiffFromStagingDirectory(args.ID, args.DiffOutput, args.DiffOptions)
3180+
return layer, rlstore.applyDiffFromStagingDirectory(layer, args.DiffOutput, args.DiffOptions)
31813181
}
31823182

31833183
// if the layer doesn't exist yet, try to create it.

0 commit comments

Comments
 (0)