-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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/sync): improve readability and debugability #14170
Conversation
7bd1142
to
00bb83b
Compare
00bb83b
to
1a34b5a
Compare
537d6f2
to
b18175b
Compare
ee07453
to
43975e3
Compare
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.
nice!! all my comments are included in its associated EE pr, which have been resolved by xuming already
d9940f1
to
2ecd057
Compare
354b255
to
2918b81
Compare
1. abstract functions and reshape the code, including error handling 2. extra call to notify CP the state of sync; 3. more debuging logs; 4. sync once retry will not count timeout as retry, allowing DP to sync deltas right after a full sync KAG-6177
2918b81
to
8ae2931
Compare
end | ||
|
||
|
||
local function lmdb_delete_impl(db, t, typ, opts, delete_if_exist, old_entity, find_entity_err) |
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 that it is premature optimization, the original code is easy to understand.
ngx_log(ngx_ERR, err) | ||
|
||
if is_full_sync then | ||
return do_sync() -- retry without releasing the mutex as the DP has nothing to do except syncing |
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.
It changed the original behavior, could we do it in another PR?
t:db_drop(false) | ||
end | ||
|
||
local db = kong.db | ||
|
||
local version = "" | ||
local version = current_version |
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.
What's the difference between this and ""? and improvement?
if not ok then | ||
return nil, err | ||
end | ||
return events.declarative_reconfigure_notify(reconfigure_data) |
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.
Not very useful refactor, it don't give us more improvement.
@@ -400,17 +433,27 @@ function sync_once_impl(premature, retry_count) | |||
local current_version = get_current_version() | |||
if current_version >= latest_notified_version then | |||
ngx_log(ngx_DEBUG, "version already updated") | |||
return | |||
return sync_handler() -- call get_delta once more to report to the CP that we are up-to-date |
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.
It changed the original behavior, could we do it in another PR?
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'd agree. The refactor PR should only contain refactor and other behavior changes should be put into a separate PR. This way it will makes the reviewers lives easier and also make it easier to track issues in the future.
if err ~= "timeout" then | ||
retry_count = retry_count + 1 | ||
end |
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.
Please refer to the tests in #14174 to ensure it will not break the cases.
-- in some cases, the new spawned timer will be switched to immediately, | ||
-- preventing the coroutine who possesses the mutex to run | ||
-- to let other coroutines has a chance to run | ||
yield() |
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.
It changed the original behavior, could we do it in another PR?
I suggest that this PR should be a PURE refactor PR, not introduce any feature or change. |
end | ||
|
||
-- ns_deltas should look like: | ||
-- { default = { deltas = { ... }, wipe = true, }, } | ||
-- { default = { deltas = { ... } }, } |
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.
Why remove the comments?
Summary
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
KAG-6177