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

refactor(clustering) dpcp config clean #8880

Closed
wants to merge 68 commits into from

Conversation

chronolaw
Copy link
Contributor

@chronolaw chronolaw commented May 30, 2022

Summary

DP/CP's code is too complex and not human readable, it is hard to understand the callback workflows.

This PR separates the logic of update_config, moves the code into an isolated file,
and also de-coupled dp/cp modules.

Full changelog

  • separates the logic of update_config into config_helper.lua
  • do not use self to mimic oop
  • remove duplicated functions extract_major_minor and validate_shared_cert in wrpc_cp
  • add many functions in utils.lua
  • remove version_handshake
  • update config hash test case

Comment on lines +89 to +92
if j % 100 == 0 then
i = 1
o[i] = ngx_md5_bin(concat(o, ";", 1, 100))
end
Copy link
Contributor

Choose a reason for hiding this comment

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

are there plans to fix this off-by-one error?

on every j==n*100, replaces all values in o with a hash of the first 100 and sets i to 1, so the next value (number 101) will go on o[2]. So when j==200, there will be 101 values in o (the last hash plus 100 values more) but it will again use only 100 values for the next hash, so it drops the hashes values of items number 201, 301, 401.... etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems true. Shall we fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe we can use local i = 1 and new_tab(count < 100 and count +1 or 101, 0)

Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we fix it?

I don't know. mentioned it just that it can be discussed. probably in a separate PR.

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 perhaps we can not change it because of the compatibility of old version.

Copy link
Contributor

Choose a reason for hiding this comment

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

the hash method has changed several times already. there's no compatibility issue

Copy link
Member

Choose a reason for hiding this comment

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

Let's fix the off-by-one error on this PR then then. Another PR will make everything take even longer.

Copy link
Member

Choose a reason for hiding this comment

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

It will force us to modify all the hashes on the test, which is a pain.

New directive: Do it only if it can be done quickly on this PR. We have lived with the problem so far.

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 we can do it later, now we should finish refactoring first.

Comment on lines -68 to -70
["kong.clustering.version_negotiation"] = "kong/clustering/version_negotiation/init.lua",
["kong.clustering.version_negotiation.services_known"] = "kong/clustering/version_negotiation/services_known.lua",
["kong.clustering.version_negotiation.services_requested"] = "kong/clustering/version_negotiation/services_requested.lua",
Copy link
Contributor

Choose a reason for hiding this comment

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

when is this coming back?

Copy link
Member

Choose a reason for hiding this comment

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

Without these, this PR is doing more than a refactor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After this PR, we will try another method to implement similar feature.

Comment on lines +89 to +92
if j % 100 == 0 then
i = 1
o[i] = ngx_md5_bin(concat(o, ";", 1, 100))
end
Copy link
Member

Choose a reason for hiding this comment

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

Let's fix the off-by-one error on this PR then then. Another PR will make everything take even longer.

kong/clustering/config_helper.lua Show resolved Hide resolved
kong/clustering/init.lua Outdated Show resolved Hide resolved
if hashes then
fill_empty_hashes(hashes)
end
local config_proto, msg = check_protocol_support(self.conf, self.cert, self.cert_key)
Copy link
Member

Choose a reason for hiding this comment

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

Can this be delayed until later? I mean: We leave it on init_worker for now in order to try to reach feature freeze, and we change it to something more robust as a bugfix, if we end up needing the resilience.

kong/clustering/wrpc_data_plane.lua Show resolved Hide resolved
kong/templates/nginx_kong.lua Show resolved Hide resolved
Comment on lines +89 to +92
if j % 100 == 0 then
i = 1
o[i] = ngx_md5_bin(concat(o, ";", 1, 100))
end
Copy link
Member

Choose a reason for hiding this comment

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

It will force us to modify all the hashes on the test, which is a pain.

New directive: Do it only if it can be done quickly on this PR. We have lived with the problem so far.

Comment on lines -68 to -70
["kong.clustering.version_negotiation"] = "kong/clustering/version_negotiation/init.lua",
["kong.clustering.version_negotiation.services_known"] = "kong/clustering/version_negotiation/services_known.lua",
["kong.clustering.version_negotiation.services_requested"] = "kong/clustering/version_negotiation/services_requested.lua",
Copy link
Member

Choose a reason for hiding this comment

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

Without these, this PR is doing more than a refactor.

@kikito kikito added this to the 3.0 milestone Jun 1, 2022
@chronolaw
Copy link
Contributor Author

This PR has conflicts with #8888, I create a new one #8893.

@chronolaw chronolaw closed this Jun 3, 2022
fffonion pushed a commit that referenced this pull request Jun 6, 2022
### Summary
DP/CP's code is too complex and not human readable, it is hard to understand the callback workflows.

This PR separates the logic of update_config, moves the code into an isolated file,
and also de-coupled dp/cp modules.

This PR is same as #8880, but solved the merge conflict of #8888.

### Full changelog
* separates the logic of `update_config` into `config_helper.lua`
* do not use `self` to mimic oop
* remove duplicated functions `extract_major_minor `and `validate_shared_cert` in wrpc_cp
* add many functions in `utils.lua`
* remove `version_handshake`
* pick #8888's yield feature in `to_sorted_string`
* update config hash test case
@mayocream mayocream removed this from the 3.0 milestone Jun 7, 2022
@bungle bungle deleted the refactor/dpcp_config_clean branch October 14, 2022 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants