question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lazy converter seems to trigger "Tried to execute unprepared query ... but we don't have the data to reprepare it."

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mp911decommented, Aug 31, 2021

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.

0reactions
thst71commented, Aug 31, 2021

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tried to execute unprepared query · Issue #816
Keyed by the statement string. We don't use that map for lookups (since the driver has a cache already) but only to keep...
Read more >
Tried to execute unknown prepared query exception after ...
We have a 3 node Cassandra 2.0.4 cluster and are using version 1.0.5 of the java driver. One of our applications is using...
Read more >
Cassandra Prepared Statement and NodeFailure
I am thinking about node failure scenario that can come while running. I don't know exactly how prepared statement works in this distributed ......
Read more >
(The only proper) PDO tutorial
Having a query with placeholders, you have to prepare it, using the PDO::prepare() ... And with "lazy" binding (using array in execute() ),...
Read more >
Hibernate ORM 5.4.33.Final User Guide
Working with both Object-Oriented software and Relational Databases can be cumbersome and time-consuming. Development costs are significantly higher due to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found