Netflix/astyanax — pull request #35 by iconara (2012-04-09 16:08:54+00:00)
Title: Reversed iteration causes an infinite loop

When iterating over the columns in a row in reverse the query goes into an infinite loop, repeating the last column (that is, the first column of the row) over and over again. It also repeats the columns at page boundaries.

This patch contains a test that demonstrates the issue (it never exits), and a fix. I'm not sure if you should actually merge in the fix though, it's a bit of a hack. I'm not sure how to correctly juggle state in the triple-nested anonymous inner classes of `ThriftColumnFamilyQueryImpl`, and I think it's possible to write a more elegant solution.

My hackish fix checks if the current page starts with the same column as the previous ended with, and if so signals that no more pages should be loaded, and returns an empty page. If also removes duplicated elements caused by the last column of the previous page being the first column of the current (because it is used as the offset). This means that when doing a reverse iteration the page size is one smaller.

Iterating forward in a row is easy, reverse iteration is not. Doing it correctly requires loading two extra columns for each page so that you know when you've loaded the last page, and you get the correct page size even though the last column of the previous page will be included in the next page
(I wrote a blog post about it a while back: http://architecturalatrocities.com/post/13918146722/implementing-column-pagination-in-cassandra). I'd love to give you a patch that did this, but I'm not familiar enough with the code that I feel I can do that, and there's not any tests to see that I'm not breaking anything in the process.