ceph / ceph-rust

Rust-lang interface to Ceph.
Apache License 2.0
98 stars 43 forks source link

Use phantom data trackers to auto drop #33

Closed cholcombe973 closed 6 years ago

cholcombe973 commented 6 years ago

This change adds automatic closing of ceph connections where necessary. Unfortunately it required reworking a huge amount of the library. The most important pieces are the impl Drop sections in src/ceph.rs

The basics here are I wrapped rados_t with Rados and rados_ioctx_t with IoCtx. I made the inner fields public because my ceph-rbd library needs to get access to those pointers. There's probably a better way to do that?

I checked that this worked with a small rayon program that runs rbd stat in parallel. This would consistently crash until I got the Rbd, ioctx and ceph cluster connection dropping in the right order.

It now runs fine with 10 threads and valgrind shows it's clean:

==1423173== HEAP SUMMARY:
==1423173==     in use at exit: 0 bytes in 0 blocks
==1423173==   total heap usage: 408,707 allocs, 408,707 frees, 19,222,091 bytes allocated
==1423173== 
==1423173== All heap blocks were freed -- no leaks are possible
==1423173== 
==1423173== For counts of detected and suppressed errors, rerun with: -v
==1423173== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

I may have messed up your ceph_client.rs and cmd.rs @ChrisMacNaughton so take a close look at those

cholcombe973 commented 6 years ago

Related PR for ceph-rbd: https://github.com/cholcombe973/ceph-rbd/pull/5

cholcombe973 commented 6 years ago

valgrind still returns clean :)

cholcombe973 commented 6 years ago

Since this works should we remove the disconnect_from_ceph and destroy_rados_ioctx functions?

ChrisMacNaughton commented 6 years ago

Only if we're assuming that the user will never use the pointers directly; it may make more sense to look at splitting the FFI bits into a sub-crate like ceph-sys, and keeping only the higher level abstractions in the primary crate

cholcombe973 commented 6 years ago

Yeah I'm for ceph-sys. I can break that out in another PR

ChrisMacNaughton commented 6 years ago

I'd love for some time to be spent identifying the travis failure, but the only reference for it that I can find is from a cargo bug a couple of years ago regarding badly packaged crate archives