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-736355: [HTAP] Add Retry Context to retried request #633

Merged
merged 15 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/connection/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const DEFAULT_PARAMS =
'validateDefaultParameters',
'arrayBindingThreshold',
'gcsUseDownscopedCredential',
'forceStageBindError'
'forceStageBindError',
'includeRetryReason'
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
];

function consolidateHostAndAccount(options)
Expand Down Expand Up @@ -484,6 +485,13 @@ function ConnectionConfig(options, validateCredentials, qaMode, clientInfo)
}
}

let includeRetryReason = true;
if (Util.exists(options.includeRetryReason)) {
Errors.checkArgumentValid(Util.isBoolean(options.includeRetryReason),
ErrorCodes.ERR_CONN_CREATE_INVALID_INCLUDE_RETRY_REASON);
includeRetryReason = options.includeRetryReason;
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns an object that contains information about the proxy hostname, port,
* etc. for when http requests are made.
Expand Down Expand Up @@ -747,6 +755,16 @@ function ConnectionConfig(options, validateCredentials, qaMode, clientInfo)
return forceStageBindError;
};

/**
* Returns whether the Retry reason is included or not in the retry url
*
* @returns {string}
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
*/

this.getIncludeRetryReason = function () {
return includeRetryReason;
}

// save config options
this.username = options.username;
this.password = options.password;
Expand Down
11 changes: 10 additions & 1 deletion lib/connection/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,7 @@ function sendSfRequest(statementContext, options, appendQueryParamOnRetry)
var numRetries = 0;
var maxNumRetries = connectionConfig.getRetrySfMaxNumRetries();
var sleep = connectionConfig.getRetrySfStartingSleepTime();
let lastStatusCodeForRetry;

// create a function to send the request
var sendRequest = function ()
Expand All @@ -1570,7 +1571,14 @@ function sendSfRequest(statementContext, options, appendQueryParamOnRetry)
// retry, update the url
if ((numRetries > 0) && appendQueryParamOnRetry)
{
options.url = Util.url.appendParam(urlOrig, 'retry', true);
const retryOption = {
url: urlOrig,
retryCount: numRetries,
retryReason: lastStatusCodeForRetry,
includeRetryContext: connectionConfig.getIncludeRetryContext()
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
}

options.url = Util.url.appendRetryParam(retryOption);
}

sf.request(options);
Expand All @@ -1588,6 +1596,7 @@ function sendSfRequest(statementContext, options, appendQueryParamOnRetry)
{
// increment the retry count
numRetries++;
lastStatusCodeForRetry = err.response ? err.response.statusCode : 0

// use exponential backoff with decorrelated jitter to compute the
// next sleep time.
Expand Down
1 change: 1 addition & 0 deletions lib/constants/error_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ exports[404037] = 'Invalid arrayBindingThreshold. The specified value must be a
exports[404038] = 'Invalid gcsUseDownscopedCredential. The specified value must be a boolean.';
exports[404039] = 'Invalid forceStageBindError. The specified value must be a number.';
exports[404040] = 'Invalid browser timeout value. The specified value must be a positive number.';
exports[404042] = 'Invalid include retry reason. The specified value must be a boolean.'

// 405001
exports[405001] = 'Invalid callback. The specified value must be a function.';
Expand Down
1 change: 1 addition & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ codes.ERR_CONN_CREATE_INVALID_ARRAY_BINDING_THRESHOLD = 404037;
codes.ERR_CONN_CREATE_INVALID_GCS_USE_DOWNSCOPED_CREDENTIAL = 404038;
codes.ERR_CONN_CREATE_INVALID_FORCE_STAGE_BIND_ERROR = 404039;
codes.ERR_CONN_CREATE_INVALID_BROWSER_TIMEOUT = 404040;
codes.ERR_CONN_CREATE_INVALID_INCLUDE_RETRY_REASON =404042
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved

// 405001
codes.ERR_CONN_CONNECT_INVALID_CALLBACK = 405001;
Expand Down
8 changes: 8 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ exports.url =
}

return url;
},

appendRetryParam: function (option) {
let retryUrl = this.appendParam(option.url, 'retryCount', option.retryCount);
if (option.includeRetryContext) {
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
retryUrl = this.appendParam(retryUrl, 'retryReason', option.retryReason);
}
return retryUrl;
}
};

Expand Down
11 changes: 11 additions & 0 deletions test/unit/connection/connection_config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,17 @@ describe('ConnectionConfig: basic', function ()
},
errorCode: ErrorCodes.ERR_CONN_CREATE_INVALID_GCS_USE_DOWNSCOPED_CREDENTIAL
},
{
name: 'invalid includeRetryReason',
options:
{
username: 'username',
password: 'password',
account: 'account',
includeRetryReason: 'invalid'
},
errorCode: ErrorCodes.ERR_CONN_CREATE_INVALID_INCLUDE_RETRY_REASON
},
];

var createNegativeITCallback = function (testCase)
Expand Down
31 changes: 31 additions & 0 deletions test/unit/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,37 @@ describe('Util', function ()
}
});

it('Util.url.appendRetryParam()', function () {
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
let url;
const testCases =
[
{
option: {
url: 'http://www.something.snowflakecomputing.com',
retryCount: 3,
retryReason: 429,
includeRetryContext: true,
},
result: 'http://www.something.snowflakecomputing.com?retryCount=3&retryReason=429'
},
{
option: {
url: 'http://www.something.snowflakecomputing.com',
retryCount: 3,
retryReason: 429,
includeRetryContext: false,
},
result: 'http://www.something.snowflakecomputing.com?retryCount=3'
}
];

for (let i = 0; i < testCases.length; i++) {
testCase = testCases[i];
url = Util.url.appendRetryParam(testCase.option);
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
assert.strictEqual(url, testCase.result);
}
})

it('Util.apply()', function ()
{
assert.strictEqual(Util.apply(null, null), null);
Expand Down