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-871416: [HTAP] Query Context Caching for Node #631

Merged
merged 36 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6868a2b
Query Context Cache
sfc-gh-ext-simba-jy Sep 6, 2023
050afdf
fixed Parameter for Query Context Cache, and make serializeQueryConte…
sfc-gh-ext-simba-jy Sep 6, 2023
abce2ea
Edited Unit testing for the serializeQueryContext and fix some erros
sfc-gh-ext-simba-jy Sep 6, 2023
feb6e92
Removed Error message for Query Context Cache because it is not a con…
sfc-gh-ext-simba-jy Sep 6, 2023
3e059be
Moved the point of initializing the querycontext cache, and fixed som…
sfc-gh-ext-simba-jy Sep 8, 2023
543acb6
Fixed getQueryContextDTO
sfc-gh-ext-simba-jy Sep 8, 2023
dc5ae8c
fixed mock_http_client.js erro
sfc-gh-ext-simba-jy Sep 8, 2023
a041850
Removed unnecessary lines, and give some spaces between the codes and…
sfc-gh-ext-simba-jy Sep 8, 2023
1180686
Merge branch 'master' into contextcache
sfc-gh-ext-simba-jy Sep 11, 2023
7201a29
removed some dead codes
sfc-gh-ext-simba-jy Sep 12, 2023
376c937
removed a dead code
sfc-gh-ext-simba-jy Sep 12, 2023
bb55f99
Merge branch 'contextcache' of https://github.com/snowflakedb/snowfla…
sfc-gh-ext-simba-jy Sep 12, 2023
d2a1ca3
added connction testing for disableQueryContextCache
sfc-gh-ext-simba-jy Sep 13, 2023
bebcf05
Fixed typos, formats, comments
sfc-gh-ext-simba-jy Sep 14, 2023
2764315
Merge branch 'master' into contextcache
sfc-gh-ext-simba-jy Sep 14, 2023
f17d72e
passed whole QCE objects in the merge function and fixed some testing…
sfc-gh-ext-simba-jy Sep 16, 2023
3222807
Merge branch 'master' into contextcache
sfc-gh-ext-simba-jy Sep 18, 2023
dd9da02
Added integration test
sfc-gh-ext-simba-jy Sep 19, 2023
b827f5c
edited some variable names in the QCC testing
sfc-gh-ext-simba-jy Sep 19, 2023
0268c02
Remove queryContextDTO from requests
sfc-gh-ext-simba-jy Sep 19, 2023
3a619fe
fixed integration tests and removed comments
sfc-gh-ext-simba-jy Sep 19, 2023
d02f273
Removed getLogLevelTag funcrtion
sfc-gh-ext-simba-jy Sep 20, 2023
85540ff
Fixed the network error and reverted back queryContexDTO to the origi…
sfc-gh-ext-simba-jy Sep 21, 2023
42af59c
Removed unnecessary spaces between two classes
sfc-gh-ext-simba-jy Sep 21, 2023
6844666
Merge branch 'master' into contextcache
sfc-gh-ext-simba-jy Sep 21, 2023
a9820a6
increased the testing timeout
sfc-gh-ext-simba-jy Sep 21, 2023
e84eef9
Added logging options for testing
sfc-gh-ext-simba-jy Sep 21, 2023
de7fb4f
reduced the number of testing
sfc-gh-ext-simba-jy Sep 21, 2023
e28fea0
Removed creating DB for testing
sfc-gh-ext-simba-jy Sep 21, 2023
5492ad7
added details logging
sfc-gh-ext-simba-jy Sep 21, 2023
7cc15af
fixed testing issues
sfc-gh-ext-simba-jy Sep 21, 2023
c961bcc
Merge branch 'master' into contextcache
sfc-gh-ext-simba-jy Sep 21, 2023
519e81e
fixed format and added comments for the qcc test
sfc-gh-ext-simba-jy Sep 21, 2023
6f0d356
fixed a format and added DTO on the both places
sfc-gh-ext-simba-jy Sep 22, 2023
9903f0c
added the copy right and reformat the code
sfc-gh-ext-simba-jy Sep 22, 2023
f3c2d40
removed comments and spaces and ran lint fix
sfc-gh-ext-simba-jy Sep 22, 2023
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
28 changes: 27 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',
'disableQueryContextCache'
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)
}
}

var disableQueryContextCache = false;
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
if (Util.exists(options.disableQueryContextCache)) {
Errors.checkArgumentValid(Util.isBoolean(options.disableQueryContextCache),
ErrorCodes.ERR_CONN_CREATE_INVALID_DISABLED_QUERY_CONTEXT_CACHE);
disableQueryContextCache = options.disableQueryContextCache;
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,23 @@ function ConnectionConfig(options, validateCredentials, qaMode, clientInfo)
return forceStageBindError;
};

/**
* Returns the force stage bind error
*
* @returns {Number}
*/
this.getForceStageBindError = function () {
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
return forceStageBindError;
};
/**
* Returns the status of the query contextcache.
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
*
* @returns {Number}
*/
this.getDisableQueryContextCache = function () {
return disableQueryContextCache;
}

// save config options
this.username = options.username;
this.password = options.password;
Expand All @@ -758,6 +783,7 @@ function ConnectionConfig(options, validateCredentials, qaMode, clientInfo)
this.masterToken = options.masterToken;
this.masterTokenExpirationTime = options.masterTokenExpirationTime;
this.sessionTokenExpirationTime = options.sessionTokenExpirationTime;
this.disableQueryContextCache = disableQueryContextCache;
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved

// create the parameters array
var parameters = createParameters();
Expand Down
5 changes: 5 additions & 0 deletions lib/connection/result/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function Result(options) {
this._returnedRows = data.returned;
this._totalRows = data.total;
this._statementTypeId = data.statementTypeId;
this._queryContext = data.queryContext;

// if no chunk headers were specified, but a query-result-master-key (qrmk)
// was specified, build the chunk headers from the qrmk
Expand Down Expand Up @@ -125,6 +126,10 @@ function Result(options) {
this._statement,
this._services);

this.getQueryContext = function() {
return this._queryContext;
}

/* Disable the ChunkCache until the implementation is complete.
*
* // create a chunk cache and save a reference to it in case we need to
Expand Down
14 changes: 14 additions & 0 deletions lib/connection/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,16 @@ function createOnStatementRequestSuccRow(statement, context)
rowMode: context.rowMode
});
// save the query id
Logger.getInstance().trace('Here is JSON Response',{
response: JSON.stringify(body),
statement: JSON.stringify(statement),
services: JSON.stringify(context.services),
connectionConfig: JSON.stringify(context.connectionConfig),
rowMode: JSON.stringify(context.rowMode),
queryContext:JSON.stringify(context.result.getQueryContext())
})
context.queryId = context.result.getQueryId();
this.services.sf.deserializeQueryContext(context.result.getQueryContext());
}
}
else
Expand Down Expand Up @@ -1334,6 +1343,11 @@ function sendRequestPreExec(statementContext, onResultAvailable)
json.isInternal = statementContext.internal;
}

if(!statementContext.disableQueryContextCache){
json.queryContextDTO = statementContext.services.sf.getQueryContextDTO();
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
}

Logger.getInstance().trace("Here is the constructed body",JSON.stringify(json));
// use the snowflake service to issue the request
sendSfRequest(statementContext,
{
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[404041] = 'Invalid disablQueryContextCache. 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_DISABLED_QUERY_CONTEXT_CACHE = 404041

// 405001
codes.ERR_CONN_CONNECT_INVALID_CALLBACK = 405001;
Expand Down
7 changes: 7 additions & 0 deletions lib/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ names.CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY = 'CLIENT_SESSION_KEEP_ALIVE
names.JS_TREAT_INTEGER_AS_BIGINT = 'JS_TREAT_INTEGER_AS_BIGINT';
names.CLIENT_STAGE_ARRAY_BINDING_THRESHOLD = 'CLIENT_STAGE_ARRAY_BINDING_THRESHOLD';
names.MULTI_STATEMENT_COUNT = 'MULTI_STATEMENT_COUNT';
names.QUERY_CONTEXT_CACHE_SIZE = 'QUERY_CONTEXT_CACHE_SIZE';

var parameters =
[
Expand Down Expand Up @@ -106,6 +107,12 @@ var parameters =
value: 1,
desc: 'When 1, multi statement is disable, when 0, multi statement is unlimited'
}),
new Parameter(
{
name: names.QUERY_CONTEXT_CACHE_SIZE,
value: 5,
desc: 'Query Context Cache Size'
}),
];

// put all the parameters in a map so they're easy to retrieve and update
Expand Down
Loading