Skip to content

fix(etcd): upgrade revision when watch request timeout#12514

Merged
nic-6443 merged 6 commits into
apache:masterfrom
nic-6443:nic/etcd-compact-err
Aug 18, 2025
Merged

fix(etcd): upgrade revision when watch request timeout#12514
nic-6443 merged 6 commits into
apache:masterfrom
nic-6443:nic/etcd-compact-err

Conversation

@nic-6443

@nic-6443 nic-6443 commented Aug 12, 2025

Copy link
Copy Markdown
Member

Description

When multiple APISIX clusters connect to the same etcd cluster, each APISIX cluster uses a different etcd.prefix to distinguish configurations.
In this case, it is possible that the configuration of Cluster A changes frequently while the configuration of Cluster B remains unchanged. Since etcd revision is globally shared, this will cause the etcd client of Cluster B to always use an old revision when requesting the /watch API.
When revisions continue updating for a certain period and trigger etcd's compact mechanism, it will result in a watch API error: compact error, which in turn causes APISIX in Cluster B to need to resynchronize data fully. This operation consumes a lot of computational resources from both the gateway and etcd.
In this PR, after a timeout occurs while watch request, we initiate the watch request again with the latest revision to avoid the above issue.

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Fixes #12167

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 12, 2025
@nic-6443
nic-6443 force-pushed the nic/etcd-compact-err branch from 9804ffe to 0e78c8c Compare August 12, 2025 12:29
Comment thread t/xrpc/pingpong.t
--- log_level: debug
--- no_error_log
stream lua tcp socket set keepalive
stream lua tcp socket keepalive create connection pool for key "127.0.0.1:1995"

@nic-6443 nic-6443 Aug 14, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because the current PR send a readdir request before the watch request, it causes the etcd client to trigger keepalive logs, making the old assertion fail.
Therefore, this assertion is modified to explicitly target keepalive log of xrpc upstream to avoid matching etcd client's keepalive logs.

goto watch_event
end

--[[

@nic-6443 nic-6443 Aug 14, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nic-chen
nic-chen previously approved these changes Aug 14, 2025
@nic-6443
nic-6443 requested a review from AlinsRan August 18, 2025 00:52
membphis
membphis previously approved these changes Aug 18, 2025

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, only one minor issue

Comment thread apisix/core/config_etcd.lua Outdated
Co-authored-by: YuanSheng Wang <[email protected]>
@nic-6443
nic-6443 dismissed stale reviews from membphis and nic-chen via fd759f7 August 18, 2025 03:29
@nic-6443
nic-6443 requested review from membphis and nic-chen August 18, 2025 03:29
nic-chen
nic-chen previously approved these changes Aug 18, 2025
membphis
membphis previously approved these changes Aug 18, 2025
f
Signed-off-by: Nic <[email protected]>
@nic-6443
nic-6443 dismissed stale reviews from membphis and nic-chen via 68f6205 August 18, 2025 06:03
@nic-6443
nic-6443 requested review from membphis and nic-chen August 18, 2025 06:03
@nic-6443
nic-6443 merged commit dac0b55 into apache:master Aug 18, 2025
23 checks passed
@nic-6443
nic-6443 deleted the nic/etcd-compact-err branch August 18, 2025 07:39
jizhuozhi pushed a commit to jizhuozhi/apisix that referenced this pull request Oct 18, 2025
shreemaan-abhishek pushed a commit to shreemaan-abhishek/apisix that referenced this pull request Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: When etcd compacted, apisix cpu usage increase.

4 participants