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

[ADDED] js_PullSubscribeAsync #785

Merged
merged 27 commits into from
Sep 18, 2024
Merged

[ADDED] js_PullSubscribeAsync #785

merged 27 commits into from
Sep 18, 2024

Conversation

levb
Copy link
Collaborator

@levb levb commented Aug 8, 2024

A replacement for #773 that seems to have lost its proper base in GitHub after changing it.

Copy link

codecov bot commented Aug 8, 2024

Codecov Report

Attention: Patch coverage is 71.71946% with 125 lines in your changes missing coverage. Please review.

Project coverage is 70.63%. Comparing base (1553d4a) to head (1fc9179).
Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
src/dispatch.c 76.25% 5 Missing and 52 partials ⚠️
src/js.c 66.66% 12 Missing and 42 partials ⚠️
src/glib/glib_dispatch_pool.c 68.18% 2 Missing and 5 partials ⚠️
src/sub.c 62.50% 0 Missing and 6 partials ⚠️
src/jsm.c 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #785      +/-   ##
==========================================
+ Coverage   68.71%   70.63%   +1.91%     
==========================================
  Files          39       47       +8     
  Lines       15207    15394     +187     
  Branches     3143     3163      +20     
==========================================
+ Hits        10449    10873     +424     
+ Misses       1700     1465     -235     
+ Partials     3058     3056       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@levb levb marked this pull request as ready for review August 8, 2024 22:51
@levb levb requested a review from kozlovic August 8, 2024 22:51
@levb
Copy link
Collaborator Author

levb commented Aug 8, 2024

@kozlovic Travis seems to have frozen, I'll check it later, passed previously.

@levb levb requested a review from mtmk August 8, 2024 22:52
examples/js-sub.c Outdated Show resolved Hide resolved
examples/js-sub.c Outdated Show resolved Hide resolved
examples/js-sub.c Outdated Show resolved Hide resolved
examples/js-sub.c Outdated Show resolved Hide resolved
src/dispatch.c Outdated Show resolved Hide resolved
src/js.c Outdated Show resolved Hide resolved
src/status.h Show resolved Hide resolved
test/test.c Show resolved Hide resolved
test/test.c Show resolved Hide resolved
test/test.c Show resolved Hide resolved
src/js.c Outdated Show resolved Hide resolved
@levb levb requested a review from kozlovic August 16, 2024 16:48
@levb
Copy link
Collaborator Author

levb commented Aug 16, 2024

@kozlovic I resolved the comments where I think I added obvious fixes for the feedback, please resolve the remaining as you find fit.

I added tests for handling connect and reconnect while fetching, and made sure that OnFetchComplete handler is called if/when the sub is closed for whatever reason(s).

There are some flappers registering on Travis in main and here likely related to the refactoring. I am investigating, but that'll be a separate PR for it.

@levb levb requested a review from Jarema August 16, 2024 16:56
jsOpts.PullSubscribeAsync.KeepAhead = 7;
jsOpts.PullSubscribeAsync.CompleteHandler = _completeFetchCb;

jsFetchRequest lifetime;
Copy link
Collaborator Author

@levb levb Aug 16, 2024

Choose a reason for hiding this comment

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

@kozlovic @Jarema @mtmk I chose to have a separate lifetime parameter as a shortcut for passing these options. 2/5 I am considering removing the extra parameter, and adding all these values to jsOpts.PullSubscribeAsync. (a) It would be more idiomatic; (b) arguably, CompleteHandler a more common use-case and they should be "level"-ed; and (c) the use of jsFetchRequest struct may be confusing since no such request will ever be made.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

You could. The thing I like about the options, is if we decide down the line that we need other option(s), then the function definition stays the same. We don't have to come up with a different function name, etc..
That being said, you could pass the parameters that seem essential at this time, and if in the future we need more, then add them through the options?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced lifetime with more jsOpts, looks cleaner.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Jarema @mtmk Can I please get your review on the API iteself (parameters, etc.) before we finalize this?

