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

server/api/admin: change the tso parameter of ResetTS to string #1896

Merged
merged 6 commits into from Nov 7, 2019

Conversation

5kbpers
Copy link
Member

@5kbpers 5kbpers commented Nov 5, 2019

Signed-off-by: 5kbpers tangminghua@pingcap.com

What problem does this PR solve?

the JSON lib can only marshall number to float64 type, which may lose precision when converting the tso parameter from uint64 to float64.

What is changed and how it works?

This PR changes the tso parameter of ResetTS to string to avoid precision losing.

Check List

Tests

  • Unit test

Code changes

  • Has HTTP API interfaces change

Signed-off-by: 5kbpers <tangminghua@pingcap.com>
@5kbpers 5kbpers requested a review from nolouch November 5, 2019 08:51
@CLAassistant
Copy link

CLAassistant commented Nov 5, 2019

CLA assistant check
All committers have signed the CLA.

server/api/admin_test.go Show resolved Hide resolved
Copy link
Contributor

@lhy1024 lhy1024 left a comment

Choose a reason for hiding this comment

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

LGTM. except CI.

Signed-off-by: 5kbpers <tangminghua@pingcap.com>
@codecov-io
Copy link

codecov-io commented Nov 6, 2019

Codecov Report

Merging #1896 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1896      +/-   ##
==========================================
+ Coverage   77.79%   77.83%   +0.04%     
==========================================
  Files         163      163              
  Lines       16333    16337       +4     
==========================================
+ Hits        12706    12716      +10     
+ Misses       2617     2614       -3     
+ Partials     1010     1007       -3
Impacted Files Coverage Δ
server/api/admin.go 69.44% <100%> (+3.81%) ⬆️
pkg/testutil/operator_check.go 88.88% <0%> (-11.12%) ⬇️
server/region_syncer/client.go 82.89% <0%> (-2.64%) ⬇️
pkg/btree/btree.go 86.94% <0%> (+0.8%) ⬆️
server/member/leader.go 78.57% <0%> (+3.06%) ⬆️
pkg/etcdutil/etcdutil.go 88.4% <0%> (+5.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37efcb0...738a00f. Read the comment docs.

@nolouch
Copy link
Contributor

nolouch commented Nov 6, 2019

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 6, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Nov 6, 2019

/run-all-tests

@5kbpers 5kbpers added the needs-cherry-pick-release-3.1 The PR needs to cherry pick to release-3.1 branch. label Nov 6, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Nov 6, 2019

@5kbpers merge failed.

@5kbpers
Copy link
Member Author

5kbpers commented Nov 6, 2019

/run-integration-common-test

server/api/admin_test.go Outdated Show resolved Hide resolved
Signed-off-by: 5kbpers <tangminghua@pingcap.com>
@@ -59,13 +59,18 @@ func (h *adminHandler) ResetTS(w http.ResponseWriter, r *http.Request) {
if err := apiutil.ReadJSONRespondError(h.rd, w, r.Body, &input); err != nil {
return
}
ts, ok := input["tso"].(float64)
if !ok || ts < 0 {
tsValue, ok := input["tso"].(string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use uint64as the type?

Copy link
Member

Choose a reason for hiding this comment

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

There is no such thing in js spec. 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

Considering this: https://play.golang.org/p/8-COmwYna7T

I think it is supported in go.

Copy link
Contributor

@shafreeck shafreeck Nov 6, 2019

Choose a reason for hiding this comment

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

I think it also works by defining var input map[string]uint64.

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
Member

Choose a reason for hiding this comment

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

I'm afraid of it does not work in other languages, eg, rust, as it's not specified in json spec.

Copy link
Contributor

Choose a reason for hiding this comment

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

@overvenus The language does not matter much, maybe the encoding library does. However, there should be no precision loss when encoding a number because that JSON is based on text not binary.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you encode a large number into JSON, it is just a sequence of digitals. IMO there is no reason for an encoding library to lose precision.

@overvenus overvenus closed this Nov 6, 2019
@overvenus overvenus reopened this Nov 6, 2019
server/api/admin_test.go Outdated Show resolved Hide resolved
@shafreeck shafreeck removed the status/can-merge Indicates a PR has been approved by a committer. label Nov 6, 2019
Signed-off-by: 5kbpers <tangminghua@pingcap.com>
@nolouch
Copy link
Contributor

nolouch commented Nov 7, 2019

PTAL @shafreeck @overvenus

@overvenus overvenus added the status/can-merge Indicates a PR has been approved by a committer. label Nov 7, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Nov 7, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Nov 7, 2019

cherry pick to release-3.1 in PR #1909

overvenus pushed a commit that referenced this pull request Nov 7, 2019
… (#1909)

Signed-off-by: 5kbpers <tangminghua@pingcap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-3.1 The PR needs to cherry pick to release-3.1 branch. status/can-merge Indicates a PR has been approved by a committer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants