10 November 2012

Riak error: gen_server riak_core_capability terminated with reason: no function clause matching orddict:fetch

I was playing with Riak in the last days. After switching the http IP I got the following error when starting Riak:
root@riak3:~# riak start
Attempting to restart script through sudo -H -u riak
2012-11-10 23:09:31.750 [info] <0.7.0> Application lager started on node 'riak@192.168.219.131'
2012-11-10 23:09:31.800 [info] <0.148.0>@riak_core_ring_manager:reload_ring:226 Upgrading legacy ring
2012-11-10 23:09:31.890 [error] <0.158.0> gen_server riak_core_capability terminated with reason: no function clause matching orddict:fetch('riak@192.168.219.131', []) line 72
The fix was to remove the Riak ring and the start it again:
# rm -rf /var/lib/riak/ring/*
# riak start
Attempting to restart script through sudo -H -u riak
2012-11-10 23:12:13.759 [info] <0.7.0> Application lager started on node 'riak@192.168.219.131'
2012-11-10 23:12:13.808 [warning] <0.148.0>@riak_core_ring_manager:reload_ring:231 No ring file available.
2012-11-10 23:12:13.889 [info] <0.154.0>@riak_core_capability:process_capability_changes:529 New capability: {riak_core,vnode_routing} = proxy
2012-11-10 23:12:13.895 [info] <0.154.0>@riak_core_capability:process_capability_changes:529 New capability: {riak_core,staged_joins} = true
2012-11-10 23:12:13.904 [info] <0.7.0> Application riak_core started on node 'riak@192.168.219.131'
2012-11-10 23:12:13.926 [info] <0.263.0>@riak_core:wait_for_application:425 Waiting for application riak_pipe to start (0 seconds).
2012-11-10 23:12:13.926 [info] <0.7.0> Application riak_pipe started on node 'riak@192.168.219.131'
...

Riak - phpmyadmin like web interface

Now this is a super-lite admin web interface for Riak. Not sure who would use something like this, but here it is free and opensource. This version allows you to see all buckets, all keys of a bucket and the values from one key. Also, you can remove each key individually.

P.S. Sorry about the indent, blogger lost it.

<?php

/*****************************************************
RiakMyAdmin - v0.1
created by Stefan Silasi => stefan@silasi.ro
*****************************************************/

$host = '127.0.0.1:8098'; // <= change this !

/**********************************************************
NO CHANGES FROM HERE ON UNLESS YOU KNOW WHAT YOU'RE DOING
**********************************************************/

function request_riak($bucket = NULL, $key = NULL)
{
global $host, $port, $options;
$curl = curl_init ();

if (!$bucket)
{
// list all buckets
$host .= '/buckets?buckets=true';
}
elseif (($bucket) && (!$key))
{
// list all keys
$host .= '/riak/'.$bucket.'?keys=true';
}
else
{
// list the current key
if ($_GET['cmd']=='DELETE'){curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $_GET['cmd']);}
$host .= '/riak/'.$bucket.'/'.$key.'/';
}

curl_setopt($curl, CURLOPT_URL, $host); // host:port/request
curl_setopt($curl, CURLOPT_HEADER, 0); // no additional headers for CURL
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // returns the curl response in the $RET instead of screen
$ret = curl_exec($curl);
curl_close($curl);

return $ret;
}

$x = request_riak($_GET['bucket'], $_GET['key']);
$a = json_decode($x);

if (!$_GET['bucket']){$arr=$a->{'buckets'};}
elseif ((($_GET['bucket']) && (!$_GET['key'])) || (($_GET['cmd'] == 'DELETE') && ($_GET['bucket']) && ($_GET['key'])))
{
$arr=$a->{'keys'};
echo '<a href="?">Bucket list</a><h1>Bucket: '.$_GET['bucket'].' ('.count($arr).' keys)</h1>';
}
else
{
echo '<a href="?">Bucket list</a><h1>Bucket: <a href="?bucket='.$_GET['bucket'].'">'.$_GET['bucket'].'</a></h1><h2>Key: <a href="?bucket='.$_GET['bucket'].'&key='.$_GET['key'].'">'.$_GET['key'].'</a></h2>';
echo '<textarea rows="25" cols="75">'.$x.'</textarea><br>';

echo '<a href="?bucket='.$_GET['bucket'].'&key='.$_GET['key'].'&cmd=DELETE">Delete</a>';
}

if ($_GET['cmd'] == 'DELETE') { echo 'key '.$_GET['key'].' was deleted. <a href="?bucket='.$_GET['bucket'].'">continue</a>'; exit; }

for ($i=0;$i<count($arr);$i++)
{
if (!$_GET['bucket'])
{
echo 'bucket name: <a href="?bucket='.$arr[$i].'">'.$arr[$i].'</a><br>';
}
elseif (($_GET['bucket']) && (!$_GET['key']))
{
echo 'key name: <a href="?bucket='.$_GET['bucket'].'&key='.$arr[$i].'">'.$arr[$i].'</a><br>';
}
}

?>

09 November 2012

Riak crash: CRASH REPORT Process ID with 0 neighbours crashed with reason: no case clause matching

Each now and then, after 30-60 minutes of playing with default Riak installation I get the following error:
2012-11-10 00:15:28.353 [error] <0.29837.0> CRASH REPORT Process <0.29837.0> with 0 neighbours crashed with reason: no case clause matching {ok,{http_error," /riak/wwwushro/1352495109/ HTTP/1.1\r\n"}} in mochiweb_http:request/3 line 107
It seems that the error is related with the open files limit (1024 by default in Debian). Read here how to increase it.

PHP error: configure: error: could not find curl/curl.h

While playing on a local machine, I got the following error:
configure: error: could not find curl/curl.h
ERROR: `/tmp/pear/temp/pecl_http/configure --with-http-curl-requests --with-http-zlib-compression --with-http-magic-mime=no --with-http-shared-deps' failed
The fix was to install on my Debian machine the libcurl4-openssl-dev package:
apt-get install libcurl4-openssl-dev

PHP error: sh: phpize: not found

While playing on a local machine, I got the following error:
# pecl install pecl_http
downloading pecl_http-1.7.4.tgz ...
Starting to download pecl_http-1.7.4.tgz (174,503 bytes)
.........................done: 174,503 bytes
71 source files, building
running: phpize
sh: phpize: not found
ERROR: `phpize' failed
It seems that I was missing php-dev package on my Debian machine. The fix was:
# apt-get install php5-dev

PHP error: undefined function http_get()

While doing some testing on a local machine, I got the following error:
PHP Fatal error: Call to undefined function http_get() in /var/www/index.php on line 14
The fix was to install the pecl_http extension:
# pecl install pecl_http

puppet: error: Could not request certificate: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A

I moved my puppet server from one datacenter to another and in the new one it was behind a firewall. All the hosts were returning the following error:
err: Could not request certificate: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A
I goggled a lot about this error. In one comment I found this test that helped me to understand the issue:
# openssl s_client -connect puppet:8140
CONNECTED(00000003)
5714:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:s23_lib.c:188:
The problem was clear. SSL handshake could not be made. The firewall was set as HTTP over port 8140. Switching to TCP fixed the issue for me, so the root cause was firewall missconfiguration.
# openssl s_client -connect puppet:8140
CONNECTED(00000003)
depth=1 /CN=Puppet CA: puppet.ww.local
verify error:num=19:self signed certificate in certificate chain
verify return:0
---
Certificate chain
0 s:/CN=puppet.ww.local
i:/CN=Puppet CA: puppet.ww.local
1 s:/CN=Puppet CA: puppet.ww.local
i:/CN=Puppet CA: puppet.ww.local
---
Server certificate
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
subject=/CN=puppet.ww.local
issuer=/CN=Puppet CA: puppet.ww.local
---
No client certificate CA names sent
---
SSL handshake has read 1761 bytes and written 331 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : DHE-RSA-AES256-SHA
Session-ID: D8D86089190C1CCC687C06C796E870575D7C6303559350E19640DFC8D356316C
Session-ID-ctx:
Master-Key:
AD94A3DF004BF12805BAA34398B19E797144A3A7DC85EBAFC7AEE5156CB53B3FE0C8CF6CAEC1EEE933FA8B1958CC0EC9
Key-Arg : None
Start Time: 1352471306
Timeout : 300 (sec)
Verify return code: 19 (self signed certificate in certificate chain)
---