Mongo-java-driver exception handling
-
I recently saw this line inside the mongodb java driver:
Does anyone know any good reason for that line there?
-
Hey, I hang around /r/shittyprogramming too!
They seemed to have worked out that since that's logging code, it's supposed to not log it 90% of the time to keep the log file from filling up.
-
They are attempting to reduce the volume of logging output by only sampling a tenth of the failures.
-
Secondary WTF: using the ternary operator to obfuscate a simple OR.
-
@Planar said:
Secondary WTF: using the ternary operator to obfuscate a simple OR.
Holy shit, that's awful.
I also like the "let's log randomly every tenth time". So if you have a few errors, chances are you'll never see them? Dammit, people, this is a solve problem.
-
I think this code actually means: There is no such thing as only a few errors.
-
@sztupy said:
I think this code actually means: There is no such thing as only a few errors.
Indeed, this seems to be saying "if there are errors then there will be a lot of errors."
-
That's useful. This way if the developer needs to push out a new release and wants to pad the release notes, he can just change the magic number "0.1" to something else and claim to have "significantly reduced exceptions generated by UpdatableNode".
It's like a speedup loop for database errors.
-
Re: mongo-java-driver exception handling: At least look at what it does
The fact that most other posters got the effect of that line wrong, tell you why you should not write that code. Lets look at it:
(!((_ok) ? true : (Math.random() > 0.1)))
The () around _ok, is confusing so let's remove them. That gives us:
if(!(_ok ? true : (Math.random() > 0.1))) which is easy to parse.
The statement in () is true if either ok is true, or with a random change of 90%
Finally this statement is reversed. So the result is that it log all statements where _ok is false, and 10% of all other statements.
It should have been written as:
if(!_ok || Math.random() > 0.1)
with a comment explaining that the random is to only log 1/10 of non error statements. and the ! is most likely a mistake. Or I should go to bed.
The test would make much more sense if true in the original line was false. Seems like a bug.
-
@mt@ilovefactory.com said:
The fact that most other posters got the effect of that line wrong, tell you why you should not write that code.
Where are you seeing this?
-
Well, some people are saying this only logs 10% of failures.
But after some cursory analysis it seems to me what is happening is it logs all failures, except 10% of failures from
res.get("maxBsonObjectSize");
But the code is written in a really contrived way.
Edit: wait, no, this thing is returning res 90% of the times _ok is false and logging an error otherwise. WTF?
See, this is what happens when you don't write your conditions in a sane way.
-
@MiffTheFox said:
Hey, I hang around /r/shittyprogramming too!
@Websense said:
This Websense category is filtered: Adult Content.
Oh fuck off Websense. I can get to /r/dragonsfuckingcars but I can't go to /r/shittyprogramming?
-
@Adanine said:
@MiffTheFox said:
Hey, I hang around /r/shittyprogramming too!
@Websense said:
This Websense category is filtered: Adult Content.
Oh fuck off Websense. I can get to /r/dragonsfuckingcars but I can't go to /r/shittyprogramming?
Maybe ramming is a bad word
-
@Adanine said:
@MiffTheFox said:
Hey, I hang around /r/shittyprogramming too!
@Websense said:
This Websense category is filtered: Adult Content.
Oh fuck off Websense. I can get to /r/dragonsfuckingcars but I can't go to /r/shittyprogramming?
What
the
christ.
-
@drurowin said:
@Adanine said:
/r/dragonsfuckingcars
What
the
christ.
There is no Christ here. Only.. empty.
-
@morbiuswilters said:
@drurowin said:
There isn't even empty. I've got an image of a dragon fucking a character from the movies Cars and Cars 2 forever burned in my retinas. I'm going to have to fucking go take some Thorazine and curl up in the foetal position for about a week before I can fucking function again.@Adanine said:
/r/dragonsfuckingcars
What
the
christ.
There is no Christ here. Only.. empty.
-
@drurowin said:
@Adanine said:
@MiffTheFox said:
Hey, I hang around /r/shittyprogramming too!
@Websense said:
This Websense category is filtered: Adult Content.
Oh fuck off Websense. I can get to /r/dragonsfuckingcars but I can't go to /r/shittyprogramming?
What
the
christ.
-
@MiffTheFox said:
@drurowin said:
@Adanine said:
@MiffTheFox said:
Hey, I hang around /r/shittyprogramming too!
@Websense said:
This Websense category is filtered: Adult Content.
Oh fuck off Websense. I can get to /r/dragonsfuckingcars but I can't go to /r/shittyprogramming?
What
the
christ.
No! Simply... No!
-
Well, my work here is done.
-
@morbiuswilters said:
@drurowin said:
@Adanine said:
/r/dragonsfuckingcars
What
the
christ.
There is no Christ here. Only.. empty.
I want to join the church of the holy empty
-
@Ben L. said:
Filed under: maybe it's empty because it's holey
<a href='http://www.reddit.com/r/3amjokes/">You'd like it here
-
@Adanine said:
@Ben L. said:
Filed under: maybe it's empty because it's holey
You'd like it here"Did you hear about the red ship and the blue ship that collided?"
"Both crews were marooned."
No, asshole, maroon is not red-plus-blue. If anything, it's red-plus-brown.
-
@morbiuswilters said:
red
@morbiuswilters said:blue
@morbiuswilters said:maroon
@morbiuswilters said:red-plus-blue
@morbiuswilters said:red-plus-brown
THAT'S RACIST
-
@drurowin said:
I've got an image of a dragon fucking a character from the movies Cars and Cars 2 forever burned in my retinas. I'm going to have to fucking go take some Thorazine and curl up in the foetal position for about a week before I can fucking function again.
Also, who the hell watched Cars 2? I'm calling bluff.
-
@mt@ilovefactory.com said:
It should have been written as:
Either that or someone really needs to look at the number of errors being produced. Perhaps if they reduced the number of problems that the poor system is trying to report in the first place (instead of just throwing them away) they'd make MondoDB even more webscale!if(!_ok || Math.random() > 0.1)
with a comment explaining that the random is to only log 1/10 of non error statements.
-
-
@morbiuswilters said:
Filed under: I take colored jokes very seriously.
I was having a bath (blue, blue, blue...) when suddenly the phone rang. (green, green, green...)I ran to answer it. "Yellow?"
But I got there too late, so I just put the phone black brown. (pink!)
I don 't remember where I red this story oranginally, but I admit it's gettin gold.
-
At least this explains the name of the product which always got me wondering why you would call it that way. I think it is supposed to characterize the developer(s).
mongo = retard
in my language. no Joke.
-
@MiffTheFox said:
Hey, I hang around /r/shittyprogramming too!
They seemed to have worked out that since that's logging code, it's supposed to not log it 90% of the time to keep the log file from filling up.
Thank for for directing me to that subreddit. Now I feel like I need to go bath my brain in alcohol to get rid of that stupidity now lodged in there.
-
@Zecc said:
I was having a bath (blue, blue, blue...) when suddenly the phone rang. (green, green, green...)
I interpreted that as "I was having a bath, and the water was blue. Then the phone rang, and the water turned green!" the first time through.