Lazy converter seems to trigger "Tried to execute unprepared query ... but we don't have the data to reprepare it."
See original GitHub issueHi,
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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Thanks a lot. I’m closing this issue. I assume this will serve as documentation for future reports related to weak references in combination with reprepares.
Maybe this information should be explicitely mentioned in the (Spring-Boot?) docs , the driver cache will expose you to the missing statement exception if you just use cassandra-data in the most simple form (a repository and an entity). The CassandraTemplate default makes only sense, if the driver cache is disabled or if you don’t use repositories or CassandraTemplate. Maybe it’s worth to rethink this default?