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