Skip to content

Commit

Permalink
fix: thread safety for progress (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzantow authored Mar 1, 2023
1 parent fab1c96 commit abfb374
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/sylabs/sif/v2 v2.8.1
github.com/sylabs/squashfs v0.6.1
github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d
github.com/wagoodman/go-progress v0.0.0-20200621122631-1a2120f0695a
github.com/wagoodman/go-progress v0.0.0-20230301185719-21920a456ad5
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d h1:KOxOL6qpmqwoPloNwi+CEgc1ayjHNOFNrvoOmeDOjDg=
github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d/go.mod h1:JPirS5jde/CF5qIjcK4WX+eQmKXdPc6vcZkJ/P0hfPw=
github.com/wagoodman/go-progress v0.0.0-20200621122631-1a2120f0695a h1:lV3ioFpbqvfZ1bXSQfloLWzom1OPU/5UjyU0wmBlkNc=
github.com/wagoodman/go-progress v0.0.0-20200621122631-1a2120f0695a/go.mod h1:jLXFoL31zFaHKAAyZUh+sxiTDFe1L1ZHrcK2T1itVKA=
github.com/wagoodman/go-progress v0.0.0-20230301185719-21920a456ad5 h1:lwgTsTy18nYqASnH58qyfRW/ldj7Gt2zzBvgYPzdA4s=
github.com/wagoodman/go-progress v0.0.0-20230301185719-21920a456ad5/go.mod h1:jLXFoL31zFaHKAAyZUh+sxiTDFe1L1ZHrcK2T1itVKA=
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
10 changes: 5 additions & 5 deletions pkg/image/docker/pull_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ func (p *PullStatus) onEvent(event *pullEvent) {
if currentPhase >= AlreadyExistsPhase {
phaseProgress.SetCompleted()
} else {
phaseProgress.N = int64(event.ProgressDetail.Current)
phaseProgress.Total = int64(event.ProgressDetail.Total)
phaseProgress.Set(int64(event.ProgressDetail.Current))
phaseProgress.SetTotal(int64(event.ProgressDetail.Total))
}

if currentPhase == DownloadingPhase {
dl := p.downloadProgress[layer]
dl.N = int64(event.ProgressDetail.Current)
dl.Total = int64(event.ProgressDetail.Total)
dl.Set(int64(event.ProgressDetail.Current))
dl.SetTotal(int64(event.ProgressDetail.Total))
} else if currentPhase >= DownloadCompletePhase {
dl := p.downloadProgress[layer]
dl.N = dl.Total
dl.Set(dl.Size())
dl.SetCompleted()
}
}
10 changes: 5 additions & 5 deletions pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ func (i *Image) IDs() []string {
}

func (i *Image) trackReadProgress(metadata Metadata) *progress.Manual {
prog := &progress.Manual{
prog := progress.NewManual(
// x2 for read and squash of each layer
Total: int64(len(metadata.Config.RootFS.DiffIDs) * 2),
}
int64(len(metadata.Config.RootFS.DiffIDs) * 2),
)

bus.Publish(partybus.Event{
Type: event.ReadImage,
Expand Down Expand Up @@ -217,7 +217,7 @@ func (i *Image) Read() error {
i.Metadata.Size += layer.Metadata.Size
layers = append(layers, layer)

readProg.N++
readProg.Increment()
}

i.Layers = layers
Expand Down Expand Up @@ -257,7 +257,7 @@ func (i *Image) squash(prog *progress.Manual) error {
layer.SquashedSearchContext = filetree.NewSearchContext(layer.SquashedTree, layer.fileCatalog.Index)
lastSquashTree = squashedTree

prog.N++
prog.Increment()
}

prog.SetCompleted()
Expand Down
4 changes: 2 additions & 2 deletions pkg/image/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func layerTarIndexer(ft filetree.Writer, fileCatalog *FileCatalog, size *int64,
fileCatalog.addImageReferences(ref.ID(), layerRef, index.Open)

if monitor != nil {
monitor.N++
monitor.Increment()
}
return nil
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func squashfsVisitor(ft filetree.Writer, fileCatalog *FileCatalog, size *int64,
return r
})

monitor.N++
monitor.Increment()
return nil
}
}
Expand Down

0 comments on commit abfb374

Please sign in to comment.