Showing posts with label Cassandra. Show all posts
Showing posts with label Cassandra. Show all posts

Mar 30, 2016

org.apache.cassandra.transport.ProtocolException: Invalid or unsupported protocol version: 4

When I wanted to upgrade my Cassandra from 2.1.3 to 3.4 in Windows 7 64 bit, I have faced following error when starting cqlsh console.

E:\apache-cassandra-3.4\bin>cqlsh
Connection error: ('Unable to connect to any servers', {'127.0.0.1': ConnectionException(u'Did not get expected SupportedMessage response; instead, got: <ErrorMessage code=0000 [Server error] message="io.netty.handler.codec.DecoderException: org.apache.cassandra.transport.ProtocolException: Invalid or unsupported protocol version: 4">',)})

This was happening even when I downgrade my cqlversion as follows.

E:\apache-cassandra-3.4\bin>cqlsh --cqlversion=3.4.0
Connection error: ('Unable to connect to any servers', {'127.0.0.1': ConnectionException(u'Did not get expected SupportedMessage response; instead, got: <ErrorMessage code=0000 [Server error] message="io.netty.handler.codec.DecoderException: org.apache.cassandra.transport.ProtocolException: Invalid or unsupported protocol version: 4">',)})

E:\apache-cassandra-3.4\bin>python -V
Python 2.7.6
E:\apache-cassandra-3.4\bin>cqlsh --version
cqlsh 5.0.1

This is due to protocol version (4) unsupported by cql.
Edit <cassandra_home>\bin\cqlsh.py to make following inclusions so that it accepts --protocolversion argument along with cqlsh command. It's advisable to take backup of cqlsh.py file before editing it.

I have given edited lines below. Add only the lines that are marked with + (plus sign). Other lines are given for reference of places to make change. 

.
.
parser.add_option('--cqlversion', default=DEFAULT_CQLVER,
                  help='Specify a particular CQL version (default: %default).'
                       ' Examples: "3.0.3", "3.1.0"')
+ parser.add_option("--protocolversion", default=DEFAULT_PROTOCOL_VERSION, help='Specify protocol version (default: %default).')
parser.add_option("-e", "--execute", help='Execute the statement and quit.')

.
.
    try:
        port = int(port)
    except ValueError:
        parser.error('%r is not a valid port number.' % port)

+    if options.protocolversion:

+       try:
+            options.protocolversion = int(options.protocolversion)
+        except ValueError:
+            options.protocolversion=DEFAULT_PROTOCOL_VERSION

    return options, hostname, port

.
.
                      connect_timeout=options.connect_timeout,
                      encoding=options.encoding,
 +                    protocol_version=options.protocolversion)
    except KeyboardInterrupt:
        sys.exit('Connection aborted.')

Once the changes are done, save it and restart Cassandra server. Now execute cqlsh with following command.

E:\apache-cassandra-3.4\bin>cqlsh --protocolversion=3

Still you may face any issue like following.

Connection error: ('Unable to connect to any servers', {'127.0.0.1': ProtocolError("cql_version '3.4.0' is not supported by remote (w/ native protocol). Support
ed versions: [u'3.2.0']",)})

In such case, execute cqlsh command as follows and the issue would be resolved now.
E:\apache-cassandra-3.4\bin>cqlsh --protocolversion=3 --cqlversion=3.2.0
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 2.1.3 | CQL spec 3.2.0 | Native protocol v3]
Use HELP for help.
WARNING: pyreadline dependency missing.  Install to enable tab completion.
cqlsh>



Jul 6, 2015

nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection refused'. (Cassandra)


Error While Using Cassandra’s 'nodetool'

This error may occur when using the 'nodetool' command, such as in the following example:

$ nodetool status

For both CentOS 6 and CentOS 7 search the following configuration file:

cassandra-env.sh


This will be inside your <cassandra_home>/conf/ directory
Open this file in edit mode (Make sure you have permission to edit this file. Here I am a root user, so I have permission to edit it)

$ vim <cassandra_home>/conf/cassandra-env.sh


Tips: If you couldn't find this file, use 'locate' command to get the file location.
$ locate cassandra-env.sh


Once you open the file in edit mode, search for:

JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=

Which will probably result in:

# add this if you’re having trouble connecting:
# JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<public name>"


Uncomment the second line, and add the hostname of your server (replace <public name> with the IP/hostname), or the IP address which you’re connecting to/from.

Then exit and save the file.

Final Note:
Make Sure to restart Cassandra once the changes are done.