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

fix: keep meta data complete #2292

Merged
merged 1 commit into from
Oct 15, 2018
Merged

fix: keep meta data complete #2292

merged 1 commit into from
Oct 15, 2018

Conversation

Ace-Tang
Copy link
Contributor

@Ace-Tang Ace-Tang commented Sep 30, 2018

before updating meta.json on disk, write a new file for the new content, in case
that if it fails to write new file(like no space on disk), we can still
have a completed file. Avoid meta.json broken, in this way, we may
hardly recover meta data
Signed-off-by: Ace-Tang aceapril@126.com

Ⅰ. Describe what this PR did

The design

  1. use timestamp as a suffix of a backfile, consider that if one time back up file is not deleted, backup file will be covered, generally it will be ok, but sometimes it may error.
  2. do not use backup file to do recovery automatically, first this case is really unusual, if it happens, we should check and do recovery by manual. If automatic recovery fails, we may never get origin file. So I do not suggest automatic recovery.

Design has changed according to the review, please check.

Ⅱ. Does this pull request fix one issue?

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

no.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Sep 30, 2018

Codecov Report

Merging #2292 into master will decrease coverage by 0.05%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2292      +/-   ##
==========================================
- Coverage    66.8%   66.74%   -0.06%     
==========================================
  Files         208      208              
  Lines       16971    16974       +3     
==========================================
- Hits        11337    11330       -7     
- Misses       4270     4275       +5     
- Partials     1364     1369       +5
Flag Coverage Δ
#criv1alpha1test 32.33% <33.33%> (-0.28%) ⬇️
#criv1alpha2test 36.03% <33.33%> (-0.19%) ⬇️
#integrationtest 39.46% <33.33%> (-0.01%) ⬇️
#nodee2etest 33.42% <33.33%> (+0.01%) ⬆️
#unittest 23.76% <33.33%> (ø) ⬆️
Impacted Files Coverage Δ
pkg/meta/local.go 63% <33.33%> (-0.92%) ⬇️
cri/v1alpha2/cri_wrapper.go 61.2% <0%> (-1.2%) ⬇️
ctrd/container.go 58.8% <0%> (-0.96%) ⬇️
cri/v1alpha1/cri.go 61.27% <0%> (-0.33%) ⬇️
cri/v1alpha2/cri.go 66.76% <0%> (-0.3%) ⬇️
daemon/mgr/container.go 57.43% <0%> (-0.21%) ⬇️
daemon/containerio/cri_log_file.go 88.23% <0%> (+3.92%) ⬆️
daemon/mgr/snapshot.go 94.2% <0%> (+4.34%) ⬆️

@pouchrobot pouchrobot added kind/bug This is bug report for project size/S labels Sep 30, 2018
@allencloud
Copy link
Collaborator

Is there any possibility that before backuping the original meta.json, the disk have already been full, and then the backup fails? @Ace-Tang

@Ace-Tang
Copy link
Contributor Author

Is there any possibility that before backuping the original meta.json, the disk have already been full, and then the backup fails? @Ace-Tang

it will return error, then, meta data update also fails.

if _, err := os.Stat(name); err == nil {
+               if err := os.Rename(name, backupFile); err != nil {
+                       return fmt.Errorf("failed to backup file %s: %s", name, err)
+               }
+       }
+

And if the container is first time to be created, the created process will fail, since disk is full.

before update meta.json on disk, write a new file for the new content, in case
that if fails to write new file(like no space on disk), we can still
have a completed file. Avoid meta.json broken, in this way, we may
hardly recover meta data

Signed-off-by: Ace-Tang <aceapril@126.com>
@Ace-Tang
Copy link
Contributor Author

@allencloud , modify as you suggest offline, PTAL.

@xiaoxubeii
Copy link
Contributor

I think you should adjust the content of pr according to your recently changes. These changes don't backup the original configuration but create a new target file and replace the origin.

@Ace-Tang
Copy link
Contributor Author

Ace-Tang commented Oct 9, 2018

@xiaoxubeii , I have alreay update content of pr, but just not update the auto-generated one, now I update it.

@allencloud
Copy link
Collaborator

LGTM, while I would invite @fuweid to take another review.

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Oct 12, 2018
@rudyfly
Copy link
Collaborator

rudyfly commented Oct 15, 2018

LGTM

@rudyfly rudyfly merged commit 7914128 into AliyunContainerService:master Oct 15, 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/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants