Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cassandra: check isFullyFetched before completion #1935

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,22 @@ import scala.util.{Failure, Success, Try}
}(exec)
}

private[this] def fetch(rs: ResultSet): Unit = {
isFetching = true
// fetch next page
val gFut = rs.fetchMoreResults()
val exec = materializer.executionContext
GuavaFutures.invokeTryCallback(gFut, exec)(futFetchedCallback)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be using an async call back?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks OK to me, it is only called within synchronous code.
tryPushAfterFetch is called via the async handler futFetchedCallback when the future returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just refactored it out into a method to not duplicate code.

}

setHandler(
out,
new OutHandler {
override def onPull(): Unit = maybeRs.foreach { rs =>
val currentlyAvailableRows = rs.getAvailableWithoutFetching

if (!isFetching && currentlyAvailableRows < minimumPreFetchSize) {
isFetching = true
// fetch next page
val gFut = rs.fetchMoreResults()
val exec = materializer.executionContext
GuavaFutures.invokeTryCallback(gFut, exec)(futFetchedCallback)
fetch(rs)
}

if (currentlyAvailableRows > 0)
Expand All @@ -69,8 +73,13 @@ import scala.util.{Failure, Success, Try}
if (isAvailable(out)) {
push(out, rs.one())
}
} else {
} else if (rs.isFullyFetched) {
// Only once the rs has no results left can we complete.
completeStage()
} else {
// It can happen that `getAvailableWithoutFetching` is 0, but the result set has more
// rows available. E.g. when fetchSize is relativley small and downstream consumer is fast.
fetch(rs)
}

case Failure(failure) => failStage(failure)
Expand Down