Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snow 1853185 jdbc driver v3.16 native okta http retry storm #2064

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

sfc-gh-fpawlowski
Copy link

@sfc-gh-fpawlowski sfc-gh-fpawlowski commented Feb 5, 2025

Overview

SNOW-1853185

Pre-review self checklist

  • PR branch is updated with all the changes from master branch
  • The code is correctly formatted (run mvn -P check-style validate)
  • New public API is not unnecessary exposed (run mvn verify and inspect target/japicmp/japicmp.html)
  • The pull request name is prefixed with SNOW-XXXX:
  • Code is in compliance with internal logging requirements

External contributors - please answer these questions before submitting a pull request. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Issue: #NNNN

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency or upgrading an existing one
    • I am adding new public/protected component not marked with @SnowflakeJdbcInternalApi (note that public/protected methods/fields in classes marked with this annotation are already internal)
  3. Please describe how your code solves the related issue.

    Please write a short description of how your code change solves the related issue.

@sfc-gh-fpawlowski sfc-gh-fpawlowski self-assigned this Feb 5, 2025
@@ -503,6 +527,9 @@ public static CloseableHttpResponse execute(
requestIdStr,
requestInfoScrubbed,
backoffInMilli);
// TODO: shouldn't we sleep here for backoffInMilli - elapsedMilliForLastCall
// ?
// Thread.sleep(backoffInMilli - elapsedMilliForLastCall);
Thread.sleep(backoffInMilli);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we sleep here for backoffInMilli - elapsedMilliForLastCall?

@sfc-gh-fpawlowski sfc-gh-fpawlowski marked this pull request as ready for review February 10, 2025 01:07
@sfc-gh-fpawlowski sfc-gh-fpawlowski requested a review from a team as a code owner February 10, 2025 01:07
TestOnly/pom.xml Outdated Show resolved Hide resolved
@@ -621,6 +622,24 @@ static String executeRequestWithoutCookies(
new ExecTimeTelemetryData());
}

public static String executeGeneralRequest(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's mark as internal or remove public

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that's possible - it is still used in multiple places - e.g. in SessionUtil.java
(I gave a longer answer in the next comment to why I kept those)

HttpUtil.executeGeneralRequest(
postRequest,
loginInput.getLoginTimeout(),
loginInput.getAuthTimeout(),
loginInput.getSocketTimeoutInMillis(),
0,
loginInput.getHttpClientSettingsKey());

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we can mark some methods with @SnowflakeJdbcInternalApi

*
* @return the retry hook.
*/
public RetryHook getRetryHook() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to extract the hook? cannot the hook be called indirectly via some method on RetryContextManager?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered the RetryHook Enum as a part of the RetryContext 'interface' - we can specify it in constructor, and adjust outer behavior based on its value later (i.e. when to execute the passed retry logic).

We could consider defining subclasses of the RetryContext class - each representing different type of retry behavior (represented originally by the RetryHook enumeration).
It would be also possible to extract the RetryHook-related data with boolean methods (e.g. isAlwaysRetry() ...) - but I don't think this approach has a significant advantages over the original one)

+ vanityUrlCalls.size());
}

// Ensure each consecutive pair of calls has at least 1-second gap (1000 ms).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the one second gap configurable? if so let's make it shorter for tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 1-second gap comes from the minimum length of the backoff during retries in RestRequest. It is not configurable from what I understand.

private static final long minBackoffInMilli = 1000;


// If not found, attempt to read from the classpath (resources directory).
// Has to start from '/' followed by a subdirectory of the resources directory.
try (InputStream in = getClass().getResourceAsStream(filePath)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be simpler?

try (InputStream inputStream =
conn.unwrap(SnowflakeConnectionV1.class)
.downloadStream(stageName, fileName, decompress);
InputStreamReader isr = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(isr)) {
String content = br.lines().collect(Collectors.joining("\n"));

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - reimplemented this way 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants