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

Switching from ArraySchema* to shared_ptr<ArraySchema> #2923

Merged
merged 2 commits into from Mar 2, 2022

Conversation

stavrospapadopoulos
Copy link
Member

@stavrospapadopoulos stavrospapadopoulos commented Feb 28, 2022

The motivation for this PR is to avoid fetching the latest array schema twice, as well as for code cleanup purposes.

We were fetching the latest array schema twice because of legacy code that was using raw ArraySchema* pointers for the latest array schema everywhere, and smart pointers for the multiple array schemas used for versioning. This PR switches from using raw array schema pointers to shared pointers wherever possible. It also fetches the latest array schema once, by grabbing it from the versioned array schemas that are loaded anyway.


TYPE: IMPROVEMENT
DESC: Switch to smart pointers and const references for ArraySchema, and avoid fetching the latest array schema twice.

tiledb/sm/query/result_tile.cc Outdated Show resolved Hide resolved
tiledb/sm/query/sparse_global_order_reader.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@eric-hughes-tiledb eric-hughes-tiledb left a comment

Choose a reason for hiding this comment

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

tdb_shared_ptr is a deprecated definition at this point and not for new code. std::shared_ptr is incorporated into our global namespace through common.h. You can simply drop the tdb_ prefix and everything should compile (assuming common.h has been added, which is most of the place by now).

I've not attempted an exhaustive review. Much of what I've said about Array also applies to FragmentInfo, for example.

tiledb/sm/array/array.h Outdated Show resolved Hide resolved
tiledb/sm/array/array.h Outdated Show resolved Hide resolved
tiledb/sm/array/array.h Outdated Show resolved Hide resolved
tiledb/sm/array/array.h Outdated Show resolved Hide resolved
tiledb/sm/c_api/tiledb_struct_def.h Outdated Show resolved Hide resolved
tiledb/sm/c_api/tiledb_struct_def.h Outdated Show resolved Hide resolved
@@ -77,7 +77,7 @@ class ArraySchema {
*
* @param array_schema The array schema to copy.
*/
explicit ArraySchema(const ArraySchema* array_schema);
explicit ArraySchema(const tdb_shared_ptr<const ArraySchema>& array_schema);
Copy link
Contributor

Choose a reason for hiding this comment

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

From looking at this code previously, I know this constructor is only called once, in the C API function tiledb_array_get_schema() line 4772. As this PR changes allocation in that function, this constructor isn't called any more and can be removed.

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 still see this getting used btw.

Copy link
Contributor

Choose a reason for hiding this comment

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

Which "this"? tiledb_array_get_schema() or ArraySchema(...)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I am referring to the constructor. I attempted to remove it but it was still used in another place. I will punt for now.

@stavrospapadopoulos stavrospapadopoulos force-pushed the sp/schema_tdb_shared branch 5 times, most recently from c011131 to 0076ce4 Compare March 1, 2022 22:13
Copy link
Member

@Shelnutt2 Shelnutt2 left a comment

Choose a reason for hiding this comment

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

Great change for improved smart pointer usage and lifetime management

@stavrospapadopoulos stavrospapadopoulos force-pushed the sp/schema_tdb_shared branch 4 times, most recently from 375e8a1 to 50c8c6d Compare March 2, 2022 20:39
@stavrospapadopoulos stavrospapadopoulos changed the title WIP: Switching from ArraySchema* to tdb_shared_ptr<ArraySchema> Switching from ArraySchema* to shared_ptr<ArraySchema> Mar 2, 2022
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.

None yet

3 participants