gocql icon indicating copy to clipboard operation
gocql copied to clipboard

Dont mutate query/batch when executing queries

Open Zariel opened this issue 6 years ago • 5 comments

We shouldnt mutate query or batch when executing, looks like we store the new PageState on the query which should only be on the iter.

Zariel avatar Oct 24 '18 20:10 Zariel

@Zariel Can I reuse Query instances?

I have code that reuse a query instance, which worked fine with commit before https://github.com/gocql/gocql/commit/271c061c7f16702ca550b0e9721320b1c92e00cb, but do not work anymore with commit after https://github.com/gocql/gocql/commit/271c061c7f16702ca550b0e9721320b1c92e00cb. I wrote a simple test case in gist. Please look at https://gist.github.com/skaji/e58aaa1fa2d4c893f6a6fa7666bb70f1

skaji avatar Jan 16 '19 15:01 skaji

We were just bit by this. We had a query object we were reusing, where the first use didn't read all the records and closed the iterator early, and then the second query was skipping over the records that were already read, even though it was a brand new iterator.

Until it is made safe I suggest updating the documentation to note that reuse of a query object is not safe.

dankinder avatar Mar 09 '20 13:03 dankinder

To be fair @dankinder the documentation for Session states that it is safe for concurrent use but the Query object has no such doc and assuming safety is never safe. If they are not accessed concurrently then maybe it can be that the pageState is not reset properly. Maybe it should be reset in the defaultsFromSession I am not sure.

dahankzter avatar Mar 10 '20 13:03 dahankzter

Yeah in my case it is not an issue with concurrent access. It does sound like the page state is simply not reset. Maybe fixing that would be quicker/easier than moving where the page state is stored?

dankinder avatar Mar 10 '20 14:03 dankinder

Related to #1508, #1511 and #1447

martin-sucha avatar Dec 03 '20 21:12 martin-sucha