use of com.datastax.driver.core.PagingState in project emodb by bazaarvoice.
the class AdaptiveResultSet method reduceFetchSize.
/**
* Reduces the fetch size and retries the query. Returns true if the query succeeded, false if the root cause
* of the exception does not indicate a frame size issue, if the frame size cannot be adjusted down any further,
* or if the retried query fails for an unrelated reason.
*/
private boolean reduceFetchSize(Throwable reason) {
if (!isAdaptiveException(reason) || --_remainingAdaptations == 0) {
return false;
}
ExecutionInfo executionInfo = _delegate.getExecutionInfo();
Statement statement = executionInfo.getStatement();
PagingState pagingState = executionInfo.getPagingState();
int fetchSize = statement.getFetchSize();
while (fetchSize > MIN_FETCH_SIZE) {
fetchSize = Math.max(fetchSize / 2, MIN_FETCH_SIZE);
_log.debug("Retrying query at next page with fetch size {} due to {}", fetchSize, reason.getMessage());
statement.setFetchSize(fetchSize);
statement.setPagingState(pagingState);
try {
_delegate = _session.execute(statement);
return true;
} catch (Throwable t) {
// Exit the adaptation loop if the exception isn't one where adapting further may help
if (!isAdaptiveException(t) || --_remainingAdaptations == 0) {
return false;
}
}
}
return false;
}
use of com.datastax.driver.core.PagingState in project incubator-hugegraph by apache.
the class CassandraEntryIterator method pageState.
@Override
protected PageState pageState() {
byte[] position;
int offset = 0;
int count = (int) this.count();
assert this.fetched() == count;
int extra = this.availableLocal();
List<ExecutionInfo> infos = this.results.getAllExecutionInfo();
if (extra > 0 && infos.size() >= 2) {
/*
* Go back to the previous page if there are still available
* results fetched to local memory but not consumed, and set page
* offset with consumed amount of results.
*
* Safely, we should get the remaining size of the current page by:
* `Whitebox.getInternalState(results, "currentPage").size()`
* instead of
* `results.getAvailableWithoutFetching()`
*/
ExecutionInfo previous = infos.get(infos.size() - 2);
PagingState page = previous.getPagingState();
position = page.toBytes();
offset = this.fetchdPageSize - extra;
} else {
PagingState page = this.results.getExecutionInfo().getPagingState();
if (page == null || this.expected > 0L) {
// Call isExhausted() will lead to try to fetch the next page
E.checkState(this.results.isExhausted(), "Unexpected paging state with expected=%s, " + "ensure consume all the fetched results before " + "calling pageState()", this.expected);
position = PageState.EMPTY_BYTES;
} else {
/*
* Exist page position which used to fetch the next page.
* Maybe it happens to the last page (that's the position is
* at the end of results and next page is empty)
*/
position = page.toBytes();
}
}
return new PageState(position, offset, count);
}
Aggregations