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

gce: make append_or_replace.. atomic #49897

Merged
merged 1 commit into from
Aug 2, 2017

Conversation

mikedanese
Copy link
Member

@mikedanese mikedanese commented Jul 31, 2017

Before this change,

  • the final echo is not atomically written to the target file
  • two concurrent callers will use the same tempfile

Helps with #49895

cc @miekg

In GCE, add measures to prevent corruption of known_tokens.csv.

Before this change,
* the final echo is not atomically written to the target file
* two concurrent callers will use the same tempfile
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 31, 2017
@k8s-github-robot k8s-github-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. release-note-label-needed labels Jul 31, 2017
@mikedanese mikedanese added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Jul 31, 2017
@mikedanese mikedanese assigned liggitt and unassigned roberthbailey Jul 31, 2017
echo "${prefix}${suffix}" >> "${file}"
awk "substr(\$0,0,length(\"${prefix}\")) != \"${prefix}\" { print }" "${file}" > "${tmpfile}"
echo "${prefix}${suffix}" >> "${tmpfile}"
mv "${tmpfile}" "${file}"
Copy link
Member

@liggitt liggitt Jul 31, 2017

Choose a reason for hiding this comment

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

this is still not threadsafe... if two processes both write to different tmp files, one's mv back to the original can stomp the other's change. where are we calling this from multiple threads on a single file?

Copy link

Choose a reason for hiding this comment

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

As said in #49895 we're seeing corruption in this file - how exactly that happens is still unclear - this should at least prevent corruption. You're right in assessing that we now might loose changes to this file, I tend to believe that is a lesser evil.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's one theory. We are scrambling to find a fix for #49895. Copied from that bug:

Very rarely we are seeing known tokens files filled with the NULL character, with ASCII value 000. Restarting the master doesn't fix the issue because the known_tokens.csv is saved between restarts.

Copy link
Member

Choose a reason for hiding this comment

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

ok, as long as we're clear that this isn't actually making the bash function atomic. the other thing this change does is make it so that a partially failed run of the awk command will still overwrite the file. previously, the mv command would only run if the awk command succeeded.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, as long as we're clear that this isn't actually making the bash function atomic

I'm considering adding an flock around "${file}".

previously, the mv command would only run if the awk command succeeded.

This behavior should still be preserved since the script runs with set -o errexit.

@miekg
Copy link

miekg commented Jul 31, 2017 via email

@liggitt
Copy link
Member

liggitt commented Jul 31, 2017

I don't object to the change, but I don't really see this changing anything that would explain nulls in the file.

@gmarek gmarek self-assigned this Aug 1, 2017
@gmarek
Copy link
Contributor

gmarek commented Aug 1, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 1, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gmarek, mikedanese

Associated issue: 49895

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 49898, 49897, 49919, 48860, 49491)

@k8s-github-robot k8s-github-robot merged commit 49955b1 into kubernetes:master Aug 2, 2017
@mikedanese mikedanese deleted the atomic-append branch August 2, 2017 02:05
@wojtek-t wojtek-t added the cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. label Aug 2, 2017
k8s-github-robot pushed a commit that referenced this pull request Aug 2, 2017
…9897-#49898-release-1.7

Automatic merge from submit-queue

Automated cherry pick of #49897 #49898 release 1.7

Cherrypick of  #49897 #49898
Part of #49895
```release-note
In GCE, add measures to prevent corruption of known_tokens.csv
```
@k8s-cherrypick-bot
Copy link

Commit found in the "release-1.7" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked.

@enisoc enisoc added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Aug 4, 2017
k8s-github-robot pushed a commit that referenced this pull request Aug 5, 2017
…9897-#49898-release-1.6

Automatic merge from submit-queue

Automated cherry pick of #49897 #49898 release 1.6

Cherrypick of  #49897 #49898
Part of #49895
```release-note
In GCE, add measures to prevent corruption of known_tokens.csv
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.