gocql
gocql copied to clipboard
Dont mutate query/batch when executing queries
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 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
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.
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.
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?
Related to #1508, #1511 and #1447