Skip to content

metadata: improve deleting a non-empty namespace's error message#5360

Merged
estesp merged 1 commit intocontainerd:masterfrom
kzys:namespace-delete
Apr 16, 2021
Merged

metadata: improve deleting a non-empty namespace's error message#5360
estesp merged 1 commit intocontainerd:masterfrom
kzys:namespace-delete

Conversation

@kzys
Copy link
Copy Markdown
Member

@kzys kzys commented Apr 14, 2021

Deleting a non-empty namespace fails with

namespace must be empty: failed precondition

This change improves the error message by listing all objects in
the namespace that prevent deletion.

Signed-off-by: Kazuyoshi Kato [email protected]

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 14, 2021

Build succeeded.

@dmcgowan
Copy link
Copy Markdown
Member

I'm not sure I understand the value of having all the types listed in the error message. It can have a potential costly memory usage to produce this message and produce a large error message. Would it help just having something on the client which could give some stats on the namespace? All the objects listed can easily be requested by the client already.

@kzys
Copy link
Copy Markdown
Member Author

kzys commented Apr 14, 2021

Yeah. I do agree that iterating over buckets x listBucket could be slow.

How about returning information about non-empty buckets (e.g. image and container), without mentioning specific objects? Then the worst case is only 4 buckets (image, blob, container and snapshot), and the operator can query specific types based on the error message.

@dmcgowan
Copy link
Copy Markdown
Member

@kzys that sounds reasonable to me

@kzys kzys force-pushed the namespace-delete branch from d52b040 to ea57bef Compare April 14, 2021 20:57
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 14, 2021

Build succeeded.

@kzys kzys force-pushed the namespace-delete branch from ea57bef to bfae622 Compare April 14, 2021 21:17
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 14, 2021

Build succeeded.

@kzys kzys force-pushed the namespace-delete branch from bfae622 to 75c4a3c Compare April 14, 2021 21:37
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 14, 2021

Build succeeded.

@kzys kzys force-pushed the namespace-delete branch from 75c4a3c to 53f8636 Compare April 15, 2021 16:16
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 15, 2021

Build succeeded.

Comment thread metadata/namespaces.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather keep things simple and just use strings.Join here
for same reasons discussed in: #4248 (comment)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Will do.

Comment thread metadata/namespaces.go Outdated
Copy link
Copy Markdown
Member

@mxpv mxpv Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about this variation:

func (s *namespaceStore) listNs(namespace string) ([]string, error) {
	var out []string
	if !isBucketEmpty(getImagesBucket(s.tx, namespace)) {
		out = append(out, "images")
	}

	if !isBucketEmpty(getBlobsBucket(s.tx, namespace)) {
		out = append(out, "blobs")
	}
        ...
	if snbkt := getSnapshottersBucket(s.tx, namespace); snbkt != nil {
		if err := snbkt.ForEach(func(k, v []byte) error {
			if v == nil {
				if !isBucketEmpty(snbkt.Bucket(k)) {
					out = append(out, "snapshots-"+string(k))
				}
			}
			return nil
		}); err != nil {
			return nil, err
		}
	}

	return out, nil
}
  • if we want to be informative, let's use k to clarify which snapshotter.
  • no need to remap map -> key slice after calling listNamespace
  • no need to have pair

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Updated in the last revision.

@kzys kzys force-pushed the namespace-delete branch from 53f8636 to bcd6360 Compare April 15, 2021 17:41
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 15, 2021

Build succeeded.

@github-actions

This comment has been minimized.

@estesp
Copy link
Copy Markdown
Member

estesp commented Apr 15, 2021

@cpuguy83 any reason the last merge to master is generating a comment in this PR about tests during that (merge, not PR) workflow run? 🤔 😂

@mxpv
Copy link
Copy Markdown
Member

mxpv commented Apr 15, 2021

@estesp I think it's because how workflow_run works:
The workflow runs on workflow_run event must exist on the master or default branch. And this workflow will only run on the master or default branch, regardless of whether it is triggered by a workflow run on other branches or not.

Copy link
Copy Markdown
Member

@mxpv mxpv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on green

@github-actions

This comment has been minimized.

@kzys kzys force-pushed the namespace-delete branch from bcd6360 to 1bdded8 Compare April 15, 2021 18:49
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 15, 2021

Build succeeded.

@github-actions

This comment has been minimized.

Deleting a non-empty namespace fails with

> namespace must be empty: failed precondition

This change improves the error message by listing the types of
the objects in the namespace that prevent deletion.

Signed-off-by: Kazuyoshi Kato <[email protected]>
@kzys kzys force-pushed the namespace-delete branch from 1bdded8 to cb15809 Compare April 15, 2021 22:49
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Apr 15, 2021

Build succeeded.

@kzys
Copy link
Copy Markdown
Member Author

kzys commented Apr 15, 2021

It is green now :)

Copy link
Copy Markdown
Member

@samuelkarp samuelkarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@estesp estesp merged commit 9efd3e2 into containerd:master Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants