query : urgent

3 views
Skip to first unread message

vineet daniel

unread,
Apr 22, 2010, 2:54:44 AM4/22/10
to pandr...@googlegroups.com
Hi

In your php files, localhost or some IP is used to connect with cassandra, how do we connect when we have a cluster, secondly, if we are using a single IP and that node is distributing or replicating data to other nodes, what happens if that node fails.

How do we maintain zero point of failure in coding. String of IP's, some loadbalancer or what ??????


mjpearson

unread,
Apr 22, 2010, 4:17:08 AM4/22/10
to pandra-user
Hi,

There's a few different ways of managing this, the easiest being via
the core 'auto' method :

/**
* Given a single host, attempts to find other nodes in the
cluster and attaches them
* to the pool
* @todo build connections from token map
* @param string $host host name or IP of connecting node
* @param string $poolName name of the connection pool (cluster
name)
* @param int $port TCP port of connecting node
* @return bool connected ok
*/
static public function auto($host, $poolName =
self::DEFAULT_POOL_NAME, $port = THRIFT_PORT_DEFAULT);

It grabs a token map of the cluster you're connecting to (via $host)
and automatically creates a connection to each host in the cluster.
If you need fault tolerance against this primary type node, then you'd
probably need to hint the autoconnect host within a loop to detect
total failure :

eg:
<?php
$cassandraHosts = array('host1', 'host2', 'host3');
$hostFound = FALSE;
foreach ($cassndraHosts as $host) {
if (PandraCore::auto($host)) {
// Connected to a cluster? then mark as ok and break out
$hostFound = TRUE;
break;
}
}
if (!$hostFound) die('catastrophe');
?>

All auto really does is run the token map against the core
'connect' method, to add hosts into the pool, so this can be managed
manually also :

eg:
<?php
$hostFound = FALSE;
foreach ($cassndraHosts as $host) {
if (PandraCore::connect($host)) {
$hostFound = TRUE;
}
}
if (!$hostFound) die('catastrophe');
?>

Fault tolerance is managed internally by settable read/write modes
(setReadMode/setWriteMode). Default is 'random'.

MODE_ACTIVE - uses the individual named node, set by
setActiveNode

MODE_ROUND - round-robins across known hosts

MODE_RANDOM - random host selection

The socket pool in core trims hosts it can't contact and marks them as
down via APC or Memcached, so multiple php instances should back off
accordingly - they're retried within a cooldown period (default 10
seconds). This is handled via the getClient method in core if you
want to take a look.

I'd definitely suggest using the PandraCore::auto() method, enabling
the syslog (PandraCore::registerLogger('Syslog');) or mail
(PandraCore::registerLogger('Mail');) loggers may help also..

hope that helps?
michael
> --
> Subscription settings:http://groups.google.com/group/pandra-user/subscribe?hl=en

mjpearson

unread,
Apr 22, 2010, 4:18:10 AM4/22/10
to pandra-user
btw, ignore ' * @todo build connections from token map ' in the phpdoc
- it's an artifact.

vineet daniel

unread,
Apr 22, 2010, 4:19:13 AM4/22/10
to pandr...@googlegroups.com
Thanks, is there any manual for pandra?

mjpearson

unread,
Apr 22, 2010, 4:22:55 AM4/22/10
to pandra-user
Not yet sorry, but it's being worked on.

On Apr 22, 6:19 pm, vineet daniel <vineetdan...@gmail.com> wrote:
> Thanks, is there any manual for pandra?
>
Reply all
Reply to author
Forward
0 new messages