-
Notifications
You must be signed in to change notification settings - Fork 49
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
Sort alphabetically fill_names_and_types #536
base: rolling
Are you sure you want to change the base?
Conversation
Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
hmm we actually introduced |
@Yadunund According with the documentation in the code, we use a ordered map but remember by insertion https://github.com/ros2/rmw_zenoh/blob/rolling/rmw_zenoh_cpp/src/detail/graph_cache.hpp#L85-L88 I reruned all the stack I can't see any new error |
Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
My point is that we explicitly switched to the custom ordered_map which preserves insertion order as some parts of the ROS 2 stack required this when calling get_names_and _types. |
I browsed the other DDS-based implementations. They use the To align with them, we can preserve the |
A small suggestion: For better efficiency, we can create and sort only the keys. I also tried wrapping the diff --git a/rmw_zenoh_cpp/src/detail/graph_cache.cpp b/rmw_zenoh_cpp/src/detail/graph_cache.cpp
index e24a53e..e8c1d8d 100644
--- a/rmw_zenoh_cpp/src/detail/graph_cache.cpp
+++ b/rmw_zenoh_cpp/src/detail/graph_cache.cpp
@@ -770,15 +770,24 @@ rmw_ret_t fill_names_and_types(
});
// Fill topic names and types.
std::size_t index = 0;
- for (const std::pair<std::string, GraphNode::TopicTypeMap> & item : entity_map) {
- names_and_types->names.data[index] = rcutils_strdup(item.first.c_str(), *allocator);
+
+ // Sort the topics of entity_map alphabetically
+ std::vector<std::string> sorted_topics;
+ for (const auto & item : entity_map) {
+ sorted_topics.push_back(item.first);
+ }
+ std::sort(sorted_topics.begin(), sorted_topics.end());
+
+ for (const auto & topic : sorted_topics) {
+ names_and_types->names.data[index] = rcutils_strdup(topic.c_str(), *allocator);
if (!names_and_types->names.data[index]) {
return RMW_RET_BAD_ALLOC;
}
+ auto topic_map = entity_map.at(topic);
rcutils_ret_t rcutils_ret = rcutils_string_array_init(
&names_and_types->types[index],
- item.second.size(),
+ topic_map.size(),
allocator);
if (RCUTILS_RET_OK != rcutils_ret) {
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
@@ -786,7 +795,7 @@ rmw_ret_t fill_names_and_types(
}
size_t type_index = 0;
- for (const std::pair<const std::string, GraphNode::TopicQoSMap> & type : item.second) {
+ for (const std::pair<const std::string, GraphNode::TopicQoSMap> & type : topic_map) {
char * type_name = rcutils_strdup(_demangle_if_ros_type(type.first).c_str(), *allocator);
if (!type_name) {
RMW_SET_ERROR_MSG("failed to allocate memory for type name"); |
If I use a I can see some error in rcl: 97 - test_get_node_names__rmw_zenoh_cpp (Failed) or rclcpp 44 - test_node_interfaces__node_graph (Failed) |
Hi @ahcorde, I tested this branch against rcl, rclcpp, and system_tests. I didn't see any failures. |
@YuanYuYuan That's true, I had a hanging process which made these tests to fail Do you min to try this one #546? |
Sure. Will do. |
|
So here's where i'm confused.
My original question still stands, which is the test that actually requires topic names in a node to be ordered? Because the ordered_map is only used here. I'm not comfortable with switching to std::map without ascertaining this. |
ros2node test are failing because the names are not sorted alphabetically, this should fix the issue
Related with this issue #523