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

Zenoh 1.0.0 Porting #276

Open
wants to merge 133 commits into
base: rolling
Choose a base branch
from
Open

Zenoh 1.0.0 Porting #276

wants to merge 133 commits into from

Conversation

YuanYuYuan
Copy link
Contributor

@YuanYuYuan YuanYuYuan commented Sep 5, 2024

Notes

  • Remove some unused dependencies.
  • Use z_view_keyexpr_t rather z_owned_keyexpr_t if possible. This keeps the reference only and doesn't need to be dropped.
  • The attachment type has been removed. Use the plain z_bytes instead.
  • Attachment is nothing but z_bytes. Use an iterator to get value by key.
  • z_check is now internal. We check zenoh entities' health by the creation functions' return.

Mallets and others added 30 commits August 9, 2024 14:32
Signed-off-by: Luca Cominardi <[email protected]>
Signed-off-by: Luca Cominardi <[email protected]>
Signed-off-by: Luca Cominardi <[email protected]>
chore: checkout dev/1.0.0
#ifndef DETAIL__SHM_CONTEXT_HPP_
#define DETAIL__SHM_CONTEXT_HPP_


Copy link
Contributor

Choose a reason for hiding this comment

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

#include <cstddef>

namespace rmw_zenoh_cpp
{
///=============================================================================
#ifdef RMW_ZENOH_BUILD_WITH_SHARED_MEMORY
Copy link
Contributor

Choose a reason for hiding this comment

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

this file is not included in the CMakeLists.txt

#ifdef RMW_ZENOH_BUILD_WITH_SHARED_MEMORY
struct ShmContext
{
z_owned_shm_provider_t shm_provider;
Copy link
Contributor

Choose a reason for hiding this comment

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

missing header

#ifdef RMW_ZENOH_BUILD_WITH_SHARED_MEMORY
ShmContext::~ShmContext()
{
z_drop(z_move(shm_provider));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm getting a segfault here, double free

@alireza-moayyedi
Copy link

Not sure what the status of the abovementioned issue by @ahcorde is but I am getting the following with the latest commit:
Screenshot from 2024-11-15 10-17-34

@evshary
Copy link

evshary commented Nov 15, 2024

Not sure what the status of the abovementioned issue by @ahcorde is but I am getting the following with the latest commit

@alireza-moayyedi Sorry for the inconvenience. There are some errors with the latest commit. Would you mind using the previous one? I've tested with this one.
ZettaScaleLabs@28d917e

We will fix that ASAP.

@YuanYuYuan
Copy link
Contributor Author

Hi @alireza-moayyedi! It has been fixed 😃

@alireza-moayyedi
Copy link

Not sure what the status of the abovementioned issue by @ahcorde is but I am getting the following with the latest commit

@alireza-moayyedi Sorry for the inconvenience. There are some errors with the latest commit. Would you mind using the previous one? I've tested with this one. ZettaScaleLabs@28d917e

We will fix that ASAP.

hey @evshary ,

Yes indeed I switched to ZettaScaleLabs@28d917e for the time being. And of course, no apologies required. This is what open source is for and I am more than grateful for your contributions ;-)

Copy link
Collaborator

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

I've done a first review pass (for me), and left some comments. Once this is rebased onto the latest and my comments are addressed, I'll do another review pass.

.github/workflows/style.yaml Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/attachment_helpers.cpp Outdated Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/attachment_helpers.cpp Outdated Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/attachment_helpers.cpp Outdated Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/graph_cache.hpp Show resolved Hide resolved
zenoh_c_vendor/CMakeLists.txt Show resolved Hide resolved
rmw_zenoh_cpp/src/rmw_zenoh.cpp Outdated Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/shm_context.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's just remove this file from the pull request for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 9f78ca4

Copy link
Member

Choose a reason for hiding this comment

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

The file is still present...

@mergify mergify bot mentioned this pull request Nov 18, 2024
Copy link
Collaborator

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

Besides what I left inline, I'm did a head-to-head comparison between rolling and the dev/1.0.0 branch. Some of this matches what is in #286 (comment) , though some of it is different.

package test rolling branch (3d771c8) dev/1.0.0 branch (9f78ca4) note
rcl test_guard_condition ✔️ particularly under load
rcl_action test_action_server ✔️
rclcpp test_client_common ✔️
rclcpp test_publisher
rclcpp_action test_server ✔️
rclcpp_lifecycle test_lifecycle_service_client ✔️ flaky; I was only able to make this fail once
test_rclcpp test_client_scope_cpp ✔️
test_rclcpp test_node_name ✔️
test_rclcpp test_n_nodes ✔️
test_rclcpp gtest_spin ✔️
test_communication test_publisher_subscriber_rclcpp_rclpy ✔️
test_communication test_publisher_subscriber_rclcpp
test_communication test_requester_replier ✔️
test_quality_of_service test_deadline
test_quality_of_service test_liveliness
test_quality_of_service test_best_available
rclpy test_action_client
rclpy test_client ✔️

Total failures: rolling 8, dev/1.0.0 15

rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp Outdated Show resolved Hide resolved
.github/workflows/style.yaml Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/graph_cache.hpp Show resolved Hide resolved
zenoh_c_vendor/CMakeLists.txt Show resolved Hide resolved
@YuanYuYuan
Copy link
Contributor Author

The failure on test_client_common can be related to this issue ros2/rclcpp#2680.

Copy link
Member

@Yadunund Yadunund left a comment

Choose a reason for hiding this comment

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

Re-reviewed 75% of the changes and provided some feedback. My primary concern is the introduction of registering a function with the atexit signal handler. As explained inline, there is still a problem of the static variable being invalidated and 'm confused why we need it with dev/1.0.0 when we do not need it rolling.

Secondly, I think the diff in the PR is way larger than it needs to be. Imo the changes only need reflect changes in the zenoh-c API but there are changes in rmw_zenoh.cpp wrt to checking if entities are valid, and various cleanups to headers.
My recommendation is to take all the changes that remove cleanup headers and target a PR to the current rolling branch. And save other changes unrelated to breaking zenoh-c API to a future PR.

@@ -68,6 +68,9 @@ int main(int argc, char ** argv)
return 1;
}

// Enable the zenoh built-in logger
Copy link
Member

Choose a reason for hiding this comment

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

Nit

Suggested change
// Enable the zenoh built-in logger
// Enable the zenoh built-in logger.

@@ -361,28 +351,21 @@ rmw_ret_t ClientData::take_response(
}

// Fill in the request_header
request_header->request_id.sequence_number =
rmw_zenoh_cpp::get_int64_from_attachment(&sample->attachment, "sequence_number");
rmw_zenoh_cpp::attachment_data_t attachment(z_sample_attachment(sample));
Copy link
Member

Choose a reason for hiding this comment

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

This API feels awkward and requires you to define the move constructor. Why not just pass const z_loaned_sample_t * and construct the z_sample_attachment internally?

Comment on lines -538 to +516
if (zc_liveliness_token_check(&token_)) {
zc_liveliness_undeclare_token(z_move(token_));
}
if (z_check(z_loan(keyexpr_))) {
z_drop(z_move(keyexpr_));
}
zc_liveliness_undeclare_token(z_move(token_));

z_drop(z_move(keyexpr_));
Copy link
Member

Choose a reason for hiding this comment

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

We previously needed this check since it was possible for token_ and keyexpr_ to be uninitialized when shutdown is called within ClientData::make. Do these functions now check whether the tokens are valid before dropping?

Comment on lines +44 to +53
// The variable is used to identify whether the process is trying to exit or not.
// The atexit function we registered will set the flag and prevent us from closing
// Zenoh Session. Zenoh API can't be used in atexit function, because Tokio context
// is already destroyed. It will cause panic if we do so.
static bool is_exiting = false;
void update_is_exiting()
{
is_exiting = true;
}

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this logic with 1.0.0 only? How do we ensure two or more threads do not access is_exiting concurrently? Moreover, when the program terminates, static ordering is unknown so there is no guarantee that is_exiting is valid. That's one of the reasons we redid the way we track ClientData in #310
cc @clalancette

// This global mapping of raw Data pointers to Data shared pointers allows graph_sub_data_handler()
// to lookup the pointer, and gain a reference to a shared_ptr if it exists.
// This guarantees that the Data object will not be destroyed while we are using it.
static std::mutex data_to_data_shared_ptr_map_mutex;
static std::unordered_map<rmw_context_impl_s::Data *,
std::shared_ptr<rmw_context_impl_s::Data>> data_to_data_shared_ptr_map;

static void graph_sub_data_handler(const z_sample_t * sample, void * data);
static void graph_sub_data_handler(z_loaned_sample_t * sample, void * data);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
static void graph_sub_data_handler(z_loaned_sample_t * sample, void * data);
static void graph_sub_data_handler(const z_loaned_sample_t * sample, void * data);

Comment on lines +107 to +109
// TODO(yuyuan): SHM, make this configurable
#define SHM_BUF_OK_SIZE 2621440

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 unused so please remove.

Suggested change
// TODO(yuyuan): SHM, make this configurable
#define SHM_BUF_OK_SIZE 2621440

Comment on lines -396 to -399
if (!context_impl->session_is_valid()) {
RMW_SET_ERROR_MSG("zenoh session is invalid");
return nullptr;
}
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this?

Comment on lines +449 to +450
/// Finalize a given publisher handle, reclaim the resources, and deallocate the
/// publisher handle.
Copy link
Member

Choose a reason for hiding this comment

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

Undo unnecessary change.

Comment on lines -754 to -757
if (!pub_data->liveliness_is_valid()) {
return RMW_RET_ERROR;
}

Copy link
Member

Choose a reason for hiding this comment

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

Why remove this?

Comment on lines -929 to -932
if (!context_impl->session_is_valid()) {
RMW_SET_ERROR_MSG("zenoh session is invalid");
return nullptr;
}
Copy link
Member

Choose a reason for hiding this comment

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

Again, why remove this here and in other functions below?

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.