test/test.c Show resolved Hide resolved
test/test.c Show resolved Hide resolved
- Properly account for *received* fetch messages/bytes
- Fetch status set to NATS_CONNECTION_CLOSED if fetch is terminated by a disconnect
- Auto-Unsubscribe when the (pull async) subscription reaches the end of life(*)
- Handle errors from sending fetch requests(*)
- Disallow MaxBytes and KeepAhead simultaneously so we can set MaxBytes on subsequent requests accurately
- Unrelated: _unsubscribe should not stop timers for max>0
@levb levb requested a review from kozlovic August 23, 2024 10:04
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

(Going to review the last commit in another review)

src/js.c Outdated Show resolved Hide resolved
src/nats.h Outdated Show resolved Hide resolved
src/nats.h Outdated Show resolved Hide resolved
test/test.c Show resolved Hide resolved
test/test.c Show resolved Hide resolved
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

Nothing to add to that one.

@levb levb requested a review from kozlovic August 23, 2024 22:57
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

Small changes (no need for a typedef). The tests pass now on Windows.

src/nats.h Outdated Show resolved Hide resolved
src/js.c Show resolved Hide resolved
@levb
Copy link
Collaborator Author

levb commented Aug 24, 2024

@wallyqs FYI, many GHA jobs are still failing to download server images.

@levb levb requested a review from kozlovic August 24, 2024 13:31
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

LGTM. By the way, we may want to add to the list of disabled Windows warnings in the CMakeLists.txt: add_compile_options(/wd4204) # non-constant aggregate initializer. This is for when we do something like: myStruct s = {"a", i}; (when one of the initialization value is not a constant)

examples/js-sub.c Show resolved Hide resolved
examples/js-sub.c Outdated Show resolved Hide resolved
examples/js-sub.c Outdated Show resolved Hide resolved
examples/js-sub.c Outdated Show resolved Hide resolved
src/jsm.c Show resolved Hide resolved
src/nats.h Show resolved Hide resolved
@levb levb requested a review from Jarema August 28, 2024 14:16
// Defalut values, change as needed.
jsOpts.PullSubscribeAsync.FetchSize = 128; // ask for 128 messages at a time
jsOpts.PullSubscribeAsync.NoWait = false;
jsOpts.PullSubscribeAsync.Timeout = 0; // for the entire subscription, in milliseconds
Copy link
Member

Choose a reason for hiding this comment

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

This is fine,
But I think that each pull request should have 30s expires default value.
Otherwise if server looses the Pull Requst, client will never know about it.

Similarly, HeartBeats should be enabled by default, with a value of 15 seconds (half of expires, which is maximum).

Copy link
Collaborator Author

@levb levb Aug 29, 2024

Choose a reason for hiding this comment

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

@Jarema First, 1/5 I don't think that subscription-level Expires/Timeout should be defaulted on. By default, a sub should live until Unsubscribe, that's the idiom. A separate FetchTimeout (was Batch a better name?) would solve this issue but also add complexity and potential confusion.

Second, if the heartbeats are ON, and the server loses a pull request, the client will know about because of the missing heartbeat error. So, if we make heartbeat ON by default at some number of seconds why add a default timeout?

There is also a small issue of how to package "No Heartbeat" if the 0 value is defaulted on. A separate flag also adds complexity and may lead to confusion. Hearbeat=-1 would not be very intention-revealing IMO.

Copy link
Member

Choose a reason for hiding this comment

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

I agree on not having timeout on subscription. In fact, none other clients have that option at all.
If you want to stop subscription, stop it explicitly, or do drain. We never do timeouts like thoge.

What I meant however, is expires value for each pull requst, and heartbeats for those pull requests too.

@levb levb requested a review from Jarema August 29, 2024 16:12
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

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

LGTM

@levb levb merged commit 3de6a67 into main Sep 18, 2024
30 checks passed
@levb levb deleted the lev-sub-pull-async-try2 branch September 18, 2024 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants