Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Go 1.18 generics in the store’s locking helpers #1577

Merged
merged 7 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ vendor_task:

cross_task:
container:
image: golang:1.17
image: golang:1.18
build_script: make cross


Expand All @@ -182,6 +182,6 @@ success_task:
- vendor
- cross
container:
image: golang:1.17
image: golang:1.18
clone_script: 'mkdir -p "$CIRRUS_WORKING_DIR"' # Source code not needed
script: /bin/true
36 changes: 18 additions & 18 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ func (s *store) Check(options *CheckOptions) (CheckReport, error) {

// Walk the list of layer stores, looking at each layer that we didn't see in a
// previously-visited store.
if errored, err := s.readAllLayerStores(func(store roLayerStore) (bool, error) {
if _, _, err := readAllLayerStores(s, func(store roLayerStore) (struct{}, bool, error) {
layers, err := store.Layers()
if err != nil {
return true, err
return struct{}{}, true, err
}
isReadWrite := roLayerStoreIsReallyReadWrite(store)
readWriteDesc := ""
Expand Down Expand Up @@ -337,7 +337,7 @@ func (s *store) Check(options *CheckOptions) (CheckReport, error) {
// At this point we're out of things that we can be sure will work in read-only
// stores, so skip the rest for any stores that aren't also read-write stores.
if !isReadWrite {
return false, nil
return struct{}{}, false, nil
}
// Content and mount checks are also things that we can only be sure will work in
// read-write stores.
Expand Down Expand Up @@ -439,8 +439,8 @@ func (s *store) Check(options *CheckOptions) (CheckReport, error) {
err := fmt.Errorf("%slayer %s: %w", readWriteDesc, parent, ErrLayerMissing)
report.Layers[id] = append(report.Layers[id], err)
}
return false, nil
}); errored {
return struct{}{}, false, nil
}); err != nil {
return CheckReport{}, err
}

Expand All @@ -452,10 +452,10 @@ func (s *store) Check(options *CheckOptions) (CheckReport, error) {

// Walk the list of image stores, looking at each image that we didn't see in a
// previously-visited store.
if errored, err := s.readAllImageStores(func(store roImageStore) (bool, error) {
if _, _, err := readAllImageStores(s, func(store roImageStore) (struct{}, bool, error) {
images, err := store.Images()
if err != nil {
return true, err
return struct{}{}, true, err
}
isReadWrite := roImageStoreIsReallyReadWrite(store)
readWriteDesc := ""
Expand Down Expand Up @@ -564,16 +564,16 @@ func (s *store) Check(options *CheckOptions) (CheckReport, error) {
}
}
}
return false, nil
}); errored {
return struct{}{}, false, nil
}); err != nil {
return CheckReport{}, err
}

// Iterate over each container in turn.
if done, err := s.readContainerStore(func() (bool, error) {
if _, _, err := readContainerStore(s, func() (struct{}, bool, error) {
containers, err := s.containerStore.Containers()
if err != nil {
return true, err
return struct{}{}, true, err
}
for i := range containers {
container := containers[i]
Expand Down Expand Up @@ -622,21 +622,21 @@ func (s *store) Check(options *CheckOptions) (CheckReport, error) {
referencedLayers[container.LayerID] = true
}
}
return false, nil
}); done {
return struct{}{}, false, nil
}); err != nil {
return CheckReport{}, err
}

// Now go back through all of the layer stores, and flag any layers which don't belong
// to an image or a container, and has been around longer than we can reasonably expect
// such a layer to be present before a corresponding image record is added.
if errored, err := s.readAllLayerStores(func(store roLayerStore) (bool, error) {
if _, _, err := readAllLayerStores(s, func(store roLayerStore) (struct{}, bool, error) {
if isReadWrite := roLayerStoreIsReallyReadWrite(store); !isReadWrite {
return false, nil
return struct{}{}, false, nil
}
layers, err := store.Layers()
if err != nil {
return true, err
return struct{}{}, true, err
}
for _, layer := range layers {
maximumAge := defaultMaximumUnreferencedLayerAge
Expand All @@ -654,8 +654,8 @@ func (s *store) Check(options *CheckOptions) (CheckReport, error) {
}
}
}
return false, nil
}); errored {
return struct{}{}, false, nil
}); err != nil {
return CheckReport{}, err
}

Expand Down
8 changes: 4 additions & 4 deletions check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ func TestCheckDetectWriteable(t *testing.T) {
require.NoError(t, err, "unexpected error initializing test store")
s, ok := stoar.(*store)
require.True(t, ok, "unexpected error making type assertion")
done, err := s.readAllLayerStores(func(store roLayerStore) (bool, error) {
_, done, err := readAllLayerStores(s, func(store roLayerStore) (struct{}, bool, error) {
if roLayerStoreIsReallyReadWrite(store) { // implicitly checking that the type assertion in this function doesn't panic
sawRWlayers = true
}
return false, nil
return struct{}{}, false, nil
})
assert.False(t, done, "unexpected error from readAllLayerStores")
assert.NoError(t, err, "unexpected error from readAllLayerStores")
assert.True(t, sawRWlayers, "unexpected error detecting which layer store is writeable")
done, err = s.readAllImageStores(func(store roImageStore) (bool, error) {
_, done, err = readAllImageStores(s, func(store roImageStore) (struct{}, bool, error) {
if roImageStoreIsReallyReadWrite(store) { // implicitly checking that the type assertion in this function doesn't panic
sawRWimages = true
}
return false, nil
return struct{}{}, false, nil
})
assert.False(t, done, "unexpected error from readAllImageStores")
assert.NoError(t, err, "unexpected error from readAllImageStores")
Expand Down
Loading