[SERVER-37250] Ban use of $out with read preferences other than "primary" Created: 21/Sep/18 Updated: 03/Jun/19 Resolved: 06/Nov/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Nicholas Zolnierz | Assignee: | Devin Hilly (Inactive) |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Sprint: | Query 2018-10-22, Query 2018-11-05, Query 2018-11-19 | ||||||||
| Participants: | |||||||||
| Description |
|
Aggregations with a $out stage fail when issued to a secondary on a replica set because we do not currently support reading from a primary and writing to a secondary. While this was always the case, with the new $out modes, we are now able to issue a $out to a secondary on a sharded cluster because we use the ClusterWriter. Though this is a nice feature, the behavior is not consistent between replica sets and sharded clusters. To provide consistency, we should ban reading from a secondary when the aggregation contains a $out stage. As connecting to a secondary is almost always achieved by setting readPreference to something other than "primary" (ie. "secondary", "secondaryPreferred", "primaryPreferred", or "nearest"), we should prohibit this combination. We should also clean up the error message issued to the user when they do connect directly with the secondary. |
| Comments |
| Comment by Devin Hilly (Inactive) [ 06/Nov/18 ] |
|
Decided not to fix this. The undesired behavior - honoring readPreference in an aggregation with a $out - would only ever happen if there were a bug in the shell or the driver issuing the aggregation. Though there is such a bug in PyMongo ( |
| Comment by Asya Kamsky [ 30/Oct/18 ] |
|
We might need to sync up to make sure we agree on what a consistent way to do this is. on a replica set, we can simply detect that an aggregate with $out is about to run on a secondary node and fail it with a nice error message. however, we cannot do that in a sharded cluster since secondaries won't see the full pipeline, so the error has to be issued by mongos when it gets an aggregate with $out and readPreference secondary yes? Any other read preference can be ignored in favor of routing the aggregation to primaries as any other write command. Does that seem correct?
|
| Comment by Asya Kamsky [ 30/Oct/18 ] |
|
Note that driver spec already says that drivers should notice when aggregate has $out and direct it to primary regardless of read preference. However not all drivers seemed to have implemented it. The shell does implement it. Though not for "explain" |