-
Notifications
You must be signed in to change notification settings - Fork 0
Implement bulk delete #49
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
Changes from 3 commits
8b4ff5e
796b372
52a0eeb
bf063d1
8f83865
24c211e
7edc067
71701ca
a13f103
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -596,6 +596,13 @@ struct DeleteException <: RequestException | |
|
|
||
| DeleteException(msg) = new(msg, rust_message_to_reason(msg)) | ||
| end | ||
| # Used for generic exceptions that are not specific to one of the to be deleted paths | ||
| struct BulkDeleteException <: RequestException | ||
| msg::String | ||
| reason::ErrorReason | ||
|
|
||
| BulkDeleteException(msg) = new(msg, rust_message_to_reason(msg)) | ||
| end | ||
| struct ListException <: RequestException | ||
| msg::String | ||
| reason::ErrorReason | ||
|
|
@@ -905,6 +912,104 @@ function delete_object(path::String, conf::AbstractConfig) | |
| end | ||
| end | ||
|
|
||
| # ========================================================================================= | ||
| # Bulk Delete | ||
| struct BulkFailedEntryFFI | ||
| path::Cstring | ||
| error_message::Cstring | ||
| end | ||
|
|
||
| struct BulkFailedEntry | ||
| path::String | ||
| error_message::String | ||
| end | ||
|
|
||
| function convert_bulk_failed_entry(entry::BulkFailedEntryFFI) | ||
| return BulkFailedEntry( | ||
| unsafe_string(entry.path), | ||
| unsafe_string(entry.error_message), | ||
| ) | ||
| end | ||
|
|
||
| mutable struct BulkResponseFFI | ||
| result::Cint | ||
| failed_entries::Ptr{BulkFailedEntryFFI} | ||
| failed_count::Culonglong | ||
| error_message::Ptr{Cchar} | ||
| context::Ptr{Cvoid} | ||
|
|
||
| BulkResponseFFI() = new(-1, C_NULL, 0, C_NULL, C_NULL) | ||
| end | ||
|
|
||
| """ | ||
| bulk_delete_objects(path, conf) | ||
|
|
||
| Send a delete request to the object store. | ||
|
|
||
| # Arguments | ||
| - `path::String`: The location of the object to delete. | ||
adnan-alhomssi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - `conf::AbstractConfig`: The configuration to use for the request. | ||
| It includes credentials and other client options. | ||
|
|
||
| # Throws | ||
| - `DeleteException`: If the request fails for any reason. Note that S3 will treat a delete request | ||
| to a non-existing object as a success, while Azure Blob will treat it as a 404 error. | ||
adnan-alhomssi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| function bulk_delete_objects(paths::Vector{String}, conf::AbstractConfig) | ||
| response = BulkResponseFFI() | ||
| ct = current_task() | ||
| event = Base.Event() | ||
| handle = pointer_from_objref(event) | ||
| config = into_config(conf) | ||
| while true | ||
| preserve_task(ct) | ||
adnan-alhomssi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Convert Julia strings to Cstrings | ||
| c_paths = [Base.cconvert(Cstring, path) for path in paths] | ||
| # Create an array of pointers to the Cstrings | ||
| paths_array = [pointer(c_path) for c_path in c_paths] | ||
| result = GC.@preserve paths c_paths paths_array config response event try | ||
|
||
| # Pass a pointer to the array of pointers to the Cstrings | ||
| c_paths_ptr = pointer(paths_array) | ||
| result = @ccall rust_lib.bulk_delete( | ||
| c_paths_ptr::Ptr{Ptr{Cchar}}, | ||
| length(paths)::Cuint, | ||
| config::Ref{Config}, | ||
| response::Ref{BulkResponseFFI}, | ||
| handle::Ptr{Cvoid} | ||
| )::Cint | ||
|
|
||
| wait_or_cancel(event, response) | ||
|
|
||
| result | ||
| finally | ||
| unpreserve_task(ct) | ||
| end | ||
|
|
||
| if result == 2 | ||
| # backoff | ||
| sleep(0.01) | ||
| continue | ||
| end | ||
|
|
||
| @throw_on_error(response, "bulk_delete", BulkDeleteException) | ||
|
|
||
| entries = if response.failed_count > 0 | ||
| raw_entries = unsafe_wrap(Array, response.failed_entries, response.failed_count) | ||
| vector = map(convert_bulk_failed_entry, raw_entries) | ||
| @ccall rust_lib.destroy_bulk_failed_entries( | ||
| response.failed_entries::Ptr{BulkFailedEntryFFI}, | ||
| response.failed_count::Culonglong | ||
| )::Cint | ||
| vector | ||
| else | ||
| Vector{BulkFailedEntry}[] | ||
| end | ||
|
|
||
| return entries | ||
| end | ||
| end | ||
| # ========================================================================================= | ||
|
|
||
| mutable struct ReadResponseFFI | ||
| result::Cint | ||
| length::Culonglong | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.