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

Update rcutils_calculate_directory_size() to support recursion #306

Conversation

Barry-Xu-2018
Copy link
Contributor

No description provided.

@Barry-Xu-2018
Copy link
Contributor Author

Related to #304

@fujitatomoya
Copy link
Collaborator

@clalancette @Karsten1987 friendly ping. i will be looking into this today.

@@ -419,9 +419,9 @@ TEST_F(TestFilesystemFixture, calculate_directory_size) {
#ifdef WIN32
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would keep the non-recursive test case like following.

  • non-recursive test case: rcutils_calculate_directory_size(test/dummy_folder/dummy-subfolder/dummy-subfolder)
  • recursive test case: rcutils_calculate_directory_size(test/dummy_folder)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This modification is to support recursion. So not support non-recursion.
If there is non-recursive test case, do you mean 2 API --- one for non-recursion and the other for recursion ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

my bad, i wasn't clear enough. what i mean is not about the function but test cases,

  • test only files in a single directory. (non-recursive search test case)
  • test directories and files. (recursive search test case)

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@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 still have the overall concern about this, which is whether this change makes a difference to rosbag2. I'm still waiting to hear back from @Karsten1987 about that. Other than that, I have one more concern inline.

@Barry-Xu-2018 Barry-Xu-2018 force-pushed the topic-enhance-rcutils_calculate_directory_size branch from b7c3412 to f517865 Compare November 12, 2020 06:18
@Barry-Xu-2018
Copy link
Contributor Author

@clalancette @fujitatomoya

I updated codes to implement recursion without consuming memory from stack.
A new API rcutils_calculate_directory_size_with_recursion() is added. For the original API rcutils_calculate_directory_size(), the behavior isn't changed.

Copy link
Contributor

@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 got a bunch of stuff to fix in here.

One other thing; the inner loops for both the Windows and Unix sides are very similar. Do you think it is possible to use a common function for that?

@Barry-Xu-2018
Copy link
Contributor Author

if we cannot change the rosbag2 code, i think we should stick with current rcutils_calculate_directory_size that means it returns 0 even with error. but as interface, i think current interface is the one which needs to be changed. since user application cannot tell error or actual size is 0. that would lead the another problem.

Agree. So I try to change the interface to return -1 for error.
Now only one project (rosbag2) use this rcutils_calculate_directory_size().
So the sooner we update this interface, the better.

@Barry-Xu-2018 Barry-Xu-2018 force-pushed the topic-enhance-rcutils_calculate_directory_size branch from 39714fc to 767fd78 Compare November 16, 2020 07:34
@Barry-Xu-2018
Copy link
Contributor Author

@clalancette @fujitatomoya

I updated codes based on your comments.

Change the return type from a size_t to an ssize_t. Then we can return -1 to indicate error.

I adopt this way to show error while calling rcutils_calculate_directory_size() or rcutils_calculate_directory_size_with_recursion().

Copy link
Contributor

@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.

A few more things to think about in here. This one is tricky to get right.

@Barry-Xu-2018
Copy link
Contributor Author

@clalancette

Sorry to late update.
Please help review again.
For rcutils_calculate_directory_size(), I don't keep the same interface as rcutils_calculate_directory_size_with_recursion().
It is because we should update code of rosbag once rcutils_calculate_directory_size() interface is changed.
I cannot make sure 2 repositories have been update at the same time for CI system. (Otherwise, CI system always reports build failure).

Copy link
Contributor

@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.

One major thing to change. We are getting closer, thanks for all of the revisions.

@Barry-Xu-2018
Copy link
Contributor Author

@clalancette

Updated. Please review again.

src/filesystem.c Outdated
Comment on lines 241 to 242
size_t
rcutils_calculate_directory_size(const char * directory_path, rcutils_allocator_t allocator)
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that it is hard to make API changes across repositories, but I do think we should do that here. In point of fact, this API has the same problems as the new rcutils_calculate_directory_size_with_recursion had, namely:

  1. You can't tell if the return value is 0 because the call failed, or because there were just no files in the directory.
  2. On 32-bit, you can only return a size up to 4GB, which is pretty small.

So I think we should change this signature to:

rcutils_ret_t
rcutils_calculate_directory_size(const char *directory_path, uint64_t *size, rcutils_allocator_t allocator)

And also update rosbag2 to use that signature as well. It won't pass the PR job until we release both of them, but that's OK. We'll run normal CI (that's why we have it), and then I can merge both and do a release of both at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I will update rcutils_calculate_directory_size().
And update rosbag2' codes since rcutils_calculate_directory_size() is changed.

We'll run normal CI (that's why we have it)

I don't know this normal CI. What is the difference with the current system ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know this normal CI. What is the difference with the current system ?

Sorry, I should have been more clear.

We actually have two separate types of CI. When you open a PR (and anytime you update it), the "Rpr" job runs on https://build.ros2.org. You can see the output of that down below in the "Checks" section of this PR. The PR job takes all of the current Rolling packages that this package depends on, installs them, checks this branch out, and then does a build-and-test. This is great as it is automatic, and gives us fairly quick feedback on small issues like compiler warnings, linter warnings, unit tests, etc. But it does have some problems:

  1. It won't test packages that depend on this package. So in this case, the PR job succeeded, but if we merge this and then try to build rosbag2, it would fail because of the changed API.
  2. If there are API changes in packages that this package depends on, it will just fail. There is no way to do a coordinated test across several repositories.
  3. It only tests Linux, not the other Tier-1 platforms.

For all of those reasons, we also have https://ci.ros2.org, where we can test all of the things above.

Therefore, for this PR, once we are happy with the code and it is approved, I can run a full test on ci.ros2.org to get cross-platform tests going, and with all packages that depend on this one.

Does that all make some sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for your detailed explanation.
I get it.
I try to login https://ci.ros2.org and I think normal user have no permission to execute it.
So you will help to execute it. Right ?

Copy link
Contributor

Choose a reason for hiding this comment

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

So you will help to execute it. Right ?

Yes, exactly. Once I approve, I'll go ahead and run the job on https://ci.ros2.org.

@Barry-Xu-2018
Copy link
Contributor Author

@clalancette

Codes have been updated. Please help to review.
Besides, I have created PR (ros2/rosbag2#567) for rosbag2.

@Barry-Xu-2018 Barry-Xu-2018 force-pushed the topic-enhance-rcutils_calculate_directory_size branch 2 times, most recently from c8fcc29 to 7d89863 Compare November 25, 2020 11:28
Copy link
Contributor

@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.

This is looking great. I've got a few more minor things to fix up inline; once that is done, I'll go ahead and run CI. Thanks for all of the iterations here.

@clalancette
Copy link
Contributor

I did some minor cleanups in the test code just to avoid memory leaks if an assertion fails. You can see that work in 6b16702. With that, I'm happy with this code, so I'm going to approve and run CI.

@clalancette
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette clalancette force-pushed the topic-enhance-rcutils_calculate_directory_size branch from 6b16702 to bb4f1b1 Compare December 1, 2020 20:26
@clalancette
Copy link
Contributor

So the Windows CMake warnings and test warnings can be ignored; those are in the nightlies (and at least some of them should be fixed for tomorrow).

The MSBuild ones I believe are fixed on master. So I just rebased this whole thing onto master and force-pushed it. I'll run another Windows CI to check:

  • Windows Build Status

@clalancette
Copy link
Contributor

All right, Windows is now happier. One more run of the rest of the platforms, and I'll merge tomorrow:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette
Copy link
Contributor

All right, going ahead and merging along with ros2/rosbag2#567. Thanks for the contribution @Barry-Xu-2018 .

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.

4 participants