Skip to content

Commit a481e5f

Browse files
committed
Create req in DistSearchCommandImp()
1 parent be175c6 commit a481e5f

3 files changed

Lines changed: 18 additions & 32 deletions

File tree

src/coord/rmr/rmr.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ void *MRCtx_GetPrivData(struct MRCtx *ctx) {
156156
return ctx->privdata;
157157
}
158158

159-
void MRCtx_SetPrivData(struct MRCtx *ctx, void *privdata) {
160-
ctx->privdata = privdata;
161-
}
162-
163159
int MRCtx_GetNumReplied(struct MRCtx *ctx) {
164160
return ctx->numReplied;
165161
}

src/coord/rmr/rmr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ void MR_FreeCluster();
8383

8484
/* Get the user stored private data from the context */
8585
void *MRCtx_GetPrivData(struct MRCtx *ctx);
86-
void MRCtx_SetPrivData(struct MRCtx *ctx, void *privdata);
8786

8887
struct RedisModuleCtx *MRCtx_GetRedisCtx(struct MRCtx *ctx);
8988
int MRCtx_GetNumReplied(struct MRCtx *ctx);

src/module.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3797,16 +3797,6 @@ static int prepareCommand(MRCommand *cmd, searchRequestCtx *req, struct MRCtx *m
37973797
return REDISMODULE_OK;
37983798
}
37993799

3800-
static searchRequestCtx *createReq(RedisModuleString **argv, int argc, struct MRCtx *mrctx, QueryError *status) {
3801-
searchRequestCtx *req = rscParseRequest(argv, argc, status);
3802-
3803-
if (!req) {
3804-
bailOut(MRCtx_GetBlockedClient(mrctx), status);
3805-
return NULL;
3806-
}
3807-
return req;
3808-
}
3809-
38103800
int FlatSearchCommandHandler(struct MRCtx *mrctx, RedisModuleBlockedClient *bc, int protocol,
38113801
RedisModuleString **argv, int argc, ConcurrentSearchHandlerCtx *handlerCtx) {
38123802
QueryError status = QueryError_Default();
@@ -3947,17 +3937,23 @@ int DistSearchCommandImp(RedisModuleCtx *ctx, RedisModuleString **argv, int argc
39473937
return ReplyBlockDeny(ctx, argv[0]);
39483938
}
39493939

3950-
// Parse the search request on the main thread (non-debug path).
3951-
// For debug path, req is created later in DEBUG_FlatSearchCommandHandler.
3952-
searchRequestCtx *req = NULL;
3953-
if (!isDebug) {
3954-
QueryError parseStatus = QueryError_Default();
3955-
req = rscParseRequest(argv, argc, &parseStatus);
3956-
if (!req) {
3940+
QueryError parseStatus = QueryError_Default();
3941+
int parse_argc = argc;
3942+
if (isDebug) {
3943+
AREQ_Debug_params debug_params = parseDebugParamsCount(argv, argc, &parseStatus);
3944+
if (QueryError_HasError(&parseStatus)) {
39573945
QueryErrorsGlobalStats_UpdateError(QueryError_GetCode(&parseStatus), 1, COORD_ERR_WARN);
3958-
QueryError_ReplyAndClear(ctx, &parseStatus);
3959-
return REDISMODULE_ERR;
3946+
return QueryError_ReplyAndClear(ctx, &parseStatus);
39603947
}
3948+
parse_argc = argc - (debug_params.debug_params_count + 2);
3949+
}
3950+
3951+
// Parse the search request on the main thread so both the standard and debug
3952+
// paths attach req to mrctx before dispatching to the worker thread.
3953+
searchRequestCtx *req = rscParseRequest(argv, parse_argc, &parseStatus);
3954+
if (!req) {
3955+
QueryErrorsGlobalStats_UpdateError(QueryError_GetCode(&parseStatus), 1, COORD_ERR_WARN);
3956+
return QueryError_ReplyAndClear(ctx, &parseStatus);
39613957
}
39623958

39633959
// Create MRCtx on main thread with searchRequestCtx as privdata.
@@ -4365,14 +4361,9 @@ static int DEBUG_FlatSearchCommandHandler(struct MRCtx *mrctx, RedisModuleBlocke
43654361

43664362
int debug_argv_count = debug_params.debug_params_count + 2;
43674363
int base_argc = argc - debug_argv_count;
4368-
searchRequestCtx *req = createReq(argv, base_argc, mrctx, &status);
4369-
4370-
if (!req) {
4371-
return REDISMODULE_OK;
4372-
}
4373-
4374-
// Set req as privdata on mrctx so the reducer and cleanup can access it
4375-
MRCtx_SetPrivData(mrctx, req);
4364+
// req was created on the main thread and set as mrctx privdata before dispatch.
4365+
searchRequestCtx *req = MRCtx_GetPrivData(mrctx);
4366+
RS_ASSERT(req);
43764367

43774368
// Copy coordinator queue time for profile output
43784369
req->coordQueueTime = handlerCtx->coordQueueTime;

0 commit comments

Comments
 (0)