-
Notifications
You must be signed in to change notification settings - Fork 719
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
config: rewrite and persist config file #2153
Conversation
Signed-off-by: Ryan Leung <rleungx@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
return nil | ||
} | ||
var buf bytes.Buffer | ||
if err := toml.NewEncoder(&buf).Encode(*new); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it also writes out hidden configurations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
slice := make([]interface{}, 0) | ||
for _, str := range strSlice { | ||
slice = append(slice, str) | ||
// TODO: handle slice better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain how it is not good enough now?
// TODO: handle slice better | ||
if item, ok := updateItem.(string); ok { | ||
strSlice := strings.Split(item, ",") | ||
slice := make([]interface{}, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var slice []interface{}
or make([]interface{}, 0, len(strSlice))
Signed-off-by: Ryan Leung <rleungx@gmail.com>
server/config/config.go
Outdated
return err | ||
} | ||
// 0644 represent the permission of file which is "-rw-r--r--" here. | ||
return ioutil.WriteFile(filePath, buf.Bytes(), 0644) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid corrupted content during lost power, we should:
- write the content to temp file
- sync the temp file
- rename the temp file to the config file.
Signed-off-by: Ryan Leung <rleungx@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
dir := filepath.Dir(filePath) | ||
tmpfile := filepath.Join(dir, "tmp_pd.toml") | ||
|
||
f, err := os.Create(tmpfile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default permission is 0666, should we change it to 0644?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's unnecessary?
Codecov Report
@@ Coverage Diff @@
## master #2153 +/- ##
==========================================
- Coverage 76.03% 75.99% -0.04%
==========================================
Files 195 195
Lines 20376 20405 +29
==========================================
+ Hits 15493 15507 +14
- Misses 3695 3710 +15
Partials 1188 1188
Continue to review full report at Codecov.
|
/merge |
/run-all-tests |
@rleungx merge failed. |
/run-all-tests |
1 similar comment
/run-all-tests |
/merge |
/run-all-tests |
@rleungx merge failed. |
/merge |
/run-all-tests |
will the comments in the old config file get persisted in the updated config file? |
This feature has been removed, it won't rewrite the config file now |
Oh😱... |
AFAIK, If you use BurntSushi/toml, there are issues that have some solution to do it, but they are not the official way, otherwise, you need to implement it by yourself. |
got it, thx. |
What problem does this PR solve?
After we enable the dynamic config, we will rewrite the config file and persist it once the config has been updated. Related to tikv/tikv#6684
What is changed and how it works?
The PR adds a new function named
RewriteFile
to do it.Check List
Tests