-
Notifications
You must be signed in to change notification settings - Fork 311
Description
Hi,
we are running spring-data-cassandra 3.2.2 with spring-boot 2.5.2
We have been hit by the unprepared query issues and could resolve some of the issues with the update to SB 2.5.2.
Yet, we still get the exception and we consider that it may be because of a lazy converter, that we use and that worked great with the 2.2.x version of SB (Driver V3)
The converter-config looks like this:
public class CassandraConvertersConfiguration {
private final AvroSerializer avroSerializer;
private final AvroDeserializer avroDeserializer;
public CassandraConvertersConfiguration(AvroSerializer avroSerializer, AvroDeserializer avroDeserializer) {
this.avroSerializer = avroSerializer;
this.avroDeserializer = avroDeserializer;
}
@Bean
public CassandraCustomConversions customConversions() {
return new CassandraCustomConversions(asList(
new LazyAvroWriteConverter(avroSerializer),
new LazyAvroReadConverter(avroDeserializer)
));
}
}
The Lazy Converter is like this:
public class LazyAvroReadConverter implements Converter<ByteBuffer, Avro<?>> {
private final AvroDeserializer avroDeserializer;
public LazyAvroReadConverter(AvroDeserializer avroDeserializer) {
this.avroDeserializer = avroDeserializer;
}
@Override
public Avro<?> convert(@NonNull ByteBuffer source) {
return new LazyAvro<>(() -> avroDeserializer.deserialize(source.array()));
}
}
Please remark the lambda in the convert function.
The reasonable behind this is, that the conversion shall only take place, when the value is actually used. As long as objects are "just forwarded", nothing is supposed to happen.
The issue seems to be, that the lambda can get lost in the weak-references cache in the driver. But I don't know enough of the mechanics between the Mapper / Converter and the prepared statement cache in cassandra driver.
Is this pattern disallowed or is there a smarter way to avoid unneccessary ser/deser operations?
Thank you for the support!
Update: In the comments below an important fact is added: The code uses plain cassandra repositories, no PreparedStatements are created in the application itself.