-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added drizzle_return_error_code and drizzle_no_log_error_codes directives #7
base: master
Are you sure you want to change the base?
Conversation
Hey Marcus,
|
Hi, In response, I'll do them in reverse order :
If I missed something, then great. Do I need to change a setting somewhere to get it to return the error code and message? Also, importantly though, is the logging issue. It appears that errors will be logged regardless. For most errors, of course you'd probably want this, but for duplicate keys I don't. I want to know why it fails, but not log the fact. If there's another way to turn off the logging of errors, too, then please let me know, but I didn't see anything in the code.
Overall, I would personally like the option of returning the error codes / messages as JSON (with the default being on, probably), with the option to also just return the code. Marcus. |
Hi, However, I still don't like returning values outside of the usual HTTP response codes range. There are at least few ways to solve this in more elegant way:
btw: I don't have anything against your logging changes. |
Hi ya, Yes - I'd skim-read the rds_json_ret stuff too, hence my surprise when I got no return at all from them.
I understand your point of not wanting to send responses outside the normal HTTP responses. I think it's inappropriate to send it out over the Internet with a non-standard code. However, I'm proposing the use of DB error codes soley for 'internal' use, and I'm thinking primarily with ngx_lua, but it could also with other internal solutions. Given that there most definitely wouldn't be a conflict in the response codes with those of HTTP (and given that anyone that knows anything about the HTTP protocol is going to know that a response code of e.g. 1062 has nothing to do with HTTP), I don't really think that it'd be very confusing or a bad thing to do. It's efficient, and would need to be turned on by the developer anyway. Cheers, Marcus. |
To summarize, I would prefer to see solution 1) or 2) instead of the proposed one. |
btw: |
I think I would prefer to have the option of both 1, 2 and just returning the code as I've done (perhaps with the addition of putting the error message as the status message too - something I'm sure you don't find appealing :-P). Yes, I'd noticed that 410 had already gone (no pun intended). |
Anyway, since you clearly want to use this only internally, why are you insisting on sending this as the HTTP response code (which is breaking format of HTTP response defined in RFC2616)? |
I think the error info should be returned in the response body somehow, perhaps emitting JSON directly or as plain text. I am not insisting on sending it as an HTTP response code, but I am proposing that it be an optional way of retrieving the response code. I personally like the idea of sending it as an HTTP response code because (a) it's efficient, and (b) I think that given that the HTTP request is basically a wrapper for the database call, that it doesn't matter too much and has a certain elegance. The most important thing for me is to be able to retrieve the response code from Drizzle, and it seems to me that this is the most efficient way of doing so (because there's no overhead of creating then parsing JSON or text or whatever). Oh, and I like to break rules when I see a good reason for it. ;-) |
I prefer an nginx output variable for this purpose :) Now there's already an undocumented nginx variable $drizzle_thread_id for outputing the mysql thread id. And we usually use a custom response header to pass this information out. |
Are you ok with the logging changes? |
I'm fine with the capability to suppress logging the drizzle error codes that the user specify :) |
Suppressing logging may not be sufficient for your purpose though. Maybe you'd also want those errors to be discarded in context of keepalive database connections? That is, for those drizzle error codes, also leave the connection intact such that they can be reused by other requests later. ngx_drizzle now already does something similar for the "table not exist" error: it will use the info log level for the error message and do not abandon the current mysql connection. |
Ok. I hadn't thought about that yet. I've only done ngx_lua subrequests to MySQL thus far, but I will almost certainly have AJAX -> MySQL requests at some stage. Do you think the return code should be 200, and then just leave it up to the client to parse the headers to check for errors? |
I think we should follow the traditional definition of HTTP status code, just as what Piotr says earlier :) We've already extended it to 410 Gone to mean the mysql table missing error and we can go a bit further with that but no amazing magic ;) |
Well, the thing is that if the user has specified that certain error codes are to be ignored, then should we return an HTTP error code, or success code? I have two thoughts on this:
Personally I think that option 1 is probably better here. Looking through the MySQL error codes, though (I didn't get through all of them, just the first few hundred or so), I don't think there will be many of them that users will be interested in individually on a regular basis, so it might be OK to 'map' a few common DB error codes that users might want to ignore to HTTP ones. If we just choose an HTTP code for key-already-exists situations, then I'm ok with that (see suggestions below). I think also by default, that key-already-exists errors shouldn't be logged. I think that in most situations where INSERTs fail because of this, it's because the user is choosing something like a name that already exists, and in general, you probably wouldn't want to log this. We'll make the error code and message both available as variables. Btw, I don't think that 410 is the best code to use for a MySQL table not existing. According to RFC 2616, the HTTP code means that a resource is no longer available (i.e. that it was available in the past, which isn't necessarily the case), and won't be in the future (which also may not be the case). I think 404 makes much more sense, since it may or may not have existed in the past and may exist in the future. Even having a different 4xx number to existing ones, with no established meaning, makes more sense than 410 (if you're wanting to follow the meaning of HTTP codes). To me what would make more sense would be to use the following return codes: 404 (Table does not exist) I am, however, guessing though that you won't want to change the usage of 410 so as not to break existing setups. Assuming that this is the case, how about this: 409 (Conflict) - key-already-exists situations, since the key was available in the past, but it isn't now and won't be in the future And we change the 'drizzle_ignore_error_codes' directive to something that indicates that it's providing an input error, e.g. 'drizzle_input_error_codes'. Does that work for you guys? |
I do like your second suggestion for the status code mapping ;) |
Ok. I'll get that done soonish. |
nginx的drizzle中,获取(查询)多个列值时报错如下 在ngx_http_upstream_drizzle_recv_cols函数中调用drizzle_column_free报错!两次释放同一地址。 |
@lizhitao67116961 please do not post Chinese text on all my GitHub issues boards. I'd make GitHub a pure English place for my projects. You can join the openresty (Chinese) mailing list and discuss the issue in Chinese there: https://groups.google.com/group/openresty Thank you for your understanding and cooperation. |
Hi,
I've added the mentioned two directives and comments to the module. These allow you to return the drizzle error code rather than 500 when there are errors (e.g. so you can process them inside ngx_lua), and allows you to suppress logging for specific error codes (e.g. 1062 for duplicate keys on inserts).
Cheers,
Marcus.