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: snowflake remove network dependency #947

Merged
merged 3 commits into from
Dec 2, 2020

Conversation

gxthrj
Copy link
Contributor

@gxthrj gxthrj commented Dec 2, 2020

Please answer these questions before submitting a pull request


Bugfix

  • Description
    remove network dependency for snowflake

  • How to fix?
    Get IP in local

_sf = sonyflake.NewSonyflake(sonyflake.Settings{
MachineID: func() (u uint16, e error) {
return sumIP(GetOutboundIP()) + salt, nil
return sumIP(randomIP(ips)) + salt, nil
Copy link
Member

Choose a reason for hiding this comment

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

how about sum all local ips?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think one is enough, it is for machineID, one or all IPs are the same :)

Copy link
Member

Choose a reason for hiding this comment

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

may it meet 127.0.0.1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, 127.0.0.1 is filtered out

Copy link
Member

Choose a reason for hiding this comment

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

👌

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is a risk that different instance may be get the same IP in multiple network environment (such as virtual network ), calculating all IP would be better when we can not confirm which is physical network interface.

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, you convinced me.
Done.

@membphis membphis added this to the 2.1.1 milestone Dec 2, 2020
@membphis
Copy link
Member

membphis commented Dec 2, 2020

@ShiningRush please take a look at this RP when you have time ^_^

we need to fix this issue today

@codecov-io
Copy link

Codecov Report

Merging #947 (7b9ff24) into master (95f2612) will increase coverage by 0.08%.
The diff coverage is 68.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #947      +/-   ##
==========================================
+ Coverage   43.10%   43.18%   +0.08%     
==========================================
  Files          18       18              
  Lines        1290     1299       +9     
==========================================
+ Hits          556      561       +5     
- Misses        642      644       +2     
- Partials       92       94       +2     
Impacted Files Coverage Δ
api/internal/utils/utils.go 52.50% <68.75%> (+0.88%) ⬆️

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 95f2612...7b9ff24. Read the comment docs.

@membphis
Copy link
Member

membphis commented Dec 2, 2020

@gxthrj please take a look at the output of CI

image

@membphis membphis added backend bug Something isn't working labels Dec 2, 2020
@gxthrj
Copy link
Contributor Author

gxthrj commented Dec 2, 2020

@gxthrj please take a look at the output of CI

image

Fixed.


localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP
func randomIP(xs []net.IP) net.IP {
Copy link
Contributor

Choose a reason for hiding this comment

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

So we can remove unused code and test case.
BTW: this is not a really random, because here use the default random seed, so it will always output a certain int sequence.If we need to pick a ip, pick the first one would be better, it help to debug program.

@membphis membphis merged commit 3123c43 into apache:master Dec 2, 2020
@gxthrj gxthrj deleted the kv/snowflake branch December 2, 2020 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic: dial udp 8.8.8.8:80: connect: network is unreachable
5 participants