You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Andrew Reynhout (JIRA)" <ji...@apache.org> on 2010/01/30 19:44:34 UTC

[jira] Created: (ZOOKEEPER-661) Add Ruby bindings

Add Ruby bindings
-----------------

                 Key: ZOOKEEPER-661
                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
             Project: Zookeeper
          Issue Type: New Feature
          Components: contrib-bindings
         Environment: MRI Ruby 1.9
JRuby 1.4
            Reporter: Andrew Reynhout
            Priority: Minor


Add Ruby bindings to the ZooKeeper distribution.

Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.

Proposed approach will be described in comment.

Please use this ticket for discussion and suggestions.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Patrick Hunt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12879391#action_12879391 ] 

Patrick Hunt commented on ZOOKEEPER-661:
----------------------------------------

Cool, thanks all! It would be great to see all this unified and in contrib, but seeing activity on this front regardless of where/how it's hosted is awesome! Thanks!

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Topper Bowers (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12869282#action_12869282 ] 

Topper Bowers commented on ZOOKEEPER-661:
-----------------------------------------

I've been hacking on this too: http://github.com/tobowers/zookeeper/tree/dev/eventmachine

I've basically taken everybody else's work and modified and combined to make something that's "getting there."  I'm not a fan of the FFI method as it can cause issues.  Also, Solaris (our prod env) seems to really dislike it.

My branch here has an MRI that can synchronously write/read (without watches and without eventmachine).  If you add in event machine, watches are enabled.
Jruby (our other prod env) one should theoretically support all the async and watchers out of the box.

Added some sugar: queues and lockers (lockers can be used without watches).

People think I'm on the right track here?

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Andrew Reynhout (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12836239#action_12836239 ] 

Andrew Reynhout commented on ZOOKEEPER-661:
-------------------------------------------

Looks like emaland forked the old myelin code.  We looked at that, but ultimately decided to start over using Ruby FFI.  Also, it doesn't look like they've done async calls and watchers yet, but maybe I missed it.

Asynchronous calls were never high priority for my use case, but watchers were essential.  Both ran into the same threading problems though, so I ended up using the same workarounds.

I've been a bit distracted for the last few weeks, so I haven't made any progress on the MT vs ST idea.  I've moved all of the code into a public github repo, so if it's useful please check it out.

http://github.com/ce/ruby-zookeeper



> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "brian wickman (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12879197#action_12879197 ] 

brian wickman commented on ZOOKEEPER-661:
-----------------------------------------

Yet another version - http://github.com/wickman/zookeeper

In the distant future when we're able to move our app to 1.9, it'd make good sense to merge with the FFI branch.  In the meantime, we're stuck on 1.8.  This fork uses a client API similar to Reynhout's FFI version (args via hashes w/ optionals), but differs in that it works on MRI 1.8 while still supporting watchers and callbacks.  Right now it polls to dispatch callbacks, and like Topper's, needs only another 10 lines of code to integrate EventMachine to wake up to a ping over a FIFO/socket passed to the C extension.  For the sake of minimalism, I left it as-is for now since we're not exactly using ZK as a hyper-performant datastore.

I'm not sure about Topper's dev environment (maybe Ruby threading on Solaris is happier?), but I was unable to get any Ruby C extension API methods to work at all from the Zookeeper thread pool.  I'm sure the 1.9 dev environment is a bit safer still.  Unfortunately, the instant you try to do anything on 1.8 that has the side effect of allocating some data on a stack (e.g. rb_funcall or rb_hash_new), the Ruby interpreter segfaults.  To get around this in my extension, all callback and watcher completions get saved and queued on the ZK side and dispatched from the polling method on the Ruby side, effectively decoupling the ZK threadpool from the Ruby interpreter.  Conversion from ZK data types to native Ruby data types always happens in a thread context that is active in the Ruby interpreter, side-stepping the annoying thread-safety problems.

Please take a look.  I'm new to Ruby, so pardon any idiomatic faux pas.

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Andrew Reynhout (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12828709#action_12828709 ] 

Andrew Reynhout commented on ZOOKEEPER-661:
-------------------------------------------

Hi Patrick,

The threading trickiness is similar to Python's: no true native threads, and a big Global Interpreter Lock (Ruby calls it the GVL).  Unlike Python, Ruby's mechanisms exposed for external synchronization are (appear to be) awkward and very sparsely documented.  I'm no expert on Ruby internals either, but I spent some time trolling through the 1.8 and 1.9 source trees to find a way to make this work...this is the best solution I could come up with.

Your point about the ZK ST vs MT libraries is interesting.  I considered that approach at one point, but abandoned it because I thought it wouldn't work for watchers.  I don't remember what made me think that -- I've been working on this very sporadically for a while.  If I'm following the concept, I would just manage all of the threading within Ruby and let the async calls (and watchers) wait in Ruby threads for the libzookeeper_st function to return..?

I'll take a look at that and see what I can learn.  Thank you for the pointers.


> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Jeff Hammerbacher (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12836061#action_12836061 ] 

Jeff Hammerbacher commented on ZOOKEEPER-661:
---------------------------------------------

How does this work compare to http://github.com/emaland/zookeeper_client/?

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Andrew Reynhout (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12828782#action_12828782 ] 

Andrew Reynhout commented on ZOOKEEPER-661:
-------------------------------------------

I used EventMachine an early attempt, but couldn't get it to work without also patching ZK.  I tried Rev too, but not extensively because I don't know it as well as EM.  I'll try again though, perhaps I've learned something important since then. :)  Merci.



> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Patrick Hunt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12837997#action_12837997 ] 

Patrick Hunt commented on ZOOKEEPER-661:
----------------------------------------

Cool. Sounds like a good idea. Let me know if I can help.

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Andrew Reynhout (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12837572#action_12837572 ] 

Andrew Reynhout commented on ZOOKEEPER-661:
-------------------------------------------

Patrick,

I agree on the collaboration recommendation.  I haven't had a chance to go through all of the changes in Eric's fork yet, so I'm not sure how the two attempts compare in terms of functional completeness.  I'll get in touch with Eric and Evan and see how they feel.

The primary difference in the two approaches is that we're using FFI and they are using a straight C extension.  FFI should make it simpler to keep up with any ZK API changes, and make the code more conveniently portable to JRuby and other platforms, but that might not be a big deal -- ZK is at 3.3, and the C API has been pretty stable.

Re: ASF vs github, I think it'd be great to have Ruby bindings in the official distribution, as soon as the bindings are worthy. Github and rubygems definitely make it easier to iterate on the bindings independently of the ZK/ASF release process, but theoretically at some point the bindings will catch up and ZK changes will drive the binding iterations.

Thanks,
Andrew


> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Patrick Hunt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12828196#action_12828196 ] 

Patrick Hunt commented on ZOOKEEPER-661:
----------------------------------------

Hi Andrew, I have no knowledge of ruby extension mechanisms so please keep that in mind wrt my response. ;-)

We'd love to include a ruby binding in the contrib for zk.

Can you describe, what is the "special threading difficulties" that you mention? Are you using the 
multi threaded version of the ZK c client library, or the single threaded? It might
be easier for you to integrate if you use the ST version, however you'll need to do a bit more work. See the
cli.c in trunk/src/c/src of zookeeper for an example of the differences (the THREADED define in cli.c in particular).

I've been in discussions recently with zkperl users who are looking for async support. The current binding for 
zkperl only supports sync calls for what sounds like a similar issue to what you are facing. One option that
sounded promising was switching to use of st rather than mt binding. Please take a look and let me know if
you have questions (again, cli.c is a good example of what's diff).

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Patrick Hunt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12828765#action_12828765 ] 

Patrick Hunt commented on ZOOKEEPER-661:
----------------------------------------

the perl guys mentioned http://search.cpan.org/dist/AnyEvent/ I see a few things popup for "ruby event library", at first
glance these look like they might be good options along with ZK ST (rev is built on libev for example):

http://rev.rubyforge.org/rdoc/

http://rubyeventmachine.com/

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Eric Maland (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12839400#action_12839400 ] 

Eric Maland commented on ZOOKEEPER-661:
---------------------------------------

We're definitely not attached to any one specific approach;  developing a client with ASF/contrib and completeness in mind is probably the best approach, and we're happy to switch gears to collaborate.  I agree that having one great and complete client is better than N incomplete ones.

Our current client is definitely far from complete, but far more complete than it was and for now it meets our needs.  Very soon it will not and we'll be working on completing it.  If we can instead put that effort into completing a comparable client, that sounds good by me.

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Andrew Reynhout (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806730#action_12806730 ] 

Andrew Reynhout commented on ZOOKEEPER-661:
-------------------------------------------

I have a WIP patch for the ZK C API, and an alpha level Ruby library that works fairly well.  

The following is a diff of the ZK C API patch (excerpted for clarity), for example and discussion.  The full patch is basically as below, repeated multiple times for multiple completion types, plus some autoconf tweaks to enable the ruby-specific code.  I can attach the full patch, but this is much less noisy and seems much more useful at this stage.

{code:title=zookeeper.c process_completions() diff}
             case COMPLETION_STAT:
                 LOG_DEBUG(("Calling COMPLETION_STAT for xid=%x rc=%d",cptr->xid,rc));
                 if (rc) {
+#ifdef HAVE_LIBRUBY
+                    if (getenv("RUBY_MRI_VERSION") != NULL)
+                        ruby_stat_completion_wrapper(cptr->c.stat_result, rc, 0, cptr->data);
+                    else
+#endif
                     cptr->c.stat_result(rc, 0, cptr->data);
                 } else {
                     struct SetDataResponse res;
                     deserialize_SetDataResponse(ia, "reply", &res);
+#ifdef HAVE_LIBRUBY
+                    if (getenv("RUBY_MRI_VERSION") != NULL)
+                        ruby_stat_completion_wrapper(cptr->c.stat_result, rc, &res.stat, cptr->data);
+                    else
+#endif
                     cptr->c.stat_result(rc, &res.stat, cptr->data);
                     deallocate_SetDataResponse(&res);
                 }
{code}

And this is the new code to support the Ruby bindings.

{code:title=zookeeper.c ruby support functions}

static struct Stat *stat_dup(struct Stat *stat)
  {
  struct Stat *stat_copy = malloc(sizeof(struct Stat));

  memcpy(stat_copy,stat,sizeof(struct Stat));
  return stat_copy;
  }

typedef struct stat_completion_data {
  stat_completion_t dc;
  int rc;
  struct Stat *stat;
  void *ctx;
  } stat_completion_data;

static void ruby_stat_completion_wrapper_2(struct stat_completion_data *cb)
  {
  cb->dc(cb->rc, cb->stat, cb->ctx);
  free(cb);
  }
  
static void ruby_stat_completion_wrapper(stat_completion_t dc, int rc, struct Stat *stat, void *ctx)
  {
  struct stat_completion_data *cb;

  cb = (stat_completion_data *)malloc(sizeof(stat_completion_data));
  cb->dc = dc;
  cb->rc = rc;
  cb->stat = stat ? stat_dup(stat) : 0;
  cb->ctx = ctx ? strdup(ctx) : 0;

  rb_thread_create((void *)ruby_stat_completion_wrapper_2, cb);
  }
{code}

*Known Issues*

 - I'm not treating the context pointer properly (should be struct buffer), and the strdup() is egregious -- but surprisingly this _works_ under MRI (standard) Ruby, and the correct approach does not...!  However:
 - In JRuby, the context data is mangled.  This might be my bug (I can't get good data out of ctx->buff and ctx->len...  inspection of the pointer address doesn't look like the expected struct layout either..), or possibly a quirk of the data structure expectations in JRuby FFI.  WIP, but lowered priority -- a) I don't think passing contexts into completions serve much purpose in Ruby, and b) I need to do some more reading to figure out next steps.
 - Memory allocations are not freed properly in a few cases -- I think I need to allocate the space with a C-Ruby call so that Ruby can GC it when appropriate, because the C thread could be long gone by then.  This is small but since the Ruby code might be long-running, becomes important.
 - Checking an environment variable to decide whether to wrap the callback in a Ruby thread is ugly.  However, JRuby doesn't require thread wrapping due to superior JVM threading (but might to resolve the context struct problem, TBD) so I can't just test a Ruby global that would be set by both, and I don't want to wrap all callbacks just because libruby was included at compile time.  New versions of JRuby set a unique global that I could use in conjunction with the standard Ruby globals to test "ruby-but-not-jruby", but that would cause failures on older JRuby versions.

Does this code (or the vastly improved version of it that will result from the ensuing discussions!) look like something that could/should be part of the standard ZooKeeper API/contrib distribution?  I'm currently bundling the ZK C API diff with the ruby-zookeeper Ruby library, but that isn't ideal.  The ruby-zookeeper gem will be released under AL2.0, which matches ZooKeeper obviously.

Thank you for any comments or suggestions.





> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ZOOKEEPER-661) Add Ruby bindings

Posted by "Patrick Hunt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12836760#action_12836760 ] 

Patrick Hunt commented on ZOOKEEPER-661:
----------------------------------------

I'd like to encourage both of you to consider submitting a patch to include the binding in ZK contrib. I realize that doing it on github makes for a more agile process, perhaps if not today then at some point in the future.

Also, would it make sense for the two projects/bindings to collaborate? Having two bindings is fine, but having one would be better. ;-) Esp if the collaboration will focus features/testing/usability/docs/etc... that each project individually might not have (ie pool your resources).

Regards and thanks!

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, watchers, etc).  It looks like the simplest workaround is to patch the ZK C API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.