realm-kotlin icon indicating copy to clipboard operation
realm-kotlin copied to clipboard

Use public C-API to implement custom scheduler

Open nhachicha opened this issue 4 years ago • 4 comments

Currently, we're relying on internal ObjectStore API to implement JVM scheduler. We could achieve the same effect by using realm_clone and build a scheduler using the C-API callback instead of subclassing directly realm::util::Scheduler interface

nhachicha avatar Oct 07 '21 17:10 nhachicha

I updated the implementation to use the C-API for creating the custom scheduler in #688, but realm_clone is only updating the reference count, so not sufficient to make an actual copy of the configuration and the generic scheduler is still created using the C++ API, as that is still not exposed in the C-API.

rorbech avatar Feb 21 '22 15:02 rorbech

Just for reference. Tried out with realm_clone, but it fails with:

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x138
Cause: null pointer dereference
    rax 0000000000000138  rbx 000072b77f746c00  rcx 0000000000000001  rdx 000072b80f9c15a8
    r8  0000000000000001  r9  000072b77f76f9c8  r10 0000000000000000  r11 0000000000000206
    r12 000072b733c776b0  r13 000072b734d881e6  r14 000000000000000c  r15 000072b733c77ff8
    rdi 0000000000000138  rsi 0000000000000138
    rbp 000072b733c77370  rsp 000072b733c771e0  rip 000072b732c9f3c8
backtrace:
      #00 pc 00000000007153c8  /data/app/io.realm.testapp.test-TRZkcTCmYc26qjbEBVRgOA==/lib/x86_64/librealmc.so (_ZNSt6__ndk14swapIPN5realm4util9SchedulerEEENS_9enable_ifIXaasr21is_move_constructibleIT_EE5valuesr18is_move_assignableIS6_EE5valueEvE4typeERS6_S9_+56) (BuildId: 6fc6aa1034c801b34562a342ebf51f4b08fb0c46)
      #01 pc 0000000000715370  /data/app/io.realm.testapp.test-TRZkcTCmYc26qjbEBVRgOA==/lib/x86_64/librealmc.so (std::__ndk1::shared_ptr<realm::util::Scheduler>::swap(std::__ndk1::shared_ptr<realm::util::Scheduler>&)+32) (BuildId: 6fc6aa1034c801b34562a342ebf51f4b08fb0c46)
      #02 pc 000000000070cb96  /data/app/io.realm.testapp.test-TRZkcTCmYc26qjbEBVRgOA==/lib/x86_64/librealmc.so (std::__ndk1::shared_ptr<realm::util::Scheduler>::operator=(std::__ndk1::shared_ptr<realm::util::Scheduler> const&)+70) (BuildId: 6fc6aa1034c801b34562a342ebf51f4b08fb0c46)
      #03 pc 000000000070cb3b  /data/app/io.realm.testapp.test-TRZkcTCmYc26qjbEBVRgOA==/lib/x86_64/librealmc.so (realm_config_set_scheduler+43) (BuildId: 6fc6aa1034c801b34562a342ebf51f4b08fb0c46)
      #04 pc 00000000006ecfde  /data/app/io.realm.testapp.test-TRZkcTCmYc26qjbEBVRgOA==/lib/x86_64/librealmc.so (open_realm_with_scheduler(long, _jobject*)+430) (BuildId: 6fc6aa1034c801b34562a342ebf51f4b08fb0c46)

It also doesn't look like it is intended to be cloneable https://github.com/realm/realm-core/blob/master/test/object-store/c_api/c_api.cpp#L324 so don't know what the approach should be. See comments in #688

rorbech avatar Feb 22 '22 09:02 rorbech

With #833, the only piece missing from this discussion is the part about us calling directly the ObjectStore API's instead of going through the C-API.

cmelchior avatar May 12 '22 14:05 cmelchior

Still some left overs. Ex. getting access to the default scheduler with https://github.com/realm/realm-kotlin/blob/master/packages/jni-swig-stub/src/main/jni/realm_api_helpers.cpp#L281

rorbech avatar Aug 19 '22 11:08 rorbech