Skip to content
This repository was archived by the owner on Apr 5, 2026. It is now read-only.

Provide JRuby support for model iterating#10

Open
abargnesi wants to merge 1 commit into
cordawyn:masterfrom
abargnesi:rubies_support
Open

Provide JRuby support for model iterating#10
abargnesi wants to merge 1 commit into
cordawyn:masterfrom
abargnesi:rubies_support

Conversation

@abargnesi

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants