Prakash Khandelwal
Prakash Khandelwal

Reputation: 69

Cassandra : OperationTimedOut: errors={}, last_host=127.0.0.1

I am trying "select count(*) from users;" on cassandra but after waiting for 10 seconds (approx) i am getting "OperationTimedOut: errors={}, last_host=127.0.0.1". I am trying this on cqlsh. cqlsh and cassandra versions are below.

cqlsh 5.0.1 | Cassandra 3.0.8

I found few solutions on stackoverflow. But none of them is working. I tried below.

  1. In file cassandra/conf/cassandra.yaml i increased few request_time_out settings and than restarted the cassandra
  2. I created file cqlshrc in folder .cassandra and added below in that file

    [connection]

    client_timeout = 2000000

  3. Few solution in stackoverflow are suggesting to increase some timeout field in file cqlsh, but File '/cassandra/bin/cqlsh' doesn't have any such field, so i didn't change anything in that file. cqlsh file content is below

python -c 'import sys; sys.exit(not (0x020700b0 < sys.hexversion < 0x03000000))' 2>/dev/null \ && exec python "python -c "import os;print(os.path.dirname(os.path.realpath('$0')))"/cqlsh.py" "$@" for pyver in 2.7; do which python$pyver > /dev/null 2>&1 && exec python$pyver "python$pyver -c "import os;print(os.path.dirname(os.path.realpath('$0')))"/cqlsh.py" "$@" done echo "No appropriate python interpreter found." >&2 exit 1

Solutions please.

Upvotes: 2

Views: 1115

Answers (1)

JSierra
JSierra

Reputation: 111

If the Cassandra server is working correctly, the timeout exception raises because the server can't handle the request. Is 'users' table too large?

One solution to count big tables is use the 'counter' type in another table.

For example, we can create a table like this:

CREATE TABLE custom_counters
    (name varchar,
    count counter,
    PRIMARY KEY (name)
);

Every time we insert a user in 'users' table, we update its counter in the 'custom_counters' table:

UPDATE custom_counters
    SET count = count + 1
    WHERE name='users';

So, when we need to know the number of users, we have to request that field:

SELECT count FROM custom_counters WHERE name = 'users';

More info here: https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_counter_t.html

Upvotes: 4

Related Questions