Skip to content

[WIP] revive config.json for docker checkpoints#38028

Closed
lifubang wants to merge 1 commit intomoby:masterfrom
lifubang:checkpointconfig
Closed

[WIP] revive config.json for docker checkpoints#38028
lifubang wants to merge 1 commit intomoby:masterfrom
lifubang:checkpointconfig

Conversation

@lifubang
Copy link
Contributor

Signed-off-by: Lifubang [email protected]

- What I did

root@dockerdemo:~/checkpoints# docker checkpoint ls redis2
Error response from daemon: open /var/lib/docker/containers/8b5ff6aa250b78dd8a672ee60ff239afda716e4bedc3f77acb4a70c4535b3eba/checkpoints/redis2-1/config.json: no such file or directory

- How I did it
After this commit (Update libcontainerd to use containerd 1.0): ddae20c#diff-d2fd8e9feab75f193a7d19493831c1f1
There is no "config.json" now.
So, when checkpoint ls, there will be an error.
Just create it, because all value in "config.json" is from daemon.

- How to verify it
After fix:

root@dockerdemo:~/checkpoints# docker checkpoint ls redis2
CHECKPOINT NAME
redis2-2

- Description for the changelog
Create config.json after checkpoint succ.

@codecov
Copy link

codecov bot commented Oct 12, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@bc4c1c2). Click here to learn what that means.
The diff coverage is 0%.

@@            Coverage Diff            @@
##             master   #38028   +/-   ##
=========================================
  Coverage          ?   36.11%           
=========================================
  Files             ?      610           
  Lines             ?    45225           
  Branches          ?        0           
=========================================
  Hits              ?    16334           
  Misses            ?    26650           
  Partials          ?     2241

Copy link
Member

Choose a reason for hiding this comment

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

Please define new struct, because api/types is for REST API

Copy link
Contributor Author

@lifubang lifubang Oct 16, 2018

Choose a reason for hiding this comment

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

For now, "docker checkpoint ls" just return "Checkpoint name", I think we need more useful information.
So, my original idea is that after this patch, "docker checkpoint ls " should print more information. such as:
CheckpintName, Create Time, Exit
So I reuse "types.Checkpoint".

Do you still think that we need to define a new struct?
If yes, I'll redefine it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, thank you for your review.
For one PR do one thing, I defined a new struct.

Copy link
Member

Choose a reason for hiding this comment

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

If this type is (at least currently) only used locally, perhaps it should be un-exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you.
I should be careful every time. Don't just copy & paste.

Copy link
Member

Choose a reason for hiding this comment

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

It just occurred to me, but does this play nice with custom checkpoint dirs? (i.e.; should it remove the directory in that case?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought about it when I was writing this code. I don't know we should delete or just return the error. I just choose to delete it at that time. But now, with your opinion, I think we should remain that dir. I'll remove this line.

Copy link
Member

Choose a reason for hiding this comment

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

The alternative would be to check if we created the directory, but that would be dangerous (there could be a race-condition where we checked if it existed before, but meanwhile another session is creating a checkpoint (and the checkpoint dir))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how about add an option --save-whenfail?
Whether save any incomplete files or not when fail in checkpoint create process.
The default value is true, if set to false, remove the dir when fail.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, no, I don't think we should add an option for this; also in light of future work for checkpoints is being worked on on containerd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For https://github.com/containerd/containerd/blob/06b9cb35161009dcb7123345749fef02f7cea8e0/runtime/container.go#L367
If write config.json fail, it just return the error.
I think there is very very small opportunity to meet this error, so we just return the error without remove the dir?
If yes, I'll remove this line, and modify the checkpoint list func to ignore this type folder because there is no config.json in it(very very small opportunity).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or move create config.json to the position before call daemon.containerd.CreateCheckpoint?

Copy link
Contributor Author

@lifubang lifubang Oct 25, 2018

Choose a reason for hiding this comment

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

@thaJeztah I have moved the code position, and the checkpoint dir is always created by dockerd, not created by the user(

err2 = os.MkdirAll(checkpointAbsDir, 0700)
), so it will not delete user's existing dir.

return fmt.Errorf("cannot checkpoint container %s: %s", name, err)
}

checkpointInfo := checkPoint{
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a space before the curly bracket, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I add a space, gofmt will remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I prefer to add a space, it looks more pretty. But we need to upgrade gofmt.

@rst0git
Copy link
Contributor

rst0git commented Dec 17, 2018

@lifubang Thank you for the PR! I can confirm that this commit solves the problem with docker checkpoint ls and the newly introduced structure checkPoint could be used to extend this functionality to display more useful information about the checkpoints in the future.

)

// checkPoint represents the details of a checkpoint
type checkPoint struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we need to add some fields for types.Checkpoint. And AkihiroSuda tell me I should define a new struct, I accept his suggestion. Please see the first review msg at the top of this page. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, you have to fix CheckpointList too

@kolyshkin
Copy link
Contributor

Since #38452 is merged, this is no longer needed to fix docker checkpoint ls, so it's more like an improvement. Adding WIP to the title -- feel free to remove once it's ready.

@kolyshkin kolyshkin changed the title fixes checkpoint config.json lost [WIP] revive config.json for docker checkpoints Mar 21, 2019
@kolyshkin
Copy link
Contributor

To finish this, I guess CheckpointList need to be modified to show the new values you're adding to config.json, as pointed out by @avagin earlier.

Closing for now, feel free to reopen if you want to finish it.

@kolyshkin kolyshkin closed this Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants