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

Add wrapper for tiledb_vfs_ls_recursive. #363

Merged
merged 5 commits into from
Jan 10, 2025

Conversation

teo-tsirpanis
Copy link
Member

@teo-tsirpanis teo-tsirpanis requested a review from a team as a code owner December 20, 2024 18:29
Copy link
Collaborator

@NullHypothesis NullHypothesis left a comment

Choose a reason for hiding this comment

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

Left a minor comment but looks good otherwise. I'll defer to Shaun or Ypatia for a sign-off considering that they have actual core expertise.

@@ -464,7 +464,7 @@ func (v *VFS) NumOfFragmentsInPath(path string) (int, error) {
Vfs: v,
}
data := pointer.Save(&numOfFragmentsData)
defer C.free(data)
defer pointer.Unref(data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️

@@ -635,6 +635,7 @@ func (v *VFS) List(path string) ([]string, []string, error) {
Vfs: v,
}
data := pointer.Save(&folderData)
defer pointer.Unref(data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

😍

vfs.go Outdated
@@ -643,3 +644,52 @@ func (v *VFS) List(path string) ([]string, []string, error) {

return folderData.Folders, folderData.Files, nil
}

type visitRecursiveCallback = func(path string, size uint64) (doContinue bool, err error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might want to export this type because VisitRecursive may otherwise be annoying to use: Not sure if all IDEs display non-exported types. If an IDE doesn't, you have to look at TileDB-Go's source code to figure out what function signature is expected here.

Suggested change
type visitRecursiveCallback = func(path string, size uint64) (doContinue bool, err error)
type VisitRecursiveCallback = func(path string, size uint64) (doContinue bool, err error)

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 copy-paste the callback's signature, but also didn't want to export a type without it being needed, but if some IDEs might not like it sure, done.

return 0
}

doContinue, err := state.callback(C.GoStringN(path, C.int(path_len)), uint64(size))
Copy link
Member Author

Choose a reason for hiding this comment

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

If the callback panics we should catch and rethrow it after the call to ls_recursive like we do with the errors, right? I had done a similar thing in C# with exceptions.

Copy link
Collaborator

@shaunrd0 shaunrd0 Dec 20, 2024

Choose a reason for hiding this comment

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

Do you mean using recover() to catch and rethrow an error if the callback panics? IMO if a user writes a callback that panics that's what should happen but @NullHypothesis please correct me if I am wrong.

For example I tried this in examples_lib/vfs.go and it panics, I think that's what would be expected.

err = vfs.VisitRecursive(dirA, func(path string, size uint64) (bool, error) {
    panic("Test")
    return false, nil
})

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it should still panic, but I'm not sure what is the behavior if we panic in a Go function that is called from C code, and whether we should have additional logic to handle it. I know that in C# this is not supported (because there is no standardized ABI for exceptions in non-Windows), but don't know anything about that in Go.

callback: callback,
lastError: nil,
}
data := pointer.Save(state)
Copy link
Member Author

Choose a reason for hiding this comment

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

cgo.Handle provides the same functionality as this package inbox. Using it is tracked in SC-58131.

Copy link
Collaborator

@shaunrd0 shaunrd0 left a comment

Choose a reason for hiding this comment

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

Just one comment for experimental things, LGTM otherwise 👍

@@ -1,12 +1,13 @@
#ifndef CLIBRARY_H
#define CLIBRARY_H

#include <tiledb/tiledb.h>
#include <tiledb/tiledb_experimental.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could create a vfs_experimental.go and clibrary_experimental.{h,c} to keep non experimental and experimental features separate

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, but I'm not sure what the benefit would be. We can add a //go:build experimental at the top of the file like this file in #225 does, but currently we are not doing this in the existing experimental files.

Copy link
Collaborator

@shaunrd0 shaunrd0 Jan 6, 2025

Choose a reason for hiding this comment

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

Yeah, it looks like the experimental tag was removed and we added the _experimental.go suffix to TileDB-Go sources in #302

Initially my vote was to add the build flags that were missing at the top of these _experimental.go files, but after seeing the above PRs it looks like we actually don't want the experimental tag and it should not be present at the top of these files. So.. LGTM! 👍

@teo-tsirpanis teo-tsirpanis merged commit 1ed8dab into TileDB-Inc:master Jan 10, 2025
6 checks passed
@teo-tsirpanis teo-tsirpanis deleted the ls-recursive branch January 10, 2025 17:25
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