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>



8 comments:

  1. Why is your Cassandra version showing as "Cassandra 2.1.3" in cqlsh prompt when you are executing the command from bin folder of 3.4 ? Does downgrading cqlversion also downgrade cassandra version ? I doubt it. The tar ball you extracted is 3.4 right ?

    ReplyDelete
  2. I am thinking if it's a case of 2 cassandra versions on same host you have. Can you try a fresh install of 3.4 with Py 2.7.6 and check the behavior ?

    ReplyDelete
    Replies
    1. Yeah that makes sense. I have both 2.1.3 and 3.4 and I was starting each of them back to back terminating the other. Some confusion might have occur. Thanks for the catch. Let me check.

      Delete
    2. As I said earlier, it was due to the upgrade from existing 2.1.3 to 3.4 where as the cqlsh trying to connect to existing data directory inside 2.1.3 (which is valid) and some mismatch occurs. Though it is accessing existing data directory, I am not sure why it tries to work on v2.1.3. When I removed that data directory and started cassandra, it created new data directory and this subjected error didn't even occur. Weird.

      Delete
    3. You should not try to mix up 2 versions. As such when you installed 3.4, you wouldn't have hit this issue. The reason it worked after downgrading the CQL VERSION is that it had to search for a version compatible with Cassandra 2.1.3

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. The content is good and very informative and I personally thank you for sharing article on Cassandra.

    ReplyDelete