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

Provide JRuby support for model iterating #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abargnesi
Copy link
Contributor

Includes the following enhancement:

  • Loads the correct FFI implementation for your ruby engine.
  • Initialize the librdf_world pointer at require time to avoid
    thread-safey issues during lazy initialization.
  • When JRuby, disable raptor's URI interning feature because it is not
    thread-safe. This was accomplished by calling raptor functions to
    configure a raptor_world without the uri interning feature.

Issues with these enhancements:

  • Requires the caller to create a Redlander::Model per thread to avoid
    additional threading issues encountered in librdf (related to
    librdf_free_stream and librdf_node_normalize).
  • JRuby tests segfault related to librdf_parser pointers.

Includes the following enhancement:
- Loads the correct FFI implementation for your ruby engine.
- Initialize the librdf_world pointer at require time to avoid
  thread-safey issues during lazy initialization.
- When JRuby, disable raptor's URI interning feature because it is not
  thread-safe. This was accomplished by calling raptor functions to
  configure a raptor_world without the uri interning feature.

Issues with these enhancements:
- Requires the caller to create a Redlander::Model per thread to avoid
  additional threading issues encountered in librdf (related to
  librdf_free_stream and librdf_node_normalize).
- JRuby tests segfault related to librdf_parser pointers.
@abargnesi
Copy link
Contributor Author

This commit enables concurrent access to librdf storage through Redlander::Model. The caller is required to create a Redlander::Model per thread (e.g. Thread.current[:model] ||= Redlander::Model) to avoid segfaults in librdf.

Thoughts?

@cordawyn
Copy link
Owner

Thank you for the contribution, and sorry for my delay in responding to it.

First, I'm absolutely fine with creating Redlander::Model using Thread.current. I think that's how I do it in kalimba. Or not. But I should have done so anyway ;-) In any case, Rails should be happy with that approach.

However, I'm somewhat concerned with initializing librdf_world at require time. Isn't initializing at class level and storing stuff in a constant (Redlander::RDF_WORLD in our case) the primary cause of "thread-unsafety"? So... librdf_world is going to be shared between threads. Is it immutable? I guess we should check with the C side of librdf, unless you've done so already.

You also do not have a finalizer defined for Redlander::RDF_WORLD. I believe it should be there somewhere.

And 2 more things :-)

  1. Could you delete unused code? I'm talking about those mri?, jruby? and rubinius? methods. They're good, but I'd rather avoid stale/unused code. Besides, it's not the competence of Redlander to check Ruby version, if we look at it logically ;-)
  2. I'd appreciate it if you used double colons :: to separate namespaces (constants), but use a dot in front of method calls (e.g. Redland::load_raptor -> Redland.load_raptor). Thank you.

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.

2 participants