Skip to content

Fixed flagged as "getkeys-api" during the registration ( AI.DAGRUN, AI.DAGRUN_RO, AI.MODELRUN, AI.SCRIPTRUN ) #438

New issue

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

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

Already on GitHub? # to your account

Merged
merged 21 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
09c26cf
[wip] wip on fixing the commands being flagged as getkeys-api during …
filipecosta90 Aug 5, 2020
4535022
Merge branch 'master' into fix.getkeys.api
filipecosta90 Aug 5, 2020
8c8ac76
[add] pytorch oss cluster tests passing
filipecosta90 Aug 5, 2020
7d1dff7
[add] TensorFlow lite tests passing on oss cluster
filipecosta90 Aug 5, 2020
405bdb6
[add] ONNX tests passing on oss cluster
filipecosta90 Aug 5, 2020
a366ab6
[add] TensorFlow tests passing on oss cluster
filipecosta90 Aug 5, 2020
165fd64
[wip] wip on dag
filipecosta90 Aug 5, 2020
2b3ad9e
[add] DAG tests passing on oss cluster
filipecosta90 Aug 6, 2020
5205acb
[add] enabling oss cluster tests on CI
filipecosta90 Aug 6, 2020
e50a1e8
[add] bumping rmbuilder version from 6.0.1 to 6.0.5 on circleci
filipecosta90 Aug 6, 2020
9fdfb28
[fix] fixed potential invalid mem accesses on RedisAI_DagRunSyntaxPar…
filipecosta90 Aug 6, 2020
264f8c4
[fix] fixed RAI_FreeDagOp wrongfully calling RedisModule_Free on dagO…
filipecosta90 Aug 6, 2020
8714176
[fix] fixed dictKey allocation on RAI_parseDAGLoadArgs
filipecosta90 Aug 6, 2020
21e7e04
[add] alter Sanitizer tests to accommodate keys on the same slot.
filipecosta90 Aug 6, 2020
e0aabf8
[add] extracted the methods to respond to RedisModule_IsKeysPositionR…
filipecosta90 Aug 6, 2020
32484a8
Merge branch 'master' into fix.getkeys.api
filipecosta90 Aug 6, 2020
1ee4d4b
[fix] Fixes per PR review
filipecosta90 Aug 7, 2020
827be02
Merge branch 'master' into fix.getkeys.api
filipecosta90 Aug 7, 2020
cf3dfc1
Merge branch 'fix.getkeys.api' of https://github.com/RedisAI/RedisAI …
filipecosta90 Aug 7, 2020
056834b
[fix] fixes per PR review
filipecosta90 Aug 7, 2020
67a7758
[fix] fix per CI ascii conversion error on test_dagro_modelrun_financ…
filipecosta90 Aug 7, 2020
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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ commands:
jobs:
build-debian:
docker:
- image: redisfab/rmbuilder:6.0.1-x64-buster
- image: redisfab/rmbuilder:6.0.5-x64-buster
steps:
- build-steps:
platform: debian
Expand All @@ -112,7 +112,7 @@ jobs:

coverage:
docker:
- image: redisfab/rmbuilder:6.0.1-x64-buster
- image: redisfab/rmbuilder:6.0.5-x64-buster
steps:
- checkout
- run:
Expand All @@ -136,7 +136,7 @@ jobs:
- run:
name: Test with coverage
command: |
make -C opt test SHOW=1 COV=1
make -C opt test SHOW=1 COV=1 CLUSTER=1
make -C opt cov-upload
no_output_timeout: 20m

Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
package:
type: string
docker:
- image: redisfab/rmbuilder:6.0.1-x64-buster
- image: redisfab/rmbuilder:6.0.5-x64-buster
steps:
- attach_workspace:
at: workspace
Expand Down
2 changes: 2 additions & 0 deletions opt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ endif
export GEN ?= 1
export SLAVES ?= 1
export AOF ?= 1
export CLUSTER ?= 1

test:
$(COVERAGE_RESET)
$(SHOW)\
DEVICE=$(DEVICE) \
MODULE=$(INSTALLED_TARGET) \
CLUSTER=$(CLUSTER) \
GEN=$(GEN) AOF=$(AOF) SLAVES=$(SLAVES) \
VALGRIND=$(VALGRIND) \
$(ROOT)/test/tests.sh
Expand Down
39 changes: 32 additions & 7 deletions src/dag.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ int RAI_parseDAGLoadArgs(RedisModuleCtx *ctx, RedisModuleString **argv,
ctx, "ERR invalid or negative value found in number of keys to LOAD");
return -1;
}

int number_loaded_keys = 0;
int separator_flag = 0;
size_t argpos = 2;
Expand All @@ -522,8 +521,7 @@ int RAI_parseDAGLoadArgs(RedisModuleCtx *ctx, RedisModuleString **argv,
} else {
RAI_Tensor *t;
RedisModuleKey *key;
const int status = RAI_GetTensorFromKeyspace(ctx, argv[argpos], &key, &t,
REDISMODULE_READ);
const int status = RAI_GetTensorFromKeyspace(ctx, argv[argpos], &key, &t, REDISMODULE_READ);
if (status == REDISMODULE_ERR) {
RedisModule_Log(
ctx, "warning",
Expand All @@ -532,9 +530,9 @@ int RAI_parseDAGLoadArgs(RedisModuleCtx *ctx, RedisModuleString **argv,
return -1;
}
RedisModule_CloseKey(key);
char *dictKey = RedisModule_Alloc(strlen(arg_string) + 4);
char *dictKey = (char*) RedisModule_Alloc((strlen(arg_string) + 5)*sizeof(char));
sprintf(dictKey, "%s%04d", arg_string, 1);
AI_dictAdd(*localContextDict, (void*)dictKey, t);
AI_dictAdd(*localContextDict, (void*)dictKey, (void *)t);
AI_dictAdd(*loadedContextDict, (void*)dictKey, (void *)1);
RedisModule_Free(dictKey);
number_loaded_keys++;
Expand Down Expand Up @@ -587,10 +585,35 @@ int RAI_parseDAGPersistArgs(RedisModuleCtx *ctx, RedisModuleString **argv,
return argpos;
}

int RedisAI_DagRun_IsKeysPositionRequest_ReportKeys(RedisModuleCtx *ctx,
RedisModuleString **argv, int argc){
for (size_t argpos = 1; argpos < argc; argpos++){
const char *arg_string = RedisModule_StringPtrLen(argv[argpos], NULL);
if ( (!strcasecmp(arg_string, "LOAD") || !strcasecmp(arg_string, "PERSIST") ) && (argpos+1 < argc) ) {
long long n_keys;
argpos++;
const int retval = RedisModule_StringToLongLong(argv[argpos], &n_keys);
if(retval != REDISMODULE_OK){
return REDISMODULE_ERR;
}
argpos++;
if (n_keys > 0){
size_t last_persist_argpos = n_keys+argpos;
for (; argpos < last_persist_argpos && argpos < argc; argpos++){
RedisModule_KeyAtPos(ctx, argpos);
}
}
}
}
return REDISMODULE_OK;
}

int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv,
int argc, int dagMode) {
if (RedisModule_IsKeysPositionRequest(ctx)) {
return RedisAI_DagRun_IsKeysPositionRequest_ReportKeys(ctx, argv, argc);
}
if (argc < 4) return RedisModule_WrongArity(ctx);

RedisAI_RunInfo *rinfo = NULL;
if (RAI_InitRunInfo(&rinfo) == REDISMODULE_ERR) {
return RedisModule_ReplyWithError(
Expand Down Expand Up @@ -703,6 +726,7 @@ int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv,

for (long long i=0; i<array_len(rinfo->dagOps); i++) {
RAI_DagOp *currentOp = rinfo->dagOps[i];
if(currentOp==NULL) continue;
int parse_result;
switch (currentOp->commandType) {
case REDISAI_DAG_CMD_TENSORSET:
Expand Down Expand Up @@ -818,7 +842,8 @@ int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv,
}
int *instance = AI_dictGetVal(mangled_entry);
RedisModuleString *mangled_key = RedisModule_CreateStringPrintf(ctx, "%s%04d", key, *instance);
AI_dictAdd(mangled_persisted, (void *)RedisModule_StringPtrLen(mangled_key, NULL), (void *)1);
const char* mangled_key_str = RedisModule_StringPtrLen(mangled_key, NULL);
AI_dictAdd(mangled_persisted, (void *)mangled_key_str, (void *)1);
entry = AI_dictNext(iter);
}
AI_dictReleaseIterator(iter);
Expand Down
15 changes: 15 additions & 0 deletions src/dag.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ int RAI_parseDAGPersistArgs(RedisModuleCtx *ctx, RedisModuleString **argv,
int argc, AI_dict **localContextDict,
const char *chaining_operator);

/**
* When a module command is called in order to obtain the position of
* keys, since it was flagged as "getkeys-api" during the registration,
* the command implementation checks for this special call using the
* RedisModule_IsKeysPositionRequest() API and uses this function in
* order to report keys.
* No real execution is done on this special call.
* @param ctx Context in which Redis modules operate
* @param argv Redis command arguments, as an array of strings
* @param argc Redis command number of arguments
* @return
*/
int RedisAI_DagRun_IsKeysPositionRequest_ReportKeys(RedisModuleCtx *ctx,
RedisModuleString **argv, int argc);

/**
* DAGRUN and DAGRUN_RO parser, which reads the the sequence of
* arguments and decides whether the sequence conforms to the syntax
Expand Down
13 changes: 12 additions & 1 deletion src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,18 @@ int RAI_ModelSerialize(RAI_Model *model, char **buffer, size_t *len, RAI_Error *
return ret;
}

int RedisAI_ModelRun_IsKeysPositionRequest_ReportKeys(RedisModuleCtx *ctx,
RedisModuleString **argv, int argc){
RedisModule_KeyAtPos(ctx, 1);
for (size_t argpos = 3; argpos < argc; argpos++){
const char *str = RedisModule_StringPtrLen(argv[argpos], NULL);
if (!strcasecmp(str, "OUTPUTS")) {
continue;
}
RedisModule_KeyAtPos(ctx,argpos);
}
return REDISMODULE_OK;
}

int RedisAI_Parse_ModelRun_RedisCommand(RedisModuleCtx *ctx,
RedisModuleString **argv, int argc,
Expand Down Expand Up @@ -590,7 +602,6 @@ int RedisAI_Parse_ModelRun_RedisCommand(RedisModuleCtx *ctx,
}
}
}

if ((*mto)->inputs && array_len((*mto)->inputs) != ninputs) {
RAI_SetError(
error, RAI_EMODELRUN,
Expand Down
15 changes: 15 additions & 0 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ int RAI_ModelSerialize(RAI_Model* model, char** buffer, size_t* len,
int RAI_GetModelFromKeyspace(RedisModuleCtx* ctx, RedisModuleString* keyName,
RedisModuleKey** key, RAI_Model** model, int mode);

/**
* When a module command is called in order to obtain the position of
* keys, since it was flagged as "getkeys-api" during the registration,
* the command implementation checks for this special call using the
* RedisModule_IsKeysPositionRequest() API and uses this function in
* order to report keys.
* No real execution is done on this special call.
* @param ctx Context in which Redis modules operate
* @param argv Redis command arguments, as an array of strings
* @param argc Redis command number of arguments
* @return
*/
int RedisAI_ModelRun_IsKeysPositionRequest_ReportKeys(RedisModuleCtx *ctx,
RedisModuleString **argv, int argc);

/**
* Helper method to parse AI.MODELRUN arguments
*
Expand Down
15 changes: 8 additions & 7 deletions src/redisai.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,20 +535,20 @@ int RedisAI_ModelScan_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
*/
int RedisAI_ModelRun_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
int argc) {
if (RedisModule_IsKeysPositionRequest(ctx)) {
return RedisAI_ModelRun_IsKeysPositionRequest_ReportKeys(ctx, argv, argc);
}
if (argc < 3) return RedisModule_WrongArity(ctx);

RedisAI_RunInfo *rinfo = NULL;
if (RAI_InitRunInfo(&rinfo) == REDISMODULE_ERR) {
return RedisModule_ReplyWithError(ctx, "ERR Unable to allocate the memory and initialise the RedisAI_RunInfo structure");
}

RAI_Model *mto;
RedisModuleKey *modelKey;
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &modelKey, &mto, REDISMODULE_READ);
if (status == REDISMODULE_ERR) {
return REDISMODULE_ERR;
}

RedisModule_RetainString(NULL, argv[1]);
rinfo->runkey = argv[1];
rinfo->mctx = RAI_ModelRunCtxCreate(mto);
Expand Down Expand Up @@ -618,16 +618,17 @@ int RedisAI_ModelRun_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
* AI.SCRIPTRUN <key> <function> INPUTS <input> [input ...] OUTPUTS <output> [output ...]
*/
int RedisAI_ScriptRun_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
if (RedisModule_IsKeysPositionRequest(ctx)) {
return RedisAI_ScriptRun_IsKeysPositionRequest_ReportKeys(ctx, argv, argc);
}
if (argc < 6) return RedisModule_WrongArity(ctx);

RedisAI_RunInfo *rinfo = NULL;
if (RAI_InitRunInfo(&rinfo) == REDISMODULE_ERR) {
return RedisModule_ReplyWithError(
ctx,
"ERR Unable to allocate the memory and initialise the RedisAI_RunInfo"
"structure");
}

RedisModule_RetainString(NULL, argv[1]);
rinfo->runkey = argv[1];

Expand Down Expand Up @@ -1204,11 +1205,11 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
== REDISMODULE_ERR)
return REDISMODULE_ERR;

if (RedisModule_CreateCommand(ctx, "ai.dagrun", RedisAI_DagRun_RedisCommand, "write deny-oom", 3, 3, 1)
if (RedisModule_CreateCommand(ctx, "ai.dagrun", RedisAI_DagRun_RedisCommand, "write deny-oom getkeys-api", 3, 3, 1)
== REDISMODULE_ERR)
return REDISMODULE_ERR;

if (RedisModule_CreateCommand(ctx, "ai.dagrun_ro", RedisAI_DagRunRO_RedisCommand, "readonly", 3, 3, 1)
if (RedisModule_CreateCommand(ctx, "ai.dagrun_ro", RedisAI_DagRunRO_RedisCommand, "readonly getkeys-api", 3, 3, 1)
== REDISMODULE_ERR)
return REDISMODULE_ERR;

Expand Down
11 changes: 5 additions & 6 deletions src/run_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ int RAI_ShallowCopyDagRunInfo(RedisAI_RunInfo **result, RedisAI_RunInfo *src) {
void RAI_FreeDagOp(RedisModuleCtx *ctx, RAI_DagOp *dagOp) {
if (dagOp) {
RAI_FreeError(dagOp->err);
if(dagOp->runkey){
RedisModule_FreeString(ctx,dagOp->runkey);
}
if (dagOp->argv) {
for (size_t i = 0; i < array_len(dagOp->argv); i++) {
RedisModule_FreeString(ctx, dagOp->argv[i]);
Expand All @@ -203,14 +206,14 @@ void RAI_FreeDagOp(RedisModuleCtx *ctx, RAI_DagOp *dagOp) {

if (dagOp->inkeys) {
for (size_t i=0; i<array_len(dagOp->inkeys); i++) {
RedisModule_Free(dagOp->inkeys[i]);
RedisModule_FreeString(ctx,dagOp->inkeys[i]);
}
array_free(dagOp->inkeys);
}

if (dagOp->outkeys) {
for (size_t i=0; i<array_len(dagOp->outkeys); i++) {
RedisModule_Free(dagOp->outkeys[i]);
RedisModule_FreeString(ctx,dagOp->outkeys[i]);
}
array_free(dagOp->outkeys);
}
Expand Down Expand Up @@ -273,10 +276,6 @@ void RAI_FreeRunInfo(RedisModuleCtx *ctx, struct RedisAI_RunInfo *rinfo) {
entry = AI_dictNext(iter);
}
AI_dictReleaseIterator(iter);

RedisModule_Free(rinfo->dagTensorsContext);
RedisModule_Free(rinfo->dagTensorsLoadedContext);
RedisModule_Free(rinfo->dagTensorsPersistedContext);
}

if (rinfo->dagOps) {
Expand Down
13 changes: 13 additions & 0 deletions src/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ int RAI_GetScriptFromKeyspace(RedisModuleCtx* ctx, RedisModuleString* keyName,
return REDISMODULE_OK;
}

int RedisAI_ScriptRun_IsKeysPositionRequest_ReportKeys(RedisModuleCtx *ctx,
RedisModuleString **argv, int argc){
RedisModule_KeyAtPos(ctx, 1);
for (size_t argpos = 4; argpos < argc; argpos++){
const char *str = RedisModule_StringPtrLen(argv[argpos], NULL);
if (!strcasecmp(str, "OUTPUTS")) {
continue;
}
RedisModule_KeyAtPos(ctx,argpos);
}
return REDISMODULE_OK;
}

/**
* AI.SCRIPTRUN <key> <function> INPUTS <input> [input ...] OUTPUTS <output> [output ...]
*/
Expand Down
15 changes: 15 additions & 0 deletions src/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ int RAI_GetScriptFromKeyspace(RedisModuleCtx* ctx, RedisModuleString* keyName,
int mode);


/**
* When a module command is called in order to obtain the position of
* keys, since it was flagged as "getkeys-api" during the registration,
* the command implementation checks for this special call using the
* RedisModule_IsKeysPositionRequest() API and uses this function in
* order to report keys.
* No real execution is done on this special call.
* @param ctx Context in which Redis modules operate
* @param argv Redis command arguments, as an array of strings
* @param argc Redis command number of arguments
* @return
*/
int RedisAI_ScriptRun_IsKeysPositionRequest_ReportKeys(RedisModuleCtx *ctx,
RedisModuleString **argv, int argc);

/**
* Helper method to parse AI.SCRIPTRUN arguments
*
Expand Down
Loading