public static Row createSingleStringRow(String value, int protocolVersion) { ColumnDefinitions definitions = new ColumnDefinitions(new Definition[] {new Definition("keyspace", "table", "column", DataType.ascii())}, CodecRegistry.DEFAULT_INSTANCE); ByteBuffer data = ByteBuffer.wrap(value.getBytes(UTF_8)); return ArrayBackedRow.fromData(definitions, null, ProtocolVersion.fromInt(protocolVersion), ImmutableList.of(data)); } }
private static int sizeOfValue(ByteBuffer value, ProtocolVersion version) { switch (version) { case V1: case V2: int elemSize = value.remaining(); if (elemSize > 65535) throw new IllegalArgumentException( String.format( "Native protocol version %d supports only elements with size up to 65535 bytes - but element size is %d bytes", version.toInt(), elemSize)); return 2 + elemSize; case V3: case V4: case V5: return value == null ? 4 : 4 + value.remaining(); default: throw version.unsupported(); } }
static int serializedSize(ProtocolVersion version) { return version.compareTo(ProtocolVersion.V5) >= 0 ? 4 : 1; } }
if (flags.contains(QueryFlag.VALUES)) { if (flags.contains(QueryFlag.VALUE_NAMES)) { assert version.compareTo(ProtocolVersion.V3) >= 0; CBUtil.writeNamedValueList(namedValues, dest); } else { if (flags.contains(QueryFlag.SERIAL_CONSISTENCY)) CBUtil.writeConsistencyLevel(serialConsistency, dest); if (version.compareTo(ProtocolVersion.V3) >= 0 && flags.contains(QueryFlag.DEFAULT_TIMESTAMP)) dest.writeLong(defaultTimestamp); break; default: throw version.unsupported();
private ByteBuffer generateCompleteOutput() { ByteBuffer res = ByteBuffer.allocate(pagingState.length + hash.length + 6); res.putShort((short) pagingState.length); res.putShort((short) hash.length); res.put(pagingState); res.put(hash); res.putShort((short) protocolVersion.toInt()); res.rewind(); return res; }
throws InvalidTypeException { if (array == null) return null; boolean isProtocolV3OrAbove = protocolVersion.compareTo(ProtocolVersion.V2) > 0; isProtocolV3OrAbove || length < 65536, "Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", protocolVersion.toInt(), length);
boolean supports(ProtocolVersion version) { return getCassandraVersion() == null || version.minCassandraVersion().compareTo(getCassandraVersion().nextStable()) <= 0; }
private static int streamIdSizeFor(ProtocolVersion version) { switch (version) { case V1: case V2: return 1; case V3: case V4: case V5: return 2; default: throw version.unsupported(); } }
private void negotiateProtocolVersionAndConnect() { boolean shouldNegotiate = (configuration.getProtocolOptions().initialProtocolVersion == null); while (true) { try { controlConnection.connect(); return; } catch (UnsupportedProtocolVersionException e) { if (!shouldNegotiate) { throw e; } // Do not trust version of server's response, as C* behavior in case of protocol // negotiation is not // properly documented, and varies over time (specially after CASSANDRA-11464). Instead, // always // retry at attempted version - 1, if such a version exists; and otherwise, stop and fail. ProtocolVersion attemptedVersion = e.getUnsupportedVersion(); ProtocolVersion retryVersion = attemptedVersion.getLowerSupported(); if (retryVersion == null) { throw e; } logger.info( "Cannot connect with protocol version {}, trying with {}", attemptedVersion, retryVersion); connectionFactory.protocolVersion = retryVersion; } } }
@Override public ProtocolVersion decode(String fromCassandra) throws AchillesTranscodingException { if (StringUtils.isEmpty(fromCassandra)) { return null; } else { return ProtocolVersion.valueOf(fromCassandra); } } }
@Override protected void encode(ChannelHandlerContext ctx, Frame frame, List<Object> out) throws Exception { ProtocolVersion protocolVersion = frame.header.version; ByteBuf header = ctx.alloc().ioBuffer(Frame.Header.lengthFor(protocolVersion)); // We don't bother with the direction, we only send requests. header.writeByte(frame.header.version.toInt()); header.writeByte(Header.Flag.serialize(frame.header.flags)); writeStreamId(frame.header.streamId, header, protocolVersion); header.writeByte(frame.header.opcode); header.writeInt(frame.body.readableBytes()); out.add(header); out.add(frame.body); }
if (flags.contains(QueryFlag.VALUES)) { if (flags.contains(QueryFlag.VALUE_NAMES)) { assert version.compareTo(ProtocolVersion.V3) >= 0; size += CBUtil.sizeOfNamedValueList(namedValues); } else { if (flags.contains(QueryFlag.SERIAL_CONSISTENCY)) size += CBUtil.sizeOfConsistencyLevel(serialConsistency); if (version.compareTo(ProtocolVersion.V3) >= 0 && flags.contains(QueryFlag.DEFAULT_TIMESTAMP)) size += 8; return size; default: throw version.unsupported();
cassandraVersion = cluster.protocolVersion().minCassandraVersion(); logger.warn( "Cannot find Cassandra version for host {} to parse the schema, using {} based on protocol version in use. "
private static int sizeOfCollectionSize(ProtocolVersion version) { switch (version) { case V1: case V2: return 2; case V3: case V4: case V5: return 4; default: throw version.unsupported(); } }
ProtocolVersion usedVersion = ccm().getProtocolVersion(); while (version != usedVersion && version != null) { version = version.getLowerSupported(); expectedNumberOfCalls++;
.withCredentials(cassandra.getUsername(), cassandra.getPassword()) .withPoolingOptions(poolingOptions) .withProtocolVersion(ProtocolVersion.valueOf(cassandra.getProtocolVersion())) .withLoadBalancingPolicy(loadBalancingPolicy) .withSocketOptions(socketOptions)
builder = builder.withProtocolVersion(ProtocolVersion.fromInt(protoVer));
/** * Utility method that writes a size value. Mainly intended for collection codecs when serializing * CQL collections. * * @param output The ByteBuffer to write to. * @param size The collection size. * @param version The protocol version to use. */ public static void writeSize(ByteBuffer output, int size, ProtocolVersion version) { switch (version) { case V1: case V2: if (size > 65535) throw new IllegalArgumentException( String.format( "Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", version.toInt(), size)); output.putShort((short) size); break; case V3: case V4: case V5: output.putInt(size); break; default: throw version.unsupported(); } }
private ByteBuffer generateCompleteOutput() { ByteBuffer res = ByteBuffer.allocate(pagingState.length + hash.length + 6); res.putShort((short) pagingState.length); res.putShort((short) hash.length); res.put(pagingState); res.put(hash); res.putShort((short) protocolVersion.toInt()); res.rewind(); return res; }
/** * Determines whether or not the input version supports ths feature. * * @param version the version to test against. * @return true if supported, false otherwise. */ boolean isSupportedBy(ProtocolVersion version) { switch (this) { case PREPARED_METADATA_CHANGES: return version == ProtocolVersion.V5; case CUSTOM_PAYLOADS: return version.compareTo(ProtocolVersion.V4) >= 0; case CLIENT_TIMESTAMPS: return version.compareTo(ProtocolVersion.V3) >= 0; default: return false; } } }