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

tiledb_vfs_open is not reporting error correctly #4347

Merged
merged 6 commits into from
Sep 12, 2023

Conversation

robertbindar
Copy link
Contributor

@robertbindar robertbindar commented Sep 11, 2023

Save error on the context before returning error code.


TYPE: BUG
DESC: Save error on the context before returning error code in vfs_open.

@shortcut-integration
Copy link

@@ -234,6 +235,7 @@ capi_return_t tiledb_vfs_open(
// Open VFS file
auto st{(*fh)->open()};
if (!st.ok()) {
save_error(ctx, st);
Copy link
Contributor

Choose a reason for hiding this comment

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

This statement should throw rather than manually saving the error. throw_if_not_ok(st) is sufficient.

We're setting up to change error handling away from storing it on the context and returning it. We'll redefine the symbol capi_return_t at that point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even better would be move the call to open into the constructor of tiledb_vfs_fh_handle_t and throw if the open fails. That'll save a try block and any need to break a handle.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@ihnorton ihnorton changed the title tiledb_vfs_open is not reporting error correcly tiledb_vfs_open is not reporting error correctly Sep 11, 2023
@robertbindar robertbindar force-pushed the rbin/ch33908/report_error_vfs_open branch from 3875ef1 to 6162a9c Compare September 12, 2023 11:22
@robertbindar
Copy link
Contributor Author

@eric-hughes-tiledb @bekadavis9 @ihnorton
Please note the following:

  • I moved the open() call in the tiledb_vfs_fh_handle_t constructor as Eric requested
  • But I also moved the close() call in the tiledb_vfs_fh_handle_t destructor, this way tiledb_vfs_close and tiledb_vfs_fh_is_closed become noops
  • There is a catch though: during closing of a file handle (previously opened in WRITE mode), if no data was written, the close() call creates an empty file. So moving the closing of the file handle in the tiledb_vfs_fh_handle_t and out of the tiledb_vfs_close() api can be considered breaking change. The double catch is that in the documentation of tiledb_vfs_open the exact opposite of that behavior is documented, see it at https://tiledb-inc-tiledb.readthedocs-hosted.com/en/stable/c-api.html#_CPPv415tiledb_vfs_openP12tiledb_ctx_tP12tiledb_vfs_tPKc17tiledb_vfs_mode_tPP15tiledb_vfs_fh_t
    Pasting here for reference: "If the file is closed after being opened, without having written any data to it, the file will not be created. If you wish to create an empty file, use tiledb_vfs_touch instead."
    What's right and what's wrong?

@robertbindar
Copy link
Contributor Author

Reverted the change in close() behavior so we can fit this release, I'll file a followup for addressing the comment above.

@eric-hughes-tiledb
Copy link
Contributor

so we can fit this release

It's a good decision.

The API design has problem. We shouldn't have a close function but rather a flush one. We ought to have the invariant that "if the handle exists, we have an open handle". As we learned with an analogous situation with groups, we need to separate the return status of an external write from the end-of-life of the resource. (The specific issue was that a C++ destructor can't throw, but the principle is larger.) From the point of view of transaction processing, a resource should in general abort any pending activity at the end of its life. (There are exceptions to this rule, but that's beyond the scope of a small comment.) The purpose of a flush function is to perform any pending activity in advance of end-of-life. With that available, we don't need a close function.

@robertbindar
Copy link
Contributor Author

robertbindar commented Sep 12, 2023

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.

LGTM.

Final code is much cleaner.

@ihnorton ihnorton merged commit ea25897 into dev Sep 12, 2023
@ihnorton ihnorton deleted the rbin/ch33908/report_error_vfs_open branch September 12, 2023 15:33
ihnorton pushed a commit that referenced this pull request Sep 12, 2023
)

Save error on the context before returning error code in `tiledb_vfs_open`.

---
TYPE: BUG
DESC: Save error on the context before returning error code in vfs_open

(cherry picked from commit ea25897)
ihnorton added a commit that referenced this pull request Sep 13, 2023
) (#4350)

Save error on the context before returning error code in `tiledb_vfs_open`.

---
TYPE: BUG
DESC: Save error on the context before returning error code in vfs_open

(cherry picked from commit ea25897)

Co-authored-by: Robert Bindar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants