1

我建立了一个有 2 个节点的 cassandra 集群。经过几千次写入后,它开始抛出 TimeOut 异常,这些异常直到我重新启动 cassandra 服务后才会消失。我正在使用 phpcassa(撰写本文时最新)。

Cassandra.yaml 两者

  • cluster_name: '测试集群'
  • 种子提供者:
    • 类名:org.apache.cassandra.locator.SimpleSeedProvider
  • 参数:
    • 种子:“192.168.2.101”
  • rpc_address:0.0.0.0
  • rpc_port:8080

卡桑德拉.yaml 1

  • 初始令牌:0
  • 监听地址:192.168.2.101

卡桑德拉.yaml 2

  • 初始令牌:85070591730234615865843651857942052864
  • 监听地址:192.168.2.102

假设这个配置是正确的,那么我的代码肯定有问题。这是我为重现错误而制作的测试脚本:

$pool = Config::ConnectionPool();
$stressTest = new ColumnFamily($pool, 'TwitterTest');
$id = 392766928478932992;

while(true)
{
    try
    {
        $stressTest->insert($id++, array("analyzed"=>0, "followersCount"=>"35",
            "friendsCount"=>"30", "lang"=>"en", "listedCount"=>"0",
            "name"=>"Henky Tanky", "statusesCount"=>"X", "text"=>"@HERPDERP dude i kno i lost a 16gb flash drive #MEH",
            "time"=>"2013-10-22 23:38:27", "twitterId"=>"392766928478932992", "username"=>"mehzor"),
            null, null, \cassandra\ConsistencyLevel::ANY);
    }
    catch (Exception $ex){
        print_r($ex);
        exit;
    }
}

class Config {
    static function ConnectionPool(){
        return new ConnectionPool('KSTwit', array('192.168.2.101:8080', '192.168.2.102:8080'));
    }
}

使用该配置,我得到一个'cassandra\TimedOutException'(Stacktrace 1)

// Set max-retries to 5, and read/write timeout to 60 seconds
new ConnectionPool('KSTwit', array('192.168.2.101:8080', '192.168.2.102:8080'), NULL, 5, 60000, 60000);

使用该配置,我得到一个“Thrift\Exception\TTransportException”(Stacktrace 2)

我尝试了各种 ConsistencyLevels;一个,法定人数和任何。他们所有人都有同样的问题。

正如我所说,异常不会发生,直到几千次写入之后。但是,如果我在发生异常后重新启动脚本,它将立即抛出异常。我必须重新启动 cassandra 服务,然后可能需要几千次。这似乎只发生在写入中。如果我不使用计数器列也会发生这种情况,所以这不是问题。

堆栈跟踪 1

Error performing add on 192.168.2.101:8080: exception 'cassandra\TimedOutException' in /var/installstuff/cassphp/lib/Thrift/Base/TBase.php:206
Stack trace:
#0 /var/installstuff/cassphp/lib/cassandra/Cassandra.php(3575): Thrift\Base\TBase->_read('Cassandra_add_r...', Array, Object(Thrift\Protocol\TBinaryProtocolAccelerated))
#1 /var/installstuff/cassphp/lib/cassandra/Cassandra.php(768): cassandra\Cassandra_add_result->read(Object(Thrift\Protocol\TBinaryProtocolAccelerated))
#2 /var/installstuff/cassphp/lib/cassandra/Cassandra.php(728): cassandra\CassandraClient->recv_add()
#3 [internal function]: cassandra\CassandraClient->add('All Tweets', Object(cassandra\ColumnParent), Object(cassandra\CounterColumn), 1)
#4 /var/installstuff/cassphp/lib/phpcassa/Connection/ConnectionPool.php(264): call_user_func_array(Array, Array)
#5 /var/installstuff/cassphp/lib/phpcassa/ColumnFamily.php(44): phpcassa\Connection\ConnectionPool->call('add', 'All Tweets', Object(cassandra\ColumnParent), Object(cassandra\CounterColumn), 1)
#6 /var/installstuff/cassphp/examples/db/TweetDatabase.php(103): phpcassa\ColumnFamily->add('All Tweets', 'Total')
#7 /var/installstuff/cassphp/examples/core/Helper.php(16): {closure}()
#8 /var/installstuff/cassphp/examples/db/TweetDatabase.php(104): Helper::DoForgiving(Object(Closure))
#9 /var/installstuff/cassphp/examples/core/twitterParser.php(98): TweetDatabaseCassandra->AddTweet('392633738364190...', Array)
#10 /var/installstuff/cassphp/examples/core/twitterParser.php(192): TwitterParser->RunOnce()
#11 /var/installstuff/cassphp/examples/runners/twitterParserCassandra.php(19): TwitterParser->Run()
#12 {main}

堆栈跟踪 2

Error performing add on 192.168.2.101:8080: exception 'Thrift\Exception\TTransportException' with message 'TSocket: timed out reading 4 bytes from 192.168.2.101:8080' in /var/installstuff/cassphp/lib/Thrift/Transport/TSocket.php:284
Stack trace:
#0 /var/installstuff/cassphp/lib/Thrift/Transport/TTransport.php(74): Thrift\Transport\TSocket->read(4)
#1 /var/installstuff/cassphp/lib/Thrift/Transport/TFramedTransport.php(139): Thrift\Transport\TTransport->readAll(4)
#2 /var/installstuff/cassphp/lib/Thrift/Transport/TFramedTransport.php(106): Thrift\Transport\TFramedTransport->readFrame()
#3 /var/installstuff/cassphp/lib/Thrift/Transport/TTransport.php(74): Thrift\Transport\TFramedTransport->read(4)
#4 /var/installstuff/cassphp/lib/Thrift/Protocol/TBinaryProtocol.php(305): Thrift\Transport\TTransport->readAll(4)
#5 /var/installstuff/cassphp/lib/Thrift/Protocol/TBinaryProtocol.php(197): Thrift\Protocol\TBinaryProtocol->readI32(NULL)
#6 /var/installstuff/cassphp/lib/cassandra/Cassandra.php(760): Thrift\Protocol\TBinaryProtocol->readMessageBegin(NULL, 0, 0)
#7 /var/installstuff/cassphp/lib/cassandra/Cassandra.php(728): cassandra\CassandraClient->recv_add()
#8 [internal function]: cassandra\CassandraClient->add('All Tweets', Object(cassandra\ColumnParent), Object(cassandra\CounterColumn), 1)
#9 /var/installstuff/cassphp/lib/phpcassa/Connection/ConnectionPool.php(264): call_user_func_array(Array, Array)
#10 /var/installstuff/cassphp/lib/phpcassa/ColumnFamily.php(44): phpcassa\Connection\ConnectionPool->call('add', 'All Tweets', Object(cassandra\ColumnParent), Object(cassandra\CounterColumn), 1)
#11 /var/installstuff/cassphp/examples/db/TweetDatabase.php(103): phpcassa\ColumnFamily->add('All Tweets', 'Total')
#12 /var/installstuff/cassphp/examples/core/Helper.php(17): {closure}()
#13 /var/installstuff/cassphp/examples/db/TweetDatabase.php(104): Helper::DoForgiving(Object(Closure))
#14 /var/installstuff/cassphp/examples/core/twitterParser.php(98): TweetDatabaseCassandra->AddTweet('392642135327264...', Array)
#15 /var/installstuff/cassphp/examples/core/twitterParser.php(192): TwitterParser->RunOnce()
#16 /var/installstuff/cassphp/examples/runners/twitterParserCassandra.php(19): TwitterParser->Run()
#17 {main}

cassandra 日志并没有真正显示出任何有趣的东西。除了这种情况发生了很多,但即使没有发生异常也会发生这种情况,所以我认为这不是问题;

INFO 10:58:58,241 Timed out replaying hints to /192.168.2.102; aborting further deliveries
WARN 11:07:17,979 MemoryMeter uninitialized (jamm not specified as java agent); assuming liveRatio of 10.0.  Usually this means cassandra-env.sh disabled jamm because you are using a buggy JRE; upgrade to the Sun JRE instead

使用“SIMPLE_STRATEGY”和“replication_factor = 2”设置密钥空间根据两台机器上的“nodetool ring”命令,即使在触发异常后节点也“正常”运行。老实说,我不知道下一步该尝试什么,有人能发现问题吗?

4

1 回答 1

0

我以两种方式之一解决了这个问题(不能确定。)

我最初使用列出这些 repo 的在线指南安装了 cassandra;

deb http://www.apache.org/dist/cassandra/debian 11x main
deb-src http://www.apache.org/dist/cassandra/debian 11x main

这些已经过时了,有一个20x版本,所以我更新了。

我也换成jsvc了sun的java。现在一切正常。

于 2013-11-06T09:33:45.147 回答