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
libflux: update flux msg route functions #3746
libflux: update flux msg route functions #3746
Conversation
51a856e
to
8809998
Compare
If we're going to change the API anyway, maybe we ought to update it to look more like other similar interfaces in flux:
So maybe void flux_msg_route_enable (flux_msg_t *msg);
void flux_msg_route_clear (flux_msg_t *msg);
int flux_msg_route_push (flux_msg_t *msg, const char *id);
char *flux_msg_route_pop (flux_msg_t *msg);
const char *flux_msg_route_first (flux_msg_t *msg);
const char *flux_msg_route_last (flux_msg_t *msg);
int flux_msg_route_count (flux_msg_t *msg);
// wondering if this is needed externally?
char *flux_msg_route_string (const flux_msg_t *msg);
// wondering if this is worth it, given it is easier now to access routes and compare?
bool flux_msg_route_match_first (const flux_msg_t *msg1, const flux_msg_t *msg2); |
@garlick sounds like a good idea. I assume your removal of |
Sorry, yup that was an accident. |
I tried to make this conversion in an earlier prototyping attempt, but reverted it. Unlike some other functions we have, a return of a NULL id is sort of ok, indicating there are no routes. So NULL can't be used as an indicator of error. So I kept the style the same. What's the opinion on the NULL means no routes or error style? When I made the conversion earlier I did add something like:
in a few places as a consequence. I felt it was too much of a change, but that's just me of course. |
given the rest of the msg API doesn't return void, I think it'd be better to return int on error? e.g. these funcs call |
It seems like "invalid flag" (which can't happen) or "null message" (which by the time you're setting flags, you probably know you have a good message) are the main possible errors. Since it is painfully repetitious to check for errors from these functions, it seems to me like these could just not crash on a NULL msg and be OK. I felt the same way about the route accessors. Return NULL for "no route" when there is no route, or if there is an error. By the time you're accessing the routes, you probably know you have a good message. I might be missing some subtle error case though. (But if there is one we should decide if it's worth it). |
The only user outside of
w/ the newer Ehhh ... it's sort of borderline. My lazy immediate thought is to keep the function, otherwise we'd have to do:
in 3 places :-| |
8809998
to
9ca1a0a
Compare
re-pushed with many cleanups per discussion above and a few extra pre-cleanups (borderline could peel them off into a new PR, but it's not quite there I think). Note that the commits:
could be squashed, but I let them be separate for easier review for now. Since there's no way to know if a return of NULL is an error or empty route, in some cases I set Returning void for
I could have done some trickery to avoid this, but figured I the average person might be confused if I did |
Maybe |
Doh, i thought about that last night and just forgot to try it. I'll give it a shot. |
Were you amenable to the rename suggestion above? E.g. use Also would it be OK to have |
yup, it worked out fine.
We can, but the semantics of that function are different. B/c we're popping a route frame, we're destroying the internal copy. So we sort of always have to But the inconsistent API style can be annoying. Perhaps we just need another function, |
I think peek/top would be the same as "first", wouldn't it? Maybe |
Did you already push the name changes? I wasn't seeing them in my copy. Edit: oh I just saw that "push_route" and "pop_route" wasn't renamed. I see the other functions were renamed. |
Doh! Sorry, I missed those. I was probably processing the removal of |
I'm thinking maybe we ought to bump this to the next release and try to tag soon. That ok @chu11? |
@garlick that's fine, i had assumed this was going to be for the next release already. Minimally it requires flux-sched to be changed too. |
Did a prototype of this change. It's fine I guess, but I dislike the inconsistency (sometimes calling enable_route, sometimes not). But leads to an obvious question, do we even need I imagine it was needed in the old Edit: oh wait, does a zmsg have to have a delimeter on it? even if no routes are added to it? |
I think you do need to add a delimiter with no routes before sending a request from a ROUTER socket. The socket then pushes the identity on before the message is sent to a peer. So there are cases where you want the delimiter but not routes. Reading through the ZMQ_ROUTER section of zmq_socket(3) I'm now questioning whether the delimiter is necessary! It may just be a hold over from ZMQ_REQ / ZMQ_REP which nobody uses. |
0360a19
to
469e720
Compare
re-pushed per comments above
Edit (7/8) - added one random cleanup commit |
506322f
to
ceb2816
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.
Alright this is looking good. I'm fine if this goes in when you are ready. Does the sched PR need any updating?
@garlick Yup, the I can't set MWP here b/c of the (I'll rebase so it'll be ready for manual merge). |
To manually merge we'll have to remove branch protections, merge, then re-establish branch protections. I can help with that when you are ready. |
ceb2816
to
f6d3215
Compare
@grondo, thanks Just re-based, so once it passes we can do a manual merge, then i'll kick the flux-sched side to re-do its tests. |
code coverage builder timed out, restarted builders |
f6d3215
to
0f71ade
Compare
since this wasn't yet merged, I snuck one more cleanup in. Should be reviewed before merging. The cleanup is in commit:
|
0f71ade
to
b307ed2
Compare
sorry, i snuck in one more cleanup
|
b307ed2
to
f669ed6
Compare
found yet another minor thing to cleanup, so I went ahead and peeled all those cleanups onto #3771, so that should go in first. |
Problem: The functions flux_msg_get_route_first() and flux_msg_get_route_last() return route IDs via an allocated string that must be freed by the user. This API made sense previously when route IDs were stored internally in a zframe. However, now that the route IDs are stored in decoded data structures, we could return the route IDs directly. In addition, returning this field as an in-and-out parameter is not consistent to most of the code in flux-core. Solution: Return internally stored route IDs via a const char * return parameter instead of an in-and-out paramter. Update callers accordingly.
Problem: The flux_msg_pop_route() function returns an id via an in-and-out parameter that requires a memory allocation/free. With flux_msg_get_route_last() now returning a `const char *`, users can avoid the memory allocation/free if there was a way to remove the last route on the message when necessary. Solution: Provide a new function flux_msg_delete_route_last() that will behave similarly to flux_msg_pop_route() but not allocate memory or require the user to pop a route off the message. Convert any callers that call flux_msg_pop_route() with a NULL 'id' parameter to use flux_msg_delete_route_last() instead. Add unit tests.
Problem: flux_msg_pop_route() allocates memory to return the route id that is being "popped". Under most circumstances users can call flux_msg_get_route_last() and flux_msg_delete_route_last() to get the same effect and not allocate memory. Solution: Remove flux_msg_pop_route(). Update callers accordingly.
Problem: flux_msg_enable_route() and flux_msg_clear_route() return an int on success/error. For such simple functions, most of flux-core returns void for these types of functions. Solution: Have flux_msg_enable_route() and flux_msg_clear_route() return void. Update all callers appropriately.
Problem: libflux currently supports flux_msg_enable_route() and flux_msg_clear_route(), which seem imbalanced. Hypothethically, there should be a flux_msg_disable_route(). Solution: Add a new function flux_msg_disable_route() that behaves identically to flux_msg_clear_route() before this commit. Change the behavior of flux_msg_clear_route() to only clear internally stored route ids, not to disable routing on a message. Adjust all callers accordingly. In locations that previously called flux_msg_clear_route() and flux_msg_enable_route() in series, only call flux_msg_clear_route().
Problem: The naming of the flux msg route functions was inconsistent, with some prefixing the action with "get" while others not. Some stating the "action" before "route" and others not. Solution: Make the function names consistent. Specifically, the following functions have been renamed. flux_msg_enable_route -> flux_msg_route_enable flux_msg_disable_route -> flux_msg_route_disable flux_msg_clear_route -> flux_msg_route_clear flux_msg_push_route -> flux_msg_route_push flux_msg_delete_route_last -> flux_msg_route_delete_last flux_msg_get_route_first -> flux_msg_route_first flux_msg_get_route_last -> flux_msg_route_last flux_msg_get_route_count -> flux_msg_route_count flux_msg_get_route_string -> flux_msg_route_string flux_msg_match_route_first -> flux_msg_route_match_first Some internal functions were renamed as well for consistency. Update all callers appropriately.
f669ed6
to
bb42869
Compare
rebased. None of the "snuck in" commits are here anymore, just the ones that @garlick reviewed. |
Codecov Report
@@ Coverage Diff @@
## master #3746 +/- ##
==========================================
+ Coverage 83.29% 83.31% +0.02%
==========================================
Files 342 342
Lines 50982 50897 -85
==========================================
- Hits 42464 42405 -59
+ Misses 8518 8492 -26
|
Ok, I'm going to remove branch protections, merge, and then reset branch protections. |
I'll just post what is in the primary commit message here:
If you're wondering why don't I put this change in one of the other libflux refactoring PRs, its b/c
flux-sched
needs updating too, so figure a separate PR would be best.I had some further design thoughts too which I'll post in #3617.