From 830653a4496b30dd535a14c6c9ec93c856f49ead Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Mon, 20 Oct 2008 22:41:59 +0000 Subject: [PATCH] Don't let us create a percentiler with an insane range, and carp if we expand to one. I'm half tempted to also try and cap the range to something less broken, but the bug I had that caused insanity involved recording a value of infinity, and there's not a hell of a lot I can do to sanely recover in that case (other than throw it away, I suppose). So let's yell a little bit and keep from hosing us quite as much as I was when I wound up with crazy stuff persisted to my ratings table. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@761 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../parlor/rating/util/Percentiler.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/java/com/threerings/parlor/rating/util/Percentiler.java b/src/java/com/threerings/parlor/rating/util/Percentiler.java index 87e6a8a9..832dd370 100644 --- a/src/java/com/threerings/parlor/rating/util/Percentiler.java +++ b/src/java/com/threerings/parlor/rating/util/Percentiler.java @@ -79,6 +79,14 @@ public class Percentiler _min = in.asIntBuffer().get(); } + // Un-break percentilers that have been stored with bogus data + if (_max < _min) { + log.warning("Percentiler initialized with bogus range. Coping.", + "min", _min, "max", _max); + + _max = _min + 1; + } + // compute our percentiles recomputePercentiles(); } @@ -107,17 +115,27 @@ public class Percentiler // if this value is outside our bounds, we need to redistribute our buckets if (value < _min || value > _max) { if (_fixedRange) { - log.warning("Recording value outside of initially fixed range", "min", _min, - "max", _max, "value", value); + log.warning("Recording value outside of initially fixed range", + "min", _min, "max", _max, "value", value); _fixedRange = false; } + // expand by 20% in the direction of either our new minimum or new maximum int newmin = (value < _min) ? (_max - (int)Math.ceil((_max - value) * 1.2f)) : _min; int newmax = (value > _max) ? (_min + (int)Math.ceil((value - _min) * 1.2f)) : _max; + if (newmin > _min || newmax < _max) { + log.warning("Grew our range in crazy ways?!", + "value", value, "total", _total, + "new", ("" + newmin + ":" + newmax), + "old", ("" + _min + ":" + _max)); + } + if (logNewMax) { - log.info("Resizing [total=" + _total + ", new=" + newmin + ":" + newmax + - ", old=" + _min + ":" + _max + "]."); + log.info("Resizing", + "value", value, "total", _total, + "new", ("" + newmin + ":" + newmax), + "old", ("" + _min + ":" + _max)); } // create a new counts array and map the old array to the new