private PreparedStatement loadDataAndPrepareQuery(int timeoutMs, int timeoutSecs) throws Exception, SQLException { Properties props = new Properties(); props.setProperty(QueryServices.THREAD_TIMEOUT_MS_ATTRIB, String.valueOf(timeoutMs)); Connection conn = DriverManager.getConnection(getUrl(), props); PreparedStatement ps = conn.prepareStatement("SELECT * FROM " + tableName); PhoenixStatement phoenixStmt = ps.unwrap(PhoenixStatement.class); assertEquals(timeoutMs, phoenixStmt.getQueryTimeoutInMillis()); assertEquals(timeoutSecs, phoenixStmt.getQueryTimeout()); return ps; } }
@Test public void testZeroCustomQueryTimeout() throws Exception { // Arrange Properties connectionProperties = new Properties(); connectionProperties.setProperty("phoenix.query.timeoutMs", "0"); Connection connection = DriverManager.getConnection(getUrl(), connectionProperties); PreparedStatement stmt = connection.prepareStatement("SELECT * FROM " + ATABLE); PhoenixStatement phoenixStmt = stmt.unwrap(PhoenixStatement.class); // Assert assertEquals(0, stmt.getQueryTimeout()); assertEquals(0, phoenixStmt.getQueryTimeoutInMillis()); }
/** * Executes the scan in parallel across all regions, blocking until all scans are complete. * @return the result iterators for the scan of each region */ @Override public List<PeekingResultIterator> getIterators() throws SQLException { if (logger.isDebugEnabled()) { logger.debug(LogUtil.addCustomAnnotations("Getting iterators for " + this, ScanUtil.getCustomAnnotations(scan))); } boolean isReverse = ScanUtil.isReversed(scan); boolean isLocalIndex = getTable().getIndexType() == IndexType.LOCAL; final ConnectionQueryServices services = context.getConnection().getQueryServices(); // Get query time out from Statement final long startTime = EnvironmentEdgeManager.currentTimeMillis(); final long maxQueryEndTime = startTime + context.getStatement().getQueryTimeoutInMillis(); int numScans = size(); // Capture all iterators so that if something goes wrong, we close them all // The iterators list is based on the submission of work, so it may not // contain them all (for example if work was rejected from the queue) Queue<PeekingResultIterator> allIterators = new ConcurrentLinkedQueue<>(); List<PeekingResultIterator> iterators = new ArrayList<PeekingResultIterator>(numScans); ScanWrapper previousScan = new ScanWrapper(null); return getIterators(scans, services, isLocalIndex, allIterators, iterators, isReverse, maxQueryEndTime, splits.size(), previousScan, context.getConnection().getQueryServices().getConfiguration() .getInt(QueryConstants.HASH_JOIN_CACHE_RETRIES, QueryConstants.DEFAULT_HASH_JOIN_CACHE_RETRIES)); }
@Test /** * Validates that setting custom phoenix query timeout using * the phoenix.query.timeoutMs config property is honored. */ public void testCustomQueryTimeout() throws Exception { // Arrange Properties connectionProperties = new Properties(); connectionProperties.setProperty("phoenix.query.timeoutMs", "2350"); Connection connection = DriverManager.getConnection(getUrl(), connectionProperties); PreparedStatement stmt = connection.prepareStatement("SELECT * FROM " + ATABLE); PhoenixStatement phoenixStmt = stmt.unwrap(PhoenixStatement.class); // Assert assertEquals(3, stmt.getQueryTimeout()); assertEquals(2350, phoenixStmt.getQueryTimeoutInMillis()); }
@Test /** * Validates if a user sets the timeout to zero that we store the timeout * in millis as the Integer.MAX_VALUE. */ public void testSettingZeroQueryTimeoutViaJdbc() throws Exception { // Arrange Connection connection = DriverManager.getConnection(getUrl()); PreparedStatement stmt = connection.prepareStatement("SELECT * FROM " + ATABLE); PhoenixStatement phoenixStmt = stmt.unwrap(PhoenixStatement.class); // Act stmt.setQueryTimeout(0); // Assert assertEquals(Integer.MAX_VALUE / 1000, stmt.getQueryTimeout()); assertEquals(Integer.MAX_VALUE, phoenixStmt.getQueryTimeoutInMillis()); }
@Test /** * Validates that if a user sets the query timeout via the * stmt.setQueryTimeout() JDBC method, we correctly store the timeout * in both milliseconds and seconds. */ public void testSettingQueryTimeoutViaJdbc() throws Exception { // Arrange Connection connection = DriverManager.getConnection(getUrl()); PreparedStatement stmt = connection.prepareStatement("SELECT * FROM " + ATABLE); PhoenixStatement phoenixStmt = stmt.unwrap(PhoenixStatement.class); // Act stmt.setQueryTimeout(3); // Assert assertEquals(3, stmt.getQueryTimeout()); assertEquals(3000, phoenixStmt.getQueryTimeoutInMillis()); }
@Test /** * Validates that is negative value is supplied we set the timeout to the default. */ public void testSettingNegativeQueryTimeoutViaJdbc() throws Exception { // Arrange Connection connection = DriverManager.getConnection(getUrl()); PreparedStatement stmt = connection.prepareStatement("SELECT * FROM " + ATABLE); PhoenixStatement phoenixStmt = stmt.unwrap(PhoenixStatement.class); PhoenixConnection phoenixConnection = connection.unwrap(PhoenixConnection.class); int defaultQueryTimeout = phoenixConnection.getQueryServices().getProps().getInt(QueryServices.THREAD_TIMEOUT_MS_ATTRIB, QueryServicesOptions.DEFAULT_THREAD_TIMEOUT_MS); // Act stmt.setQueryTimeout(-1); // Assert assertEquals(defaultQueryTimeout / 1000, stmt.getQueryTimeout()); assertEquals(defaultQueryTimeout, phoenixStmt.getQueryTimeoutInMillis()); }
SQLException toThrow = null; final HashCacheClient hashCacheClient = new HashCacheClient(context.getConnection()); int queryTimeOut = context.getStatement().getQueryTimeoutInMillis(); try { submitWork(scan, futures, allIterators, splitSize, isReverse, scanGrouper);
/** * Executes the scan in parallel across all regions, blocking until all scans are complete. * @return the result iterators for the scan of each region */ @Override public List<PeekingResultIterator> getIterators() throws SQLException { if (logger.isDebugEnabled()) { logger.debug(LogUtil.addCustomAnnotations("Getting iterators for " + this, ScanUtil.getCustomAnnotations(scan))); } boolean isReverse = ScanUtil.isReversed(scan); boolean isLocalIndex = getTable().getIndexType() == IndexType.LOCAL; final ConnectionQueryServices services = context.getConnection().getQueryServices(); // Get query time out from Statement final long startTime = EnvironmentEdgeManager.currentTimeMillis(); final long maxQueryEndTime = startTime + context.getStatement().getQueryTimeoutInMillis(); int numScans = size(); // Capture all iterators so that if something goes wrong, we close them all // The iterators list is based on the submission of work, so it may not // contain them all (for example if work was rejected from the queue) Queue<PeekingResultIterator> allIterators = new ConcurrentLinkedQueue<>(); List<PeekingResultIterator> iterators = new ArrayList<PeekingResultIterator>(numScans); ScanWrapper previousScan = new ScanWrapper(null); return getIterators(scans, services, isLocalIndex, allIterators, iterators, isReverse, maxQueryEndTime, splits.size(), previousScan, context.getConnection().getQueryServices().getConfiguration() .getInt(QueryConstants.HASH_JOIN_CACHE_RETRIES, QueryConstants.DEFAULT_HASH_JOIN_CACHE_RETRIES)); }
/** * Executes the scan in parallel across all regions, blocking until all scans are complete. * @return the result iterators for the scan of each region */ @Override public List<PeekingResultIterator> getIterators() throws SQLException { if (logger.isDebugEnabled()) { logger.debug(LogUtil.addCustomAnnotations("Getting iterators for " + this, ScanUtil.getCustomAnnotations(scan))); } boolean isReverse = ScanUtil.isReversed(scan); boolean isLocalIndex = getTable().getIndexType() == IndexType.LOCAL; final ConnectionQueryServices services = context.getConnection().getQueryServices(); // Get query time out from Statement final long startTime = EnvironmentEdgeManager.currentTimeMillis(); final long maxQueryEndTime = startTime + context.getStatement().getQueryTimeoutInMillis(); int numScans = size(); // Capture all iterators so that if something goes wrong, we close them all // The iterators list is based on the submission of work, so it may not // contain them all (for example if work was rejected from the queue) Queue<PeekingResultIterator> allIterators = new ConcurrentLinkedQueue<>(); List<PeekingResultIterator> iterators = new ArrayList<PeekingResultIterator>(numScans); ScanWrapper previousScan = new ScanWrapper(null); return getIterators(scans, services, isLocalIndex, allIterators, iterators, isReverse, maxQueryEndTime, splits.size(), previousScan, context.getConnection().getQueryServices().getConfiguration() .getInt(QueryConstants.HASH_JOIN_CACHE_RETRIES, QueryConstants.DEFAULT_HASH_JOIN_CACHE_RETRIES)); }
SQLException toThrow = null; final HashCacheClient hashCacheClient = new HashCacheClient(context.getConnection()); int queryTimeOut = context.getStatement().getQueryTimeoutInMillis(); try { submitWork(scan, futures, allIterators, splitSize, isReverse, scanGrouper);
SQLException toThrow = null; final HashCacheClient hashCacheClient = new HashCacheClient(context.getConnection()); int queryTimeOut = context.getStatement().getQueryTimeoutInMillis(); try { submitWork(scan, futures, allIterators, splitSize, isReverse, scanGrouper);