Using DruidExceptions in MSQ (changes related to the Broker)#14534
Using DruidExceptions in MSQ (changes related to the Broker)#14534LakshSingla merged 16 commits intoapache:masterfrom
Conversation
somu-imply
left a comment
There was a problem hiding this comment.
Looks good. Minor nits
| .build( | ||
| e, | ||
| "Unable to deserialize the insert granularity. Please retry the query with a " | ||
| + "valid segment graularity" | ||
| ); |
There was a problem hiding this comment.
This message reads to me like it's trying to get to the end user, but a defensive exception is something that we expect to never happen (because the code doesn't allow it) and therefore it faces the developer. Given this message, are you sure that this isn't an InvalidSqlInput?
There was a problem hiding this comment.
This would only be thrown if we can't serialize one of the objects predefined in the code which we are sure would get serialized. (Handles the jsonMapper.writeValueAsString throw clause). We never intend to encounter this exception, and if we do, there's something wrong with the code. Updated the error message to indicate this.
| throw InvalidInput.exception( | ||
| "%s cannot be less than 2 since at least 1 controller and 1 worker is necessary.", | ||
| MultiStageQueryContext.CTX_MAX_NUM_TASKS | ||
| ); |
There was a problem hiding this comment.
This message doesn't follow our conventions for how to write error messages or interpolate things. Please read style-conventions.md and adjust.
In this case, I would probably suggest
"MSQ context maxNumTasks [%,d] cannot be less than 2, since at least 1 controller and 1 worker is necessary"
| throw DruidException.forPersona(DruidException.Persona.DEVELOPER) | ||
| .ofCategory(DruidException.Category.DEFENSIVE) | ||
| .build("Cannot INSERT with destination [%s]", ctxDestination); |
There was a problem hiding this comment.
This message again doesn't seem defensive, it seems like it's intended for the end-user and should be InvalidSqlInput no?
| throw DruidException.forPersona(DruidException.Persona.DEVELOPER) | ||
| .ofCategory(DruidException.Category.DEFENSIVE) | ||
| .build("Unable to convert %s to a segment granularity", segmentGranularity); |
There was a problem hiding this comment.
This is throwing away the Exception e so we will never be able to figure out why we were unable to convert the value. It also doesn't follow our conventions for how to write and interpolate messages and I'm not sure that it's truly defensive?
There was a problem hiding this comment.
Good point on keeping the exception. I updated the exception message to state why this is a defensive exception.
This parameter is added by Druid while processing PARTITIONED BY _____. User inputs whatever is in front of the partitioned by we populate the query context based on that. Therefore whatever hits this exception has been sanitized and populated by us (after already going through a transformation-serialization process). We don't ever wish to encounter this in a normal misinput situation, any exception or incorrect input from the user would have been flagged by the SQL parser or while serializing.
| ) | ||
| ) | ||
| InvalidInput.exception( | ||
| "The statement sql api only supports sync mode[%s]. Please set context parameter [%s=%s] in the context payload", |
There was a problem hiding this comment.
I'm not sure I know what the statement sql api is? If it's only supposed to be one thing and this code knows what that one thing is and the user got their request to this line of the code, why does the user need to change their query to only do the one thing that this code can do? I.e. why not just ignore the context parameter entirely? Or overwrite it with the one value that this code can do?
There was a problem hiding this comment.
Since the sql statement api will support the sync mode soon, I wanted the user to set the flag explicitly.
Rolling upgrades then become easy since we donot have a default mode/overridden mode.
The mode also changes the way the results are fetched.
If the mode set is async, the results are fetched via the results api.
If the mode set is sync, then the results are streamed back in the same post request. (At-least, that's how I envision it. )
There was a problem hiding this comment.
I went through the code, and ExecutionMode is currently unused. I have left it as is since I am not aware if it will be utilized later, however, I changed the exception to defensive since this parameter isn't supported, unset, and not documented, therefore it shouldn't have been set.
(cc @cryptoe, I can clean this up in case we can remove the class)
There was a problem hiding this comment.
Its used in SqlStatementResource#contextChecks
|
@imply-cheddar Thanks a lot for the review, I have revised the PR with the changes, and better exception messages. |
cryptoe
left a comment
There was a problem hiding this comment.
Left some nit's.
LGTM otherwise.
…14534) MSQ engine returns correct error codes for invalid user inputs in the query context. Also, using DruidExceptions for MSQ related errors happening in the Broker with improved error messages.
…14534) MSQ engine returns correct error codes for invalid user inputs in the query context. Also, using DruidExceptions for MSQ related errors happening in the Broker with improved error messages.
Description
Most of the places in MSQ currently rely on the older error code, dating pre #14004. This is an attempt to fix the bits of the error code in the places where bits of MSQ reside in the broker. This extends upon the PR #14531.
maxNumTasksto 1 would return a 500 error code, which is not right since its an invalid user input. This was the original behavior, and this PR changes that.Note: This PR doesn't unify the DruidExceptions with the MSQException
Release note
MSQ engine returns correct error codes for invalid user inputs in the query context
This PR has: