From: Naoki Kambe Date: Fri, 14 Dec 2012 07:32:58 +0000 (+0900) Subject: [2225_statistics] synchronize when accessing self._disabled X-Git-Tag: bind10-1.1.0beta1-release~72^2~40^2~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aa70659de52c486695a6fc822b673adf51a2abcf;p=thirdparty%2Fkea.git [2225_statistics] synchronize when accessing self._disabled And timer cannot be updated if self._disabled is true. Due to the review comment. --- diff --git a/src/lib/python/isc/statistics/counter.py b/src/lib/python/isc/statistics/counter.py index bfc235f64b..81350978ad 100644 --- a/src/lib/python/isc/statistics/counter.py +++ b/src/lib/python/isc/statistics/counter.py @@ -277,11 +277,13 @@ class Counters(): def disable(self): """disables incrementing/decrementing counters""" - self._disabled = True + with self._rlock: + self._disabled = True def enable(self): """enables incrementing/decrementing counters""" - self._disabled = False + with self._rlock: + self._disabled = False def inc(self, *args): """A incrementer for per-zone counter. Locks the thread @@ -291,8 +293,8 @@ class Counters(): file.""" identifier = '/'.join(args) step = 1 - if self._disabled: return with self._rlock: + if self._disabled: return _inc_counter(self._statistics._data, self._statistics._spec, identifier, step) @@ -305,8 +307,8 @@ class Counters(): file.""" identifier = '/'.join(args) step = -1 - if self._disabled: return with self._rlock: + if self._disabled: return _inc_counter(self._statistics._data, self._statistics._spec, identifier, step) @@ -322,7 +324,9 @@ class Counters(): """Sets the value returned from _start_timer() as a value of the identifier in the self._start_time which is dict-type""" identifier = '/'.join(args) - isc.cc.data.set(self._start_time, identifier, _start_timer()) + with self._rlock: + if self._disabled: return + isc.cc.data.set(self._start_time, identifier, _start_timer()) def stop(self, *args): """Sets duration time between corresponding time in @@ -333,24 +337,26 @@ class Counters(): nothing. But in case of stopping the time which isn't defined in the spec file, it raises DataNotFoundError""" identifier = '/'.join(args) - try: - start_time = isc.cc.data.find(self._start_time, - identifier) - except isc.cc.data.DataNotFoundError: - # do not set the end time if the timer isn't started - pass - else: - # set the end time - _stop_timer( - start_time, - self._statistics._data, - self._statistics._spec, - identifier) - # delete the started timer - del isc.cc.data.find( - self._start_time, - '/'.join(identifier.split('/')[0:-1]))\ - [identifier.split('/')[-1]] + with self._rlock: + if self._disabled: return + try: + start_time = isc.cc.data.find(self._start_time, + identifier) + except isc.cc.data.DataNotFoundError: + # do not set the end time if the timer isn't started + pass + else: + # set the end time + _stop_timer( + start_time, + self._statistics._data, + self._statistics._spec, + identifier) + # delete the started timer + del isc.cc.data.find( + self._start_time, + '/'.join(identifier.split('/')[0:-1]))\ + [identifier.split('/')[-1]] def dump_statistics(self): """Calculates an entire server counts, and returns statistics