Skip to content

Commit 2b43639

Browse files
committed
Create req in DistSearchCommandImp()
1 parent 3da0c1a commit 2b43639

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
@@ -163,10 +163,6 @@ void *MRCtx_GetPrivData(struct MRCtx *ctx) {
163163
return ctx->privdata;
164164
}
165165

166-
void MRCtx_SetPrivData(struct MRCtx *ctx, void *privdata) {
167-
ctx->privdata = privdata;
168-
}
169-
170166
int MRCtx_GetNumReplied(struct MRCtx *ctx) {
171167
return ctx->numReplied;
172168
}

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
@@ -3801,16 +3801,6 @@ static int prepareCommand(MRCommand *cmd, searchRequestCtx *req, struct MRCtx *m
38013801
return REDISMODULE_OK;
38023802
}
38033803

3804-
static searchRequestCtx *createReq(RedisModuleString **argv, int argc, struct MRCtx *mrctx, QueryError *status) {
3805-
searchRequestCtx *req = rscParseRequest(argv, argc, status);
3806-
3807-
if (!req) {
3808-
bailOut(MRCtx_GetBlockedClient(mrctx), status);
3809-
return NULL;
3810-
}
3811-
return req;
3812-
}
3813-
38143804
int FlatSearchCommandHandler(struct MRCtx *mrctx, RedisModuleBlockedClient *bc, int protocol,
38153805
RedisModuleString **argv, int argc, ConcurrentSearchHandlerCtx *handlerCtx) {
38163806
QueryError status = QueryError_Default();
@@ -3954,17 +3944,23 @@ int DistSearchCommandImp(RedisModuleCtx *ctx, RedisModuleString **argv, int argc
39543944
return ReplyBlockDeny(ctx, argv[0]);
39553945
}
39563946

3957-
// Parse the search request on the main thread (non-debug path).
3958-
// For debug path, req is created later in DEBUG_FlatSearchCommandHandler.
3959-
searchRequestCtx *req = NULL;
3960-
if (!isDebug) {
3961-
QueryError parseStatus = QueryError_Default();
3962-
req = rscParseRequest(argv, argc, &parseStatus);
3963-
if (!req) {
3947+
QueryError parseStatus = QueryError_Default();
3948+
int parse_argc = argc;
3949+
if (isDebug) {
3950+
AREQ_Debug_params debug_params = parseDebugParamsCount(argv, argc, &parseStatus);
3951+
if (QueryError_HasError(&parseStatus)) {
39643952
QueryErrorsGlobalStats_UpdateError(QueryError_GetCode(&parseStatus), 1, COORD_ERR_WARN);
3965-
QueryError_ReplyAndClear(ctx, &parseStatus);
3966-
return REDISMODULE_ERR;
3953+
return QueryError_ReplyAndClear(ctx, &parseStatus);
39673954
}
3955+
parse_argc = argc - (debug_params.debug_params_count + 2);
3956+
}
3957+
3958+
// Parse the search request on the main thread so both the standard and debug
3959+
// paths attach req to mrctx before dispatching to the worker thread.
3960+
searchRequestCtx *req = rscParseRequest(argv, parse_argc, &parseStatus);
3961+
if (!req) {
3962+
QueryErrorsGlobalStats_UpdateError(QueryError_GetCode(&parseStatus), 1, COORD_ERR_WARN);
3963+
return QueryError_ReplyAndClear(ctx, &parseStatus);
39683964
}
39693965

39703966
// Create MRCtx on main thread with searchRequestCtx as privdata.
@@ -4372,14 +4368,9 @@ static int DEBUG_FlatSearchCommandHandler(struct MRCtx *mrctx, RedisModuleBlocke
43724368

43734369
int debug_argv_count = debug_params.debug_params_count + 2;
43744370
int base_argc = argc - debug_argv_count;
4375-
searchRequestCtx *req = createReq(argv, base_argc, mrctx, &status);
4376-
4377-
if (!req) {
4378-
return REDISMODULE_OK;
4379-
}
4380-
4381-
// Set req as privdata on mrctx so the reducer and cleanup can access it
4382-
MRCtx_SetPrivData(mrctx, req);
4371+
// req was created on the main thread and set as mrctx privdata before dispatch.
4372+
searchRequestCtx *req = MRCtx_GetPrivData(mrctx);
4373+
RS_ASSERT(req);
43834374

43844375
// Copy coordinator queue time for profile output
43854376
req->coordQueueTime = handlerCtx->coordQueueTime;

0 commit comments

Comments
 (0)