Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

What are the default values for attributes? #83

Open
sandvige opened this issue May 5, 2015 · 4 comments
Open

What are the default values for attributes? #83

sandvige opened this issue May 5, 2015 · 4 comments

Comments

@sandvige
Copy link
Contributor

sandvige commented May 5, 2015

Hello,

What would be the best way to know the default values for the supported attributes?

Thanks :)

@ghost
Copy link

ghost commented May 5, 2015

@sandvige
Copy link
Contributor Author

sandvige commented May 5, 2015

This page is listing the supported attributes, but if not specified, what are the default values?

@Skunnyk
Copy link
Contributor

Skunnyk commented May 5, 2015

Here are available configurations option with their default value (or at least what I found in the code). Maybe we should add them to the wiki ?

Default values came from Thrift 0.9.1 : lib/cpp/src/thrift/transport/TSocket.cpp , lib/cpp/src/thrift/transport/TSocketPool.cpp and lib/cpp/src/thrift/transport/TSocketPool.h

PDO_CASSANDRA_ATTR_NUM_RETRIES => 1 : How many times to retry each host in connect
PDO_CASSANDRA_ATTR_RETRY_INTERVAL => 60 : Retry interval in seconds, how long to not try a host if it has been marked as down.
PDO_CASSANDRA_ATTR_MAX_CONSECUTIVE_FAILURES => 1 : Max consecutive failures before marking a host down
PDO_CASSANDRA_ATTR_RANDOMIZE => true : Try hosts in order? or Randomized?
PDO_CASSANDRA_ATTR_ALWAYS_TRY_LAST => true (??) : Always try last host, even if marked down?
PDO_CASSANDRA_ATTR_LINGER => false : How long does the socket linger after it's being closed. Value 0 turns off linger.
PDO_CASSANDRA_ATTR_NO_DELAY => 1 : Whether to enable/disable Nagle algorithm.
PDO_CASSANDRA_ATTR_CONN_TIMEOUT => 0 : The connection timeout value. This driver will try to connect if the connection has been lost so this value can be set to control the timeout after object construction.
PDO_CASSANDRA_ATTR_RECV_TIMEOUT => 0 : Receive timeout.
PDO_CASSANDRA_ATTR_SEND_TIMEOUT => 0 : Send timeout.
PDO_CASSANDRA_ATTR_COMPRESSION => 0 : Whether to enable compression.
PDO_CASSANDRA_ATTR_THRIFT_DEBUG => false : Turns on thrift debugging. This converts thrift messages into PHP warnings. This option can be passed into the PDO constructor in the fourth argument.
PDO_CASSANDRA_ATTR_PRESERVE_VALUES => 0 : Preserves values as they come from Cassandra
PDO_CASSANDRA_ATTR_MAX => unused (?)
PDO_CASSANDRA_ATTR_CONSISTENCYLEVEL => ConsistencyLevel::ONE : 

Note that the PDO_CASSANDRA_ATTR_RANDOMIZE is broken in the thrift cpp implementation (no salt), so the same array always return the same node result…

@sandvige
Copy link
Contributor Author

sandvige commented May 5, 2015

Thank you. Yes I think this should be in the Wiki :)

Here is something that emulate the broken randomize:

    private static function generatePermutations($size)
    {
        $permutations = range(0, $size - 1);
        shuffle($permutations);
        return $permutations;
    }

    private static function applyPermutation($array, $permutations)
    {
        if (is_null($permutations))
            return $array;

        $permuted = array();
        foreach ($permutations as $key => $value)
            $permuted[$key] = $array[$value];

        return $permuted;
    }

    private function _constructPdoDsn(array $params)
    {
        $dsn = 'cassandra:';

        if (!isset($params['host']))
            throw new \Exception("No hosts provided");

        if (!isset($params['port']))
            throw new \Exception("No ports provided");

        $hosts = explode(';', $params['host']);
        $ports = explode(';', $params['port']);

        if (count($hosts) != count($ports))
            throw new \Exception("Port count is not corresponding with the host count");

        $permutations = null;
        if (!isset($params['disable_shuffle']) || !$params['disable_shuffle'])
            if (count($hosts) > 1)
                $permutations = self::generatePermutations(count($hosts));

        foreach (self::applyPermutation($hosts, $permutations) as $host)
            $dsn .= 'host=' . $host . ';';

        foreach (self::applyPermutation($ports, $permutations) as $port)
            $dsn .= 'port=' . $port . ';';

        if (isset($params['dbname']))
            $dsn .= 'dbname=' . $params['dbname'] . ';';

        return $dsn;
    }

It's part of our own Doctrine2 driver implementation (https://gist.github.com/sandvige/db7456d340e6b46fd7aa)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants