basho / riak-php-client

PHP clients for Riak
Apache License 2.0
160 stars 69 forks source link

Node failover is not working [JIRA: CLIENTS-700] #113

Closed mansoorghori closed 8 years ago

mansoorghori commented 8 years ago

When there is multiple nodes configured for the client and one of the nodes is down the client does not appear to failover to a different node.

The code used to initialize the client is:

$nodes = array();
$riak_hosts_ports = explode(',', $riak_hosts);
foreach($riak_hosts_ports as $riak_host_port) {
  $single_riak_host_port = explode(':', $riak_host_port);
  $riak_host = $single_riak_host_port[0];
  $riak_port = $single_riak_host_port[1];
  // define the connection info to our Riak nodes
  $nodes[] = (new Node\Builder)->atHost($riak_host)->onPort($riak_port)->build();
}

// instantiate the Riak client
$riak_client = new Riak($nodes);

$riak_hosts is a comma-separated list, e.g. riak-host-1:8091,riak-host-2:8092,riak-host-3:8093

Now if one of these nodes is down and the client picks the node that is down, on connection failure it doesn't try another host to fulfil the request

christophermancini commented 8 years ago

@mansoorghori I will look into this and get it resolved in the next few days. Thanks for bringing it to my attention.

christophermancini commented 8 years ago

@mansoorghori I completed a fix for v3 of the client, can you take a look and see if it fixes your needs. #114

mansoorghori commented 8 years ago

@christophermancini Thanks for the update. I had a brief look at the pull request and it seems it might be what I need. I need to try it out. How do I get this WIP code?

christophermancini commented 8 years ago

You should be able to check it out via composer by using the branch name instead of the release version. Just prefix it with "dev-", e. g. dev-issue/113

The other options are to clone the repo and checkout the branch or navigate to the branch on GitHub and download a zip file of the code.

mansoorghori commented 8 years ago

@christophermancini, I've checked the code fix and it works as expected. It tries all the nodes until it get's a response. Thanks.

christophermancini commented 8 years ago

Great! I am off the next few days, I will get a colleague to merge the PR and cut a release.

mansoorghori commented 8 years ago

Hi

Trying to find out if it is possible to get all the keys for the stored objects within a bucket using the PHP client?

Regards

Mansoor Ghori On 9 Jan 2016 22:27, "Christopher Mancini" notifications@github.com wrote:

@mansoorghori https://github.com/mansoorghori I will look into this and get it resolved in the next few days. Thanks for bringing it to my attention.

— Reply to this email directly or view it on GitHub https://github.com/basho/riak-php-client/issues/113#issuecomment-170287657 .

christophermancini commented 8 years ago

Hi @mansoorghori ,

Currently it has not been implemented for PHP but has been for some of our other clients. List keys is an extremely expensive operation on the server side and paging of the result set is not something that has really been implemented Riak side, which is ultimately why I did not implement it in PHP. Some of the other languages can handle the result set a bit easier than PHP could since they are threaded.

I would recommend at least for now, that maybe you try to depend on Yokozuna (solr) to retrieve keys within a bucket as it is a much safer operation and currently supported.

If you truly need a full list keys, you could hit the HTTP interface directly using curl and it returns JSON so it should be fairly trivial to implement as a one off.

With the performance gains of PHP 7, it might be something that gets officially added when our PB dependency library supports PHP 7. Just for now, it doesn't seem like something that would add more value than headaches to support.

Chris