Skip to content

Commit a355ecc

Browse files
authored
Allow retrying a timed-out query if it does not do writes
The current query driver logic disables retrying a query request if it gets a non-retryable error. But a TimeoutException (or RequestTimeoutException) should allow a retry if the query does not do writes. This change fixes this specific case. Retries will be allowed only if the query already is prepared and the prepare statement does not do writes.
1 parent 6548c90 commit a355ecc

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
The format is based on [Keep a Changelog](http://keepachangelog.com/).
44

5+
## [Unreleased]
6+
7+
### Changed
8+
- Allow application to retry a QueryRequest if it gets a timeout exception and the query only does reads
9+
510
## [5.3.6] 2022-08-23
611

712
### Added

driver/src/main/java/oracle/nosql/driver/query/QueryDriver.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
package oracle.nosql.driver.query;
99

1010
import java.util.ArrayList;
11+
import java.util.concurrent.TimeoutException;
1112

1213
import oracle.nosql.driver.NoSQLException;
14+
import oracle.nosql.driver.RequestTimeoutException;
1315
import oracle.nosql.driver.RetryableException;
1416
import oracle.nosql.driver.http.Client;
1517
import oracle.nosql.driver.ops.PreparedStatement;
@@ -178,7 +180,7 @@ public void compute(QueryResult result) {
178180
* If it's not a retryable exception, save it so that we throw it
179181
* again if the app resubmits the QueryRequest.
180182
*/
181-
if (!(e instanceof RetryableException)) {
183+
if (!isRetryableException(e)) {
182184
theError = new NoSQLException(
183185
"QueryRequest cannot be continued after throwing a " +
184186
"non-retryable exception in a previous execution. " +
@@ -208,6 +210,23 @@ public void compute(QueryResult result) {
208210
theRequest.setContKey(theContinuationKey);
209211
}
210212

213+
private boolean isRetryableException(Throwable e) {
214+
if (e instanceof RetryableException) {
215+
return true;
216+
}
217+
/*
218+
* if we got a timeout, and the query does not do writes, allow
219+
* retrying
220+
*/
221+
if (((e instanceof TimeoutException) ||
222+
(e instanceof RequestTimeoutException)) &&
223+
theRequest != null && theRequest.getPreparedStatement() != null &&
224+
theRequest.getPreparedStatement().doesWrites() == false) {
225+
return true;
226+
}
227+
return false;
228+
}
229+
211230
private void setQueryResult(QueryResult result) {
212231

213232
result.setResults(theResults);

0 commit comments

Comments
 (0)