Convert some hard coded errors to deferred errors in router planner

pull/4358/head
Sait Talha Nisanci 2020-12-07 15:52:05 +03:00
parent 69992d58f9
commit 28c5b6a425
5 changed files with 46 additions and 19 deletions

View File

@ -546,7 +546,8 @@ RegenerateTaskForFasthPathQuery(Job *workerJob)
GenerateSingleShardRouterTaskList(workerJob, GenerateSingleShardRouterTaskList(workerJob,
relationShardList, relationShardList,
placementList, shardId); placementList,
shardId);
} }

View File

@ -171,7 +171,8 @@ static Task * QueryPushdownTaskCreate(Query *originalQuery, int shardIndex,
RelationRestrictionContext *restrictionContext, RelationRestrictionContext *restrictionContext,
uint32 taskId, uint32 taskId,
TaskType taskType, TaskType taskType,
bool modifyRequiresCoordinatorEvaluation); bool modifyRequiresCoordinatorEvaluation,
DeferredErrorMessage **planningError);
static bool ShardIntervalsEqual(FmgrInfo *comparisonFunction, static bool ShardIntervalsEqual(FmgrInfo *comparisonFunction,
Oid collation, Oid collation,
ShardInterval *firstInterval, ShardInterval *firstInterval,
@ -2105,11 +2106,16 @@ BuildJobTreeTaskList(Job *jobTree, PlannerRestrictionContext *plannerRestriction
relationRestrictionContext, relationRestrictionContext,
&isMultiShardQuery, NULL); &isMultiShardQuery, NULL);
DeferredErrorMessage *deferredErrorMessage = NULL;
sqlTaskList = QueryPushdownSqlTaskList(job->jobQuery, job->jobId, sqlTaskList = QueryPushdownSqlTaskList(job->jobQuery, job->jobId,
plannerRestrictionContext-> plannerRestrictionContext->
relationRestrictionContext, relationRestrictionContext,
prunedRelationShardList, READ_TASK, prunedRelationShardList, READ_TASK,
false); false,
&deferredErrorMessage);
if (deferredErrorMessage != NULL) {
RaiseDeferredErrorInternal(deferredErrorMessage, ERROR);
}
} }
else else
{ {
@ -2187,7 +2193,8 @@ List *
QueryPushdownSqlTaskList(Query *query, uint64 jobId, QueryPushdownSqlTaskList(Query *query, uint64 jobId,
RelationRestrictionContext *relationRestrictionContext, RelationRestrictionContext *relationRestrictionContext,
List *prunedRelationShardList, TaskType taskType, bool List *prunedRelationShardList, TaskType taskType, bool
modifyRequiresCoordinatorEvaluation) modifyRequiresCoordinatorEvaluation,
DeferredErrorMessage **planningError)
{ {
List *sqlTaskList = NIL; List *sqlTaskList = NIL;
ListCell *restrictionCell = NULL; ListCell *restrictionCell = NULL;
@ -2201,8 +2208,11 @@ QueryPushdownSqlTaskList(Query *query, uint64 jobId,
if (list_length(relationRestrictionContext->relationRestrictionList) == 0) if (list_length(relationRestrictionContext->relationRestrictionList) == 0)
{ {
ereport(ERROR, (errmsg("cannot handle complex subqueries when the " *planningError = DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"router executor is disabled"))); "cannot handle complex subqueries when the "
"router executor is disabled",
NULL, NULL);
return NIL;
} }
/* defaults to be used if this is a reference table-only query */ /* defaults to be used if this is a reference table-only query */
@ -2227,8 +2237,11 @@ QueryPushdownSqlTaskList(Query *query, uint64 jobId,
/* we expect distributed tables to have the same shard count */ /* we expect distributed tables to have the same shard count */
if (shardCount > 0 && shardCount != cacheEntry->shardIntervalArrayLength) if (shardCount > 0 && shardCount != cacheEntry->shardIntervalArrayLength)
{ {
ereport(ERROR, (errmsg("shard counts of co-located tables do not " *planningError = DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"match"))); "shard counts of co-located tables do not "
"match",
NULL, NULL);
return NIL;
} }
if (taskRequiredForShardIndex == NULL) if (taskRequiredForShardIndex == NULL)
@ -2291,7 +2304,11 @@ QueryPushdownSqlTaskList(Query *query, uint64 jobId,
relationRestrictionContext, relationRestrictionContext,
taskIdIndex, taskIdIndex,
taskType, taskType,
modifyRequiresCoordinatorEvaluation); modifyRequiresCoordinatorEvaluation,
planningError);
if (*planningError != NULL) {
return NIL;
}
subqueryTask->jobId = jobId; subqueryTask->jobId = jobId;
sqlTaskList = lappend(sqlTaskList, subqueryTask); sqlTaskList = lappend(sqlTaskList, subqueryTask);
@ -2467,7 +2484,8 @@ ErrorIfUnsupportedShardDistribution(Query *query)
static Task * static Task *
QueryPushdownTaskCreate(Query *originalQuery, int shardIndex, QueryPushdownTaskCreate(Query *originalQuery, int shardIndex,
RelationRestrictionContext *restrictionContext, uint32 taskId, RelationRestrictionContext *restrictionContext, uint32 taskId,
TaskType taskType, bool modifyRequiresCoordinatorEvaluation) TaskType taskType, bool modifyRequiresCoordinatorEvaluation,
DeferredErrorMessage **planningError)
{ {
Query *taskQuery = copyObject(originalQuery); Query *taskQuery = copyObject(originalQuery);
@ -2546,8 +2564,12 @@ QueryPushdownTaskCreate(Query *originalQuery, int shardIndex,
List *taskPlacementList = PlacementsForWorkersContainingAllShards(taskShardList); List *taskPlacementList = PlacementsForWorkersContainingAllShards(taskShardList);
if (list_length(taskPlacementList) == 0) if (list_length(taskPlacementList) == 0)
{ {
ereport(ERROR, (errmsg("cannot find a worker that has active placements for all " *planningError = DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"shards in the query"))); "cannot find a worker that has active placements for all "
"shards in the query",
NULL, NULL);
return NULL;
} }
/* /*

View File

@ -1781,7 +1781,11 @@ RouterJob(Query *originalQuery, PlannerRestrictionContext *plannerRestrictionCon
relationRestrictionContext, relationRestrictionContext,
prunedShardIntervalListList, prunedShardIntervalListList,
MODIFY_TASK, MODIFY_TASK,
requiresCoordinatorEvaluation); requiresCoordinatorEvaluation,
planningError);
if (*planningError) {
return NULL;
}
} }
else else
{ {
@ -1806,14 +1810,12 @@ GenerateSingleShardRouterTaskList(Job *job, List *relationShardList,
{ {
Query *originalQuery = job->jobQuery; Query *originalQuery = job->jobQuery;
if (originalQuery->commandType == CMD_SELECT) if (originalQuery->commandType == CMD_SELECT)
{ {
job->taskList = SingleShardTaskList(originalQuery, job->jobId, job->taskList = SingleShardTaskList(originalQuery, job->jobId,
relationShardList, placementList, relationShardList, placementList,
shardId, shardId,
job->parametersInJobQueryResolved); job->parametersInJobQueryResolved);
/* /*
* Queries to reference tables, or distributed tables with multiple replica's have * Queries to reference tables, or distributed tables with multiple replica's have
* their task placements reordered according to the configured * their task placements reordered according to the configured

View File

@ -576,7 +576,8 @@ extern List * QueryPushdownSqlTaskList(Query *query, uint64 jobId,
RelationRestrictionContext * RelationRestrictionContext *
relationRestrictionContext, relationRestrictionContext,
List *prunedRelationShardList, TaskType taskType, List *prunedRelationShardList, TaskType taskType,
bool modifyRequiresCoordinatorEvaluation); bool modifyRequiresCoordinatorEvaluation,
DeferredErrorMessage **planningError);
/* function declarations for managing jobs */ /* function declarations for managing jobs */
extern uint64 UniqueJobId(void); extern uint64 UniqueJobId(void);

View File

@ -84,7 +84,8 @@ extern List * TargetShardIntervalForFastPathQuery(Query *query,
Const **outGoingPartitionValueConst); Const **outGoingPartitionValueConst);
extern void GenerateSingleShardRouterTaskList(Job *job, extern void GenerateSingleShardRouterTaskList(Job *job,
List *relationShardList, List *relationShardList,
List *placementList, uint64 shardId); List *placementList,
uint64 shardId);
extern bool IsRouterPlannable(Query *query, extern bool IsRouterPlannable(Query *query,
PlannerRestrictionContext *plannerRestrictionContext); PlannerRestrictionContext *plannerRestrictionContext);