28
28
import javax .net .ssl .TrustManager ;
29
29
import net .snowflake .client .jdbc .ErrorCode ;
30
30
import net .snowflake .client .jdbc .RestRequest ;
31
+ import net .snowflake .client .jdbc .RetryContextManager ;
31
32
import net .snowflake .client .jdbc .SnowflakeDriver ;
32
33
import net .snowflake .client .jdbc .SnowflakeSQLException ;
33
34
import net .snowflake .client .jdbc .SnowflakeUtil ;
@@ -582,7 +583,8 @@ public static boolean isSocksProxyDisabled() {
582
583
* @param retryTimeout retry timeout
583
584
* @param authTimeout authenticator specific timeout
584
585
* @param socketTimeout socket timeout (in ms)
585
- * @param retryCount retry count for the request
586
+ * @param retryCount max retry count for the request - if it is set to 0, it will be ignored and
587
+ * only retryTimeout will determine when to end the retries
586
588
* @param injectSocketTimeout injecting socket timeout
587
589
* @param canceling canceling?
588
590
* @param ocspAndProxyKey OCSP mode and proxy settings for httpclient
@@ -614,7 +616,8 @@ static String executeRequestWithoutCookies(
614
616
true , // guid? (do we need this?)
615
617
false , // no retry on HTTP 403
616
618
getHttpClient (ocspAndProxyKey ),
617
- new ExecTimeTelemetryData ());
619
+ new ExecTimeTelemetryData (),
620
+ null );
618
621
}
619
622
620
623
/**
@@ -624,7 +627,8 @@ static String executeRequestWithoutCookies(
624
627
* @param retryTimeout retry timeout
625
628
* @param authTimeout authenticator specific timeout
626
629
* @param socketTimeout socket timeout (in ms)
627
- * @param retryCount retry count for the request
630
+ * @param retryCount max retry count for the request - if it is set to 0, it will be ignored and
631
+ * only retryTimeout will determine when to end the retries
628
632
* @param ocspAndProxyAndGzipKey OCSP mode and proxy settings for httpclient
629
633
* @return response
630
634
* @throws SnowflakeSQLException if Snowflake error occurs
@@ -638,6 +642,41 @@ public static String executeGeneralRequest(
638
642
int retryCount ,
639
643
HttpClientSettingsKey ocspAndProxyAndGzipKey )
640
644
throws SnowflakeSQLException , IOException {
645
+ return executeGeneralRequest (
646
+ httpRequest ,
647
+ retryTimeout ,
648
+ authTimeout ,
649
+ socketTimeout ,
650
+ retryCount ,
651
+ ocspAndProxyAndGzipKey ,
652
+ null );
653
+ }
654
+
655
+ /**
656
+ * Executes an HTTP request for Snowflake.
657
+ *
658
+ * @param httpRequest HttpRequestBase
659
+ * @param retryTimeout retry timeout
660
+ * @param authTimeout authenticator specific timeout
661
+ * @param socketTimeout socket timeout (in ms)
662
+ * @param retryCount max retry count for the request - if it is set to 0, it will be ignored and
663
+ * only retryTimeout will determine when to end the retries
664
+ * @param ocspAndProxyAndGzipKey OCSP mode and proxy settings for httpclient
665
+ * @param retryContextManager RetryContext used to customize retry handling functionality
666
+ * @return response
667
+ * @throws SnowflakeSQLException if Snowflake error occurs
668
+ * @throws IOException raises if a general IO error occurs
669
+ */
670
+ @ SnowflakeJdbcInternalApi
671
+ public static String executeGeneralRequest (
672
+ HttpRequestBase httpRequest ,
673
+ int retryTimeout ,
674
+ int authTimeout ,
675
+ int socketTimeout ,
676
+ int retryCount ,
677
+ HttpClientSettingsKey ocspAndProxyAndGzipKey ,
678
+ RetryContextManager retryContextManager )
679
+ throws SnowflakeSQLException , IOException {
641
680
logger .debug ("Executing general request" );
642
681
return executeRequest (
643
682
httpRequest ,
@@ -650,7 +689,8 @@ public static String executeGeneralRequest(
650
689
false , // no retry parameter
651
690
false , // no retry on HTTP 403
652
691
ocspAndProxyAndGzipKey ,
653
- new ExecTimeTelemetryData ());
692
+ new ExecTimeTelemetryData (),
693
+ retryContextManager );
654
694
}
655
695
656
696
/**
@@ -660,7 +700,8 @@ public static String executeGeneralRequest(
660
700
* @param retryTimeout retry timeout
661
701
* @param authTimeout authenticator specific timeout
662
702
* @param socketTimeout socket timeout (in ms)
663
- * @param retryCount retry count for the request
703
+ * @param retryCount max retry count for the request - if it is set to 0, it will be ignored and
704
+ * only retryTimeout will determine when to end the retries
664
705
* @param httpClient client object used to communicate with other machine
665
706
* @return response
666
707
* @throws SnowflakeSQLException if Snowflake error occurs
@@ -688,7 +729,8 @@ public static String executeGeneralRequest(
688
729
true , // include request GUID
689
730
false , // no retry on HTTP 403
690
731
httpClient ,
691
- new ExecTimeTelemetryData ());
732
+ new ExecTimeTelemetryData (),
733
+ null );
692
734
}
693
735
694
736
/**
@@ -722,6 +764,54 @@ public static String executeRequest(
722
764
HttpClientSettingsKey ocspAndProxyKey ,
723
765
ExecTimeTelemetryData execTimeData )
724
766
throws SnowflakeSQLException , IOException {
767
+ return executeRequest (
768
+ httpRequest ,
769
+ retryTimeout ,
770
+ authTimeout ,
771
+ socketTimeout ,
772
+ maxRetries ,
773
+ injectSocketTimeout ,
774
+ canceling ,
775
+ includeRetryParameters ,
776
+ retryOnHTTP403 ,
777
+ ocspAndProxyKey ,
778
+ execTimeData ,
779
+ null );
780
+ }
781
+
782
+ /**
783
+ * Executes an HTTP request for Snowflake.
784
+ *
785
+ * @param httpRequest HttpRequestBase
786
+ * @param retryTimeout retry timeout
787
+ * @param authTimeout authenticator timeout
788
+ * @param socketTimeout socket timeout (in ms)
789
+ * @param maxRetries retry count for the request
790
+ * @param injectSocketTimeout injecting socket timeout
791
+ * @param canceling canceling?
792
+ * @param includeRetryParameters whether to include retry parameters in retried requests
793
+ * @param retryOnHTTP403 whether to retry on HTTP 403 or not
794
+ * @param ocspAndProxyKey OCSP mode and proxy settings for httpclient
795
+ * @param execTimeData query execution time telemetry data object
796
+ * @param retryContextManager RetryContext used to customize retry handling functionality
797
+ * @return response
798
+ * @throws SnowflakeSQLException if Snowflake error occurs
799
+ * @throws IOException raises if a general IO error occurs
800
+ */
801
+ public static String executeRequest (
802
+ HttpRequestBase httpRequest ,
803
+ int retryTimeout ,
804
+ int authTimeout ,
805
+ int socketTimeout ,
806
+ int maxRetries ,
807
+ int injectSocketTimeout ,
808
+ AtomicBoolean canceling ,
809
+ boolean includeRetryParameters ,
810
+ boolean retryOnHTTP403 ,
811
+ HttpClientSettingsKey ocspAndProxyKey ,
812
+ ExecTimeTelemetryData execTimeData ,
813
+ RetryContextManager retryContextManager )
814
+ throws SnowflakeSQLException , IOException {
725
815
boolean ocspEnabled = !(ocspAndProxyKey .getOcspMode ().equals (OCSPMode .DISABLE_OCSP_CHECKS ));
726
816
logger .debug ("Executing request with OCSP enabled: {}" , ocspEnabled );
727
817
execTimeData .setOCSPStatus (ocspEnabled );
@@ -738,7 +828,8 @@ public static String executeRequest(
738
828
true , // include request GUID
739
829
retryOnHTTP403 ,
740
830
getHttpClient (ocspAndProxyKey ),
741
- execTimeData );
831
+ execTimeData ,
832
+ retryContextManager );
742
833
}
743
834
744
835
/**
@@ -760,6 +851,7 @@ public static String executeRequest(
760
851
* @param includeRequestGuid whether to include request_guid
761
852
* @param retryOnHTTP403 whether to retry on HTTP 403
762
853
* @param httpClient client object used to communicate with other machine
854
+ * @param retryContextManager RetryContext used to customize retry handling functionality
763
855
* @return response in String
764
856
* @throws SnowflakeSQLException if Snowflake error occurs
765
857
* @throws IOException raises if a general IO error occurs
@@ -777,7 +869,8 @@ private static String executeRequestInternal(
777
869
boolean includeRequestGuid ,
778
870
boolean retryOnHTTP403 ,
779
871
CloseableHttpClient httpClient ,
780
- ExecTimeTelemetryData execTimeData )
872
+ ExecTimeTelemetryData execTimeData ,
873
+ RetryContextManager retryContextManager )
781
874
throws SnowflakeSQLException , IOException {
782
875
// HttpRequest.toString() contains request URI. Scrub any credentials, if
783
876
// present, before logging
@@ -811,7 +904,8 @@ private static String executeRequestInternal(
811
904
includeRetryParameters ,
812
905
includeRequestGuid ,
813
906
retryOnHTTP403 ,
814
- execTimeData );
907
+ execTimeData ,
908
+ retryContextManager );
815
909
if (logger .isDebugEnabled () && stopwatch != null ) {
816
910
stopwatch .stop ();
817
911
}
@@ -825,6 +919,7 @@ private static String executeRequestInternal(
825
919
EntityUtils .consume (response .getEntity ());
826
920
}
827
921
922
+ // We throw here exception if timeout was reached for login
828
923
throw new SnowflakeSQLException (
829
924
SqlState .IO_ERROR ,
830
925
ErrorCode .NETWORK_ERROR .getMessageCode (),
0 commit comments