mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #36577 from cpuguy83/info_tweaks
Minor optimizations
This commit is contained in:
commit
9e1c4f9906
4 changed files with 31 additions and 5 deletions
|
@ -77,7 +77,7 @@ type ImageService struct {
|
|||
// CountImages returns the number of images stored by ImageService
|
||||
// called from info.go
|
||||
func (i *ImageService) CountImages() int {
|
||||
return len(i.imageStore.Map())
|
||||
return i.imageStore.Len()
|
||||
}
|
||||
|
||||
// Children returns the children image.IDs for a parent image.
|
||||
|
|
|
@ -27,6 +27,7 @@ type Store interface {
|
|||
Children(id ID) []ID
|
||||
Map() map[ID]*Image
|
||||
Heads() map[ID]*Image
|
||||
Len() int
|
||||
}
|
||||
|
||||
// LayerGetReleaser is a minimal interface for getting and releasing images.
|
||||
|
@ -336,3 +337,9 @@ func (is *store) imagesMap(all bool) map[ID]*Image {
|
|||
}
|
||||
return images
|
||||
}
|
||||
|
||||
func (is *store) Len() int {
|
||||
is.RLock()
|
||||
defer is.RUnlock()
|
||||
return len(is.images)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package image // import "github.com/docker/docker/image"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
|
@ -171,6 +172,20 @@ func TestGetAndSetLastUpdated(t *testing.T) {
|
|||
assert.Equal(t, updated.IsZero(), false)
|
||||
}
|
||||
|
||||
func TestStoreLen(t *testing.T) {
|
||||
store, cleanup := defaultImageStore(t)
|
||||
defer cleanup()
|
||||
|
||||
expected := 10
|
||||
for i := 0; i < expected; i++ {
|
||||
_, err := store.Create([]byte(fmt.Sprintf(`{"comment": "abc%d", "rootfs": {"type": "layers"}}`, i)))
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
numImages := store.Len()
|
||||
assert.Equal(t, expected, numImages)
|
||||
assert.Equal(t, len(store.Map()), numImages)
|
||||
}
|
||||
|
||||
type mockLayerGetReleaser struct{}
|
||||
|
||||
func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) {
|
||||
|
|
|
@ -263,11 +263,15 @@ func (r *remote) startContainerd() error {
|
|||
func (r *remote) monitorConnection(monitor *containerd.Client) {
|
||||
var transientFailureCount = 0
|
||||
|
||||
ticker := time.NewTicker(500 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
<-ticker.C
|
||||
select {
|
||||
case <-r.shutdownContext.Done():
|
||||
r.logger.Info("stopping healthcheck following graceful shutdown")
|
||||
monitor.Close()
|
||||
return
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(r.shutdownContext, healthCheckTimeout)
|
||||
_, err := monitor.IsServing(ctx)
|
||||
cancel()
|
||||
|
|
Loading…
Reference in a new issue