Skip to content

Commit

Permalink
[7.17] SQL: swap JDBC page.timeout and query.timeout properties in qu…
Browse files Browse the repository at this point in the history
…ery requests (#79491) (#81878)

* SQL: swap JDBC page.timeout and query.timeout properties in query requests (#79491)

* SQL: swap JDBC page.timeout and query.timeout properties in query requests

resolves #79430

* rm reference to #79480 from spec
# Conflicts:
#	x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcHttpClient.java
#	x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfigurationDataSourceTests.java

* fix backport

* fix formatting
  • Loading branch information
Lukas Wegmann committed Dec 20, 2021
1 parent a1b144d commit 7ffc68c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Cursor query(String sql, List<SqlTypedParamValue> params, RequestMeta meta) thro
conCfg.zoneId(),
jdbcConn.getCatalog(),
fetch,
TimeValue.timeValueMillis(meta.timeoutInMs()),
TimeValue.timeValueMillis(meta.queryTimeoutInMs()),
TimeValue.timeValueMillis(meta.pageTimeoutInMs()),
null,
Boolean.FALSE,
null,
Expand All @@ -88,8 +88,8 @@ Cursor query(String sql, List<SqlTypedParamValue> params, RequestMeta meta) thro
Tuple<String, List<List<Object>>> nextPage(String cursor, RequestMeta meta) throws SQLException {
SqlQueryRequest sqlRequest = new SqlQueryRequest(
cursor,
TimeValue.timeValueMillis(meta.timeoutInMs()),
TimeValue.timeValueMillis(meta.queryTimeoutInMs()),
TimeValue.timeValueMillis(meta.pageTimeoutInMs()),
new RequestInfo(Mode.JDBC),
conCfg.binaryCommunication()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
class RequestMeta {

private int fetchSize;
private long timeoutInMs;
private long pageTimeoutInMs;
private long queryTimeoutInMs;

RequestMeta(int fetchSize, long timeout, long queryTimeoutInMs) {
RequestMeta(int fetchSize, long pageTimeoutInMs, long queryTimeoutInMs) {
this.fetchSize = fetchSize;
this.timeoutInMs = timeout;
this.pageTimeoutInMs = pageTimeoutInMs;
this.queryTimeoutInMs = queryTimeoutInMs;
}

Expand All @@ -23,8 +23,8 @@ RequestMeta queryTimeout(long timeout) {
return this;
}

RequestMeta timeout(long timeout) {
this.timeoutInMs = timeout;
RequestMeta pageTimeout(long timeout) {
this.pageTimeoutInMs = timeout;
return this;
}

Expand All @@ -37,8 +37,8 @@ int fetchSize() {
return fetchSize;
}

long timeoutInMs() {
return timeoutInMs;
long pageTimeoutInMs() {
return pageTimeoutInMs;
}

long queryTimeoutInMs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
package org.elasticsearch.xpack.sql.jdbc;

import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.test.http.MockRequest;
import org.elasticsearch.test.http.MockResponse;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonXContent;

import java.io.IOException;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -46,4 +50,37 @@ public void testDataSourceConfigurationWithSSLInURL() throws SQLException, URISy
assertEquals(address, connection.getURL());
JdbcConfigurationTests.assertSslConfig(allProps, connection.cfg.sslConfig());
}

public void testTimeoutsInUrl() throws IOException, SQLException {
int queryTimeout = 10;
int pageTimeout = 20;

webServer().enqueue(
new MockResponse().setResponseCode(200)
.addHeader("Content-Type", "application/json")
.setBody(XContentHelper.toXContent(createCurrentVersionMainResponse(), XContentType.JSON, false).utf8ToString())
);

EsDataSource dataSource = new EsDataSource();
String address = "jdbc:es://"
+ webServerAddress()
+ "/?binary.format=false&query.timeout="
+ queryTimeout
+ "&page.timeout="
+ pageTimeout;
dataSource.setUrl(address);
Connection connection = dataSource.getConnection();
webServer().takeRequest();

webServer().enqueue(
new MockResponse().setResponseCode(200).addHeader("Content-Type", "application/json").setBody("{\"rows\":[],\"columns\":[]}")
);
PreparedStatement statement = connection.prepareStatement("SELECT 1");
statement.execute();
MockRequest request = webServer().takeRequest();

Map<String, Object> sqlQueryRequest = XContentHelper.convertToMap(JsonXContent.jsonXContent, request.getBody(), false);
assertEquals(queryTimeout + "ms", sqlQueryRequest.get("request_timeout"));
assertEquals(pageTimeout + "ms", sqlQueryRequest.get("page_timeout"));
}
}

0 comments on commit 7ffc68c

Please sign in to comment.