Skip to content

cache: Add on-demand progress notification from cache#21545

Open
akstron wants to merge 1 commit intoetcd-io:mainfrom
akstron:dev/progress-notification
Open

cache: Add on-demand progress notification from cache#21545
akstron wants to merge 1 commit intoetcd-io:mainfrom
akstron:dev/progress-notification

Conversation

@akstron
Copy link
Copy Markdown
Contributor

@akstron akstron commented Mar 29, 2026

Add Cache.RequestProgress() method that mirrors the etcd Watcher.RequestProgress API but is served entirely from the cache. It broadcasts a progress notification at the cache's current revision to all active local watchers.

Also, used AI for writing tests.

Part of #19371

@k8s-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: akstron
Once this PR has been reviewed and has the lgtm label, please assign siyuanfoundation for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Copy Markdown

Hi @akstron. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@akstron akstron force-pushed the dev/progress-notification branch 3 times, most recently from 8adc2a8 to 3f10b5f Compare April 1, 2026 14:17
d.BroadcastProgress()

resps1 := readResponses(t, w1, 1)
require.Truef(t, resps1[0].IsProgressNotify(), "expected progress notify")
Copy link
Copy Markdown
Member

@serathius serathius Apr 1, 2026

Choose a reason for hiding this comment

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

nit: assert len(resps1) == 1 or whatever is the size we expect

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

readResponses is a test utility, which will always return the number of responses it is asked to read. If it can't it will timeout and the test will fail. So, we don't have to add assert len(resps1) == 1

require.Truef(t, resps2[0].IsProgressNotify(), "expected progress notify")
require.Equal(t, int64(10), resps2[0].Header.Revision)

d.maxRev = 0
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.

Nit: Validating different scenario, like if progress is sent on unsychronized demux, should be a separate test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines +581 to +586
for i := 0; i < 3; i++ {
select {
case resp := <-watchCh:
if resp.Canceled {
t.Fatalf("unexpected canceled response: %v", resp.CancelReason)
}
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.

There is no guarantee that 3 events will be put into 3 responses, this might work locally but will flake on CI. It's up to demux to group it as it pleases. Instead of reading from channel 3 times, we should collect responses until the aggregated event count get to 3.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done. thanks


ctx := t.Context()

c, err := cache.New(client, "/foo")
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.

For future would be good to also test if the progress notification progresses if writes were done outside of prefix. This would require to also propagate progress request to watch under the cache. It would require some rate limiting so we don't have multiple watchers on cache requesting progress that is demultiplexed on one watch.

Copy link
Copy Markdown
Contributor Author

@akstron akstron Apr 2, 2026

Choose a reason for hiding this comment

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

Makes sense. This would require sending progress request to the etcd server. Should we just implement that instead of this? But this would also mean that each progress request will now make a network call.

Signed-off-by: Alok Kumar Singh <dev.alok.singh123@gmail.com>
@akstron akstron force-pushed the dev/progress-notification branch from 3f10b5f to bfc3ffe Compare April 2, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants