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>