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

enhance: Handle rust error in c++ #38113

Merged
merged 8 commits into from
Dec 16, 2024

Conversation

sunby
Copy link
Contributor

@sunby sunby commented Nov 29, 2024

@sre-ci-robot sre-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines. label Nov 29, 2024
@mergify mergify bot added dco-passed DCO check passed. kind/enhancement Issues or changes related to enhancement labels Nov 29, 2024
Copy link
Contributor

mergify bot commented Nov 29, 2024

@sunby Please associate the related issue to the body of your Pull Request. (eg. “issue: #”)

Copy link
Contributor

mergify bot commented Nov 29, 2024

@sunby E2e jenkins job failed, comment /run-cpu-e2e can trigger the job again.

Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.88%. Comparing base (304cdc7) to head (dedd203).
Report is 28 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #38113      +/-   ##
==========================================
- Coverage   82.78%   80.88%   -1.91%     
==========================================
  Files        1084     1373     +289     
  Lines      166888   193165   +26277     
==========================================
+ Hits       138157   156240   +18083     
- Misses      23209    31395    +8186     
- Partials     5522     5530       +8     
Components Coverage Δ
Client 74.58% <ø> (ø)
Core 68.97% <ø> (∅)
Go 82.97% <ø> (-0.04%) ⬇️

see 412 files with indirect coverage changes

Copy link
Contributor

mergify bot commented Nov 30, 2024

@sunby E2e jenkins job failed, comment /run-cpu-e2e can trigger the job again.

explicit RustResultWrapper(RustResult result) : result_(result) {
}

RustResultWrapper(RustResultWrapper&& other) noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that RustResultWrapper is not a safe type.
The move construction operation on it make a double free.
I prefer to wrap those ffi type such as RustResult with unique_ptr to make it safe.

#[no_mangle]
pub extern "C" fn free_rust_array(array: RustArray) {
let RustArray { array, len, cap } = array;
unsafe {
Vec::from_raw_parts(array, len, cap);
}
}

#[repr(C)]
Copy link
Contributor

Choose a reason for hiding this comment

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

does the ffi type satisfy the rfc https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md?
Please add some unittest to make sure that it's ok at current compiler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does the ffi type satisfy the rfc https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md? Please add some unittest to make sure that it's ok at current compiler.

as cbindgen doc says cbindgen also supports using repr(C)/repr(u8) on non-C-like enums (enums with fields). This gives a C-compatible tagged union layout, as [defined by this RFC 2195](https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md). repr(C) will give a simpler layout that is perhaps more intuitive, while repr(u8) will produce a more compact layout.

this enum should be supported. But I will also add a ut to verify it.

#[no_mangle]
pub extern "C" fn free_rust_result(result: RustResult) {
match result.value {
Value::RustArray(array) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

In my view, the pointer type should also be freed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my view, the pointer type should also be freed.

Ptr type is catched by c++ class and will be freed when dtor is called for now. So we don't free ptr here.

Copy link
Contributor

mergify bot commented Dec 11, 2024

@sunby go-sdk check failed, comment rerun go-sdk can trigger the job again.

Copy link
Contributor

mergify bot commented Dec 11, 2024

@sunby cpp-unit-test check failed, comment rerun cpp-unit-test can trigger the job again.

Copy link
Contributor

mergify bot commented Dec 11, 2024

@sunby E2e jenkins job failed, comment /run-cpu-e2e can trigger the job again.

Signed-off-by: sunby <[email protected]>
Signed-off-by: sunby <[email protected]>
Signed-off-by: sunby <[email protected]>
@sunby sunby force-pushed the return_rust_error_msg branch from fbd0726 to 599c31a Compare December 11, 2024 14:04
Copy link
Contributor

mergify bot commented Dec 11, 2024

@sunby cpp-unit-test check failed, comment rerun cpp-unit-test can trigger the job again.

Signed-off-by: sunby <[email protected]>
Copy link
Contributor

mergify bot commented Dec 12, 2024

@sunby cpp-unit-test check failed, comment rerun cpp-unit-test can trigger the job again.

Signed-off-by: sunby <[email protected]>
Copy link
Contributor

mergify bot commented Dec 13, 2024

@sunby go-sdk check failed, comment rerun go-sdk can trigger the job again.

Copy link
Contributor

mergify bot commented Dec 13, 2024

@sunby cpp-unit-test check failed, comment rerun cpp-unit-test can trigger the job again.

Signed-off-by: sunby <[email protected]>
Copy link
Contributor

mergify bot commented Dec 16, 2024

@sunby cpp-unit-test check failed, comment rerun cpp-unit-test can trigger the job again.

Signed-off-by: sunby <[email protected]>
Copy link
Contributor

mergify bot commented Dec 16, 2024

@sunby go-sdk check failed, comment rerun go-sdk can trigger the job again.

@sunby
Copy link
Contributor Author

sunby commented Dec 16, 2024

rerun go-sdk

@mergify mergify bot added the ci-passed label Dec 16, 2024
@chyezh
Copy link
Contributor

chyezh commented Dec 16, 2024

/lgtm

Copy link
Contributor

@congqixia congqixia left a comment

Choose a reason for hiding this comment

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

/approve

@sre-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: congqixia, sunby

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sre-ci-robot sre-ci-robot merged commit 3e2a2f2 into milvus-io:master Dec 16, 2024
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved area/compilation area/test ci-passed dco-passed DCO check passed. kind/enhancement Issues or changes related to enhancement lgtm sig/testing size/XXL Denotes a PR that changes 1000+ lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants