-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Execution
-
None
-
3
-
None
-
None
-
None
-
None
-
None
-
None
Currently query rejection is perform as part of PQS lookup.
This is not inherently bad, however, during the current implementation of lookup, no access to Pipeline and parsed DocumentSources is present. In order to check if the aggregate query shape is eligible for rejection, new helper method is introduced to the ExpressionContext. DocumentSources also do not have a "isSystemStage()" method. All of these reasons made PQS have deep understanding of which stages are non-rejectable.
In order to avoid this coupling one could:
- Introduce a new class (e.g. QueryRejector), which would take aggregation Pipeline as input (and no input for find and distinct) and would reject if eligible
- Introduce a new method to DocumentSource isSystemStage() and overload this method to return true to the known system stages
e.g. code:
AggCmd::run() { // ... auto deferredShape = ...; auto settings = query_settings::lookup(expCtx, deferredShape()); QueryRejector rejector(settings, aggPipeline); ... } class QueryRejector { QueryRejector(const QuerySettings& settings, Pipeline* pipeline) { if (!settings.reject()) return; uassert(RejectErrorCode, "queryRejected", pipeline.at(0).isSystemStage()); } };
This could later be evolved into query rate limiter per query shape, if needed (PQS feature proposal), where the rejector interface could be extended to:
class QueryRateLimiter {
QueryRateLimiter(...) { incrementOrFail(...) }
~QueryRateLimiter() { decrement() }
};