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

bugfix: delete upperDir and workDir when deleting container taken over by pouch #2524

Merged
merged 1 commit into from
Dec 12, 2018

Conversation

HusterWan
Copy link
Contributor

@HusterWan HusterWan commented Dec 2, 2018

Signed-off-by: ziren.wzr ziren.wzr@alibaba-inc.com

Ⅰ. Describe what this PR did

When using d2p-migrator to upgrade docker to PouchContainer, we take over the old container's network, volumes, but the snapshot of an old container is not charged by pouchd.

So when we delete the old containers, the UpperDir and WorkDir still stay on the host, they will cost many disk space. Moreover, if the directories have disk quota id, it will make the new containers used the same disk quota id cannot use the total storage that they should. we can make it more clear:

The old UpperDir that has disk quota id 1111 costs 20G disk space, if we create a new container with the same disk quota id 1111 and intend to assign 100G disk space. Since the old UpperDir has occupied 20G, so the new container actually just can use 80G disk space.

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Dec 2, 2018

Codecov Report

Merging #2524 into master will decrease coverage by 0.13%.
The diff coverage is 9.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2524      +/-   ##
==========================================
- Coverage    69.2%   69.07%   -0.14%     
==========================================
  Files         278      278              
  Lines       18494    18694     +200     
==========================================
+ Hits        12798    12912     +114     
- Misses       4243     4309      +66     
- Partials     1453     1473      +20
Flag Coverage Δ
#criv1alpha1test 31.29% <9.09%> (-0.04%) ⬇️
#criv1alpha2test 35.43% <9.09%> (+0.15%) ⬆️
#integrationtest 40.48% <9.09%> (-0.06%) ⬇️
#nodee2etest 32.63% <9.09%> (-0.16%) ⬇️
#unittest 26.87% <0%> (-0.04%) ⬇️
Impacted Files Coverage Δ
daemon/mgr/container.go 58.77% <0%> (-0.56%) ⬇️
daemon/mgr/container_types.go 72.85% <10%> (-10.48%) ⬇️
apis/server/network_bridge.go 55.03% <0%> (-8.61%) ⬇️
pkg/system/system.go 62.33% <0%> (-5.78%) ⬇️
daemon/mgr/system.go 67.93% <0%> (-5.35%) ⬇️
daemon/mgr/events.go 96.29% <0%> (-3.71%) ⬇️
cri/v1alpha2/cri_wrapper.go 61.2% <0%> (-2.4%) ⬇️
ctrd/client.go 66.92% <0%> (-2.31%) ⬇️
daemon/logger/jsonfile/utils.go 71.54% <0%> (-1.63%) ⬇️
pkg/meta/store.go 67.44% <0%> (-1.56%) ⬇️
... and 8 more

@pouchrobot pouchrobot added kind/bug This is bug report for project size/S labels Dec 2, 2018
@HusterWan HusterWan requested a review from rudyfly December 2, 2018 09:08
@pouchrobot pouchrobot added size/M and removed size/S labels Dec 3, 2018

if v, ok := c.Snapshotter.Data["WorkDir"]; ok {
workDir = v
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What about refactor it to

if c.Snapshotter == nil || c.Snapshotter.Data == nil {
return
}

for _, dir := range []string{"MergedDir", "UpperDir", "WorkDir"} {
        ...
        v, ok := c.Snapshotter.Data[dir]
        if !ok {
	        continue
        }
        ...
}

@HusterWan

Copy link
Collaborator

Choose a reason for hiding this comment

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

@zhuangqh Your code haven't unlocked.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the better codes like these:

if c.Snapshotter == nil || c.Snapshotter.Data == nil {
    return
}
lock()
removeDirs []string
for _, dir := range []string{"MergedDir",  "WorkDir", "UpperDir"} {
        ...
        v, ok := c.Snapshotter.Data[dir]
        if !ok {
	        continue
        }
        removeDirs = append(removeDir, v)
}
unlock()

for _, dir := range removeDirs {
    os.Remove(...)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@rudyfly I know. I just briefly point out how to refactor the code structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rudyfly @zhuangqh good advice

// WorkDir. Since the snapshot of container created by containerd will be cleaned by
// containerd, so we only clean rootfs that is RootFSProvided.
func (c *Container) CleanRootfsSnapshotDirs() error {
// if RootFSProvided is set, we no need clean the rootfs
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment is is not set?


if v, ok := c.Snapshotter.Data["WorkDir"]; ok {
workDir = v
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@zhuangqh Your code haven't unlocked.

@@ -491,6 +492,51 @@ func (c *Container) GetSpecificBasePath(path string) string {
return ""
}

// CleanRootfsSnapshotDirs delete container's rootfs snapshot MergedDir, UpperDir and
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/delete/deletes


if v, ok := c.Snapshotter.Data["WorkDir"]; ok {
workDir = v
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the better codes like these:

if c.Snapshotter == nil || c.Snapshotter.Data == nil {
    return
}
lock()
removeDirs []string
for _, dir := range []string{"MergedDir",  "WorkDir", "UpperDir"} {
        ...
        v, ok := c.Snapshotter.Data[dir]
        if !ok {
	        continue
        }
        removeDirs = append(removeDir, v)
}
unlock()

for _, dir := range removeDirs {
    os.Remove(...)
}

…r by pouch

Signed-off-by: ziren.wzr <ziren.wzr@alibaba-inc.com>
Copy link
Contributor

@zhuangqh zhuangqh left a comment

Choose a reason for hiding this comment

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

LGTM. also cc @rudyfly

@rudyfly
Copy link
Collaborator

rudyfly commented Dec 12, 2018

LGTM

@rudyfly rudyfly merged commit 50917ef into AliyunContainerService:master Dec 12, 2018
@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is bug report for project LGTM one maintainer or community participant agrees to merge the pull reuqest. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants