Skip to content

CDRIVER-4674 Remove unnecessary code from bson-clock.c #1348

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

Merged
merged 4 commits into from
Jul 20, 2023

Conversation

joshbsiegel
Copy link
Contributor

@joshbsiegel joshbsiegel commented Jul 18, 2023

Summary

This PR will remove an elif block from bson_get_monotonic_time that checks if the driver is running on macOS as it serves no purpose anymore.

Background

https://jira.mongodb.org/browse/CDRIVER-4565 fixed an assertion failure that occasionally occurred on macOS 10.14. This involved using clock_gettime_nsec_np and CLOCK_UPTIME_RAW to get the monotonic time on macOS machines. However, because clock_gettime_nsec_np and CLOCK_UPTIME_RAW were introduced in macOS 10.12 and clock_gettime and CLOCK_MONOTONIC were introduced in OS X 10.11 (one of these must not be defined to hit the elif block in question), this function won't compile on OS X 10.10 or earlier.
As of now, all supported versions of macOS have clock_gettime and CLOCK_MONOTONIC, so this elif statement is no longer necessary. This PR will also ensure that the driver will compile on older versions of OS X, even if they are unable to use bson_get_monotonic_time sucessfully.

What's New

  • Removed unnecessary code from bson_get_monotonic_time
  • Removed unnecessary headers from bson-clock.c

@joshbsiegel joshbsiegel marked this pull request as draft July 18, 2023 19:54
@joshbsiegel joshbsiegel changed the title remove unnecessary code from bson-clock.c CDRIVER-4673 Remove unnecessary code from bson-clock.c Jul 18, 2023
@joshbsiegel joshbsiegel requested a review from kevinAlbs July 18, 2023 21:57
@@ -16,9 +16,6 @@


#ifdef __APPLE__
#include <mach/clock.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <sys/time.h>
Copy link
Member

Choose a reason for hiding this comment

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

Is this include still needed? It dates back to mongodb/libbson@c6e981e, although it's not clear if it was specific to the use of mach_ functions since that commit also included it for the defined(HAVE_CLOCK_GETTIME) case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the catch. Based upon what I can see in time.h and backed up by this patch, I think we are good to remove all of the macOS includes.

@joshbsiegel joshbsiegel marked this pull request as ready for review July 19, 2023 14:53
@joshbsiegel joshbsiegel requested a review from jmikola July 19, 2023 14:53
@@ -16,10 +16,6 @@


#ifdef __APPLE__
Copy link
Member

Choose a reason for hiding this comment

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

This entire #ifdef can be removed if it no longer has a body.

Copy link
Contributor Author

@joshbsiegel joshbsiegel Jul 19, 2023

Choose a reason for hiding this comment

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

I thought I already did this and I have no idea why that commit wasn't showing before. I just made a new commit ("remove empty line") and now the "remove #ifdef" commit is showing 😕

@joshbsiegel joshbsiegel changed the title CDRIVER-4673 Remove unnecessary code from bson-clock.c CDRIVER-4674 Remove unnecessary code from bson-clock.c Jul 19, 2023
@joshbsiegel joshbsiegel requested a review from jmikola July 19, 2023 17:12
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

@kevinAlbs should probably still sign off on this.

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

even if they are unable to use bson_get_monotonic_time sucessfully.

I expect bson_get_monotonic_time will continue to "succeed" and fall back to the else case of using bson_gettimeofday, and show the "Monotonic clock is not yet supported on your platform" warning on compile.
I think that is OK. Support of macOS 10.14 and 10.15 was decidedly dropped in 1.24.0 as part of CDRIVER-4580.

@joshbsiegel joshbsiegel merged commit 6d2be25 into mongodb:master Jul 20, 2023
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