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

Standalone 5/N: Implement and test ZarrStream_s #297

Merged
merged 57 commits into from
Sep 26, 2024
Merged

Conversation

aliddell
Copy link
Member

@aliddell aliddell commented Sep 17, 2024

Depends on #295

@aliddell aliddell changed the base branch from standalone-sequence-4b to standalone-sequence-4 September 20, 2024 20:56
Copy link
Collaborator

@shlomnissan shlomnissan left a comment

Choose a reason for hiding this comment

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

I believe there's room for improvement in this PR. My main concern is the new API for creating a dimension array using the settings object for assignment and deallocation. While I'm approving this PR to avoid blocking progress, I think we should consider this comment before merging. It's a borderline issue, but worth considering.

* and freed with ZarrStreamSettings_destroy_dimension_array. The order in which you
* set the dimension properties in the array should match the order of the dimensions
* from slowest to fastest changing, for example, [Z, Y, X] for a 3D dataset.
*/
typedef struct ZarrStreamSettings_s
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you planning to move this type to zarr.types, or is there a specific reason for keeping it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to bury the main settings struct at the bottom of zarr.types.h.

ZarrDataType data_type;
ZarrVersion version;
bool multiscale;
const char* store_path; /**< Path to the store. Filesystem path or S3 key prefix. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe a more robust API would involve passing a store object (either as part of the settings object or separately to the "create stream" function) rather than using a single argument that could have dual meanings. I previously raised this point. However, I don't consider it a critical issue that would prevent progress.

Comment on lines 72 to 78
ZarrStatusCode ZarrStreamSettings_create_dimension_array(ZarrStreamSettings* settings, size_t dimension_count);

/**
* @brief Free memory for the dimension array in the Zarr stream settings struct.
* @param[in, out] settings The Zarr stream settings struct containing the dimension array to free.
*/
void ZarrStreamSettings_destroy_dimension_array(ZarrStreamSettings* settings);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe requiring the settings object for memory allocation and deallocation blurs ownership boundaries. Instead, could the function return a pointer to the dimension array, which the user can then assign to the settings object? This way, when users want to destroy it, they can simply pass that pointer. This approach would clarify ownership and simplify memory management.

Copy link
Member Author

Choose a reason for hiding this comment

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

It could, but there are two parameters that are set or reset (I double checked this and realized dimension_count is not actually getting reset in ZarrStreamSettings_destroy_dimension_array though, but I'll push a fix for that).

@@ -1,4 +1,6 @@
add_subdirectory(logger)
add_subdirectory(streaming)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the "logger" is used exclusively by the streaming target and not by the driver, adding its subdirectory should be placed there instead of at the top level.

# Install public header files
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION include
FILES_MATCHING PATTERN "*.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is file matching necessary? Wouldn't all files in the public include directory be considered public header files?


[[nodiscard]]
std::string
trim(const char* s)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This utility function, unrelated to zarr streaming, can be moved to a "utilities" header file. It can be used to clean up input in various parts of the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not really used anywhere else, but I can move it to zarr.common.hh/cpp in the next PR

Comment on lines 55 to 59
std::string trimmed = trim(settings->endpoint);
if (trimmed.empty()) {
LOG_ERROR("S3 endpoint is empty");
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The emptiness check is repeated multiple times. We should extract it into a separate function that takes an untrimmed string and an error message as parameters.

if (is_empty_string(settings->endpoint, "S3 endpoint is empty")) {
    return false;
}

This is also a good candidate for a utility function.

@@ -1,6 +1,8 @@
if (${NOTEST})
message(STATUS "Skipping test targets")
else ()
add_subdirectory(unit-tests)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What other tests are we expecting to necessitate the need for a subdirectory called "unit-tests"?


#include "logger.hh"

#define EXPECT(e, ...) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't we use a testing framework like GTest to avoid this boilerplate code every time we configure tests?

bool
is_s3_acquisition(const struct ZarrStreamSettings_s* settings)
{
return nullptr != settings->s3_settings;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I already mentioned this over Slack. Yoda conditions are uncommon in modern C++ codebases because the compiler and static analyzer will warn you about this. Personally, I find this form less readable and counterintuitive, as it contradicts the natural reading order.

@aliddell aliddell force-pushed the standalone-sequence-4 branch from 39ec6a7 to bda14d7 Compare September 24, 2024 20:05
@aliddell aliddell force-pushed the standalone-sequence-5 branch from c8f5e9f to 82df0a2 Compare September 25, 2024 13:58
Base automatically changed from standalone-sequence-4 to main September 26, 2024 16:48
@aliddell aliddell merged commit 16c553f into main Sep 26, 2024
3 checks passed
@aliddell aliddell deleted the standalone-sequence-5 branch September 26, 2024 20:10
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.

2 participants