diff --git a/docs/src/main/sphinx/connector/phoenix.md b/docs/src/main/sphinx/connector/phoenix.md index 7efdbe2e98c1..38c8e2c5c9ab 100644 --- a/docs/src/main/sphinx/connector/phoenix.md +++ b/docs/src/main/sphinx/connector/phoenix.md @@ -45,11 +45,12 @@ to load custom Phoenix client connection properties. The following Phoenix-specific configuration properties are available: -| Property name | Required | Description | -| ----------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `phoenix.connection-url` | Yes | `jdbc:phoenix[:zk_quorum][:zk_port][:zk_hbase_path]`. The `zk_quorum` is a comma separated list of ZooKeeper servers. The `zk_port` is the ZooKeeper port. The `zk_hbase_path` is the HBase root znode path, that is configurable using `hbase-site.xml`. By default the location is `/hbase` | -| `phoenix.config.resources` | No | Comma-separated list of configuration files (e.g. `hbase-site.xml`) to use for connection properties. These files must exist on the machines running Trino. | -| `phoenix.max-scans-per-split` | No | Maximum number of HBase scans that will be performed in a single split. Default is 20. Lower values will lead to more splits in Trino. Can also be set via session propery `max_scans_per_split`. For details see: [https://phoenix.apache.org/update_statistics.html](https://phoenix.apache.org/update_statistics.html). (This setting has no effect when guideposts are disabled in Phoenix.) | +| Property name | Required | Description | +|------------------------------------| -------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `phoenix.connection-url` | Yes | `jdbc:phoenix[:zk_quorum][:zk_port][:zk_hbase_path]`. The `zk_quorum` is a comma separated list of ZooKeeper servers. The `zk_port` is the ZooKeeper port. The `zk_hbase_path` is the HBase root znode path, that is configurable using `hbase-site.xml`. By default the location is `/hbase` | +| `phoenix.config.resources` | No | Comma-separated list of configuration files (e.g. `hbase-site.xml`) to use for connection properties. These files must exist on the machines running Trino. | +| `phoenix.max-scans-per-split` | No | Maximum number of HBase scans that will be performed in a single split. Default is 20. Lower values will lead to more splits in Trino. Can also be set via session propery `max_scans_per_split`. For details see: [https://phoenix.apache.org/update_statistics.html](https://phoenix.apache.org/update_statistics.html). (This setting has no effect when guideposts are disabled in Phoenix.) | +| `phoenix.server-scan-page-timeout` | No | The time limit on the amount of work single RPC request can do before it times out. Type: [](prop-type-duration). | ```{include} jdbc-common-configurations.fragment ``` diff --git a/plugin/trino-phoenix5/pom.xml b/plugin/trino-phoenix5/pom.xml index dd25843aed77..053e53989d36 100644 --- a/plugin/trino-phoenix5/pom.xml +++ b/plugin/trino-phoenix5/pom.xml @@ -53,6 +53,11 @@ log + + io.airlift + units + + io.trino trino-base-jdbc diff --git a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClientModule.java b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClientModule.java index b0b7d03deaed..a7d5a784b867 100644 --- a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClientModule.java +++ b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClientModule.java @@ -90,6 +90,7 @@ import static io.trino.plugin.phoenix5.PhoenixClient.DEFAULT_DOMAIN_COMPACTION_THRESHOLD; import static io.trino.plugin.phoenix5.PhoenixErrorCode.PHOENIX_CONFIG_ERROR; import static java.util.Objects.requireNonNull; +import static org.apache.phoenix.query.QueryServices.PHOENIX_SERVER_PAGE_SIZE_MS; import static org.apache.phoenix.util.ReadOnlyProps.EMPTY_PROPS; import static org.weakref.jmx.guice.ExportBinder.newExporter; @@ -209,6 +210,7 @@ public static Properties getConnectionProperties(PhoenixConfig config) ConnectionInfo connectionInfo = ConnectionInfo.create(config.getConnectionUrl(), EMPTY_PROPS, new Properties()); connectionInfo.asProps().asMap().forEach(connectionProperties::setProperty); + config.getServerScanPageTimeout().ifPresent(duration -> connectionProperties.setProperty(PHOENIX_SERVER_PAGE_SIZE_MS, String.valueOf(duration.toMillis()))); return connectionProperties; } diff --git a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixConfig.java b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixConfig.java index 3dbb8b1d3e89..75c9f59764c7 100644 --- a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixConfig.java +++ b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixConfig.java @@ -17,11 +17,13 @@ import io.airlift.configuration.Config; import io.airlift.configuration.ConfigDescription; import io.airlift.configuration.validation.FileExists; +import io.airlift.units.Duration; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import java.util.List; +import java.util.Optional; public class PhoenixConfig { @@ -41,6 +43,11 @@ public class PhoenixConfig private int maxScansPerSplit = 20; private boolean reuseConnection = true; + /** + * By default, let Phoenix client derive Page size from HBase RPC timeout configs. + */ + private Optional serverScanPageTimeout = Optional.empty(); + @NotNull public String getConnectionUrl() { @@ -94,4 +101,17 @@ public PhoenixConfig setReuseConnection(boolean reuseConnection) this.reuseConnection = reuseConnection; return this; } + + public Optional getServerScanPageTimeout() + { + return serverScanPageTimeout; + } + + @Config("phoenix.server-scan-page-timeout") + @ConfigDescription("Phoenix scan page timeout to reflect the time limit on the amount of work single Scan RPC request can do") + public PhoenixConfig setServerScanPageTimeout(Duration serverScanPageTimeout) + { + this.serverScanPageTimeout = Optional.ofNullable(serverScanPageTimeout); + return this; + } } diff --git a/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConfig.java b/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConfig.java index d32fec958cd4..284aaeedf674 100644 --- a/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConfig.java +++ b/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConfig.java @@ -21,10 +21,12 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; +import java.util.concurrent.TimeUnit; import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping; import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults; +import static io.airlift.units.Duration.succinctDuration; public class TestPhoenixConfig { @@ -35,7 +37,8 @@ public void testDefaults() .setConnectionUrl(null) .setResourceConfigFiles(ImmutableList.of()) .setMaxScansPerSplit(20) - .setReuseConnection(true)); + .setReuseConnection(true) + .setServerScanPageTimeout(null)); } @Test @@ -49,12 +52,14 @@ public void testExplicitPropertyMappings() .put("phoenix.config.resources", configFile.toString()) .put("phoenix.max-scans-per-split", "1") .put("query.reuse-connection", "false") + .put("phoenix.server-scan-page-timeout", "11h") .buildOrThrow(); PhoenixConfig expected = new PhoenixConfig() .setConnectionUrl("jdbc:phoenix:localhost:2181:/hbase") .setResourceConfigFiles(ImmutableList.of(configFile.toString())) .setMaxScansPerSplit(1) + .setServerScanPageTimeout(succinctDuration(11, TimeUnit.HOURS)) .setReuseConnection(false); assertFullMapping(properties, expected);