summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEamonn O'Toole <eamonn.otoole@hp.com>2014-04-29 15:04:42 +0100
committerEamonn O'Toole <eamonn.otoole@hp.com>2014-04-29 17:21:00 +0100
commitbcdafa3831111f334caadd30505f051c81abcb1f (patch)
tree12cdc6644860e65aced27271e55b5aa295ea4ba1
parent032f0bfc7c6754afbad1bf8de7a4a6fde8d5cee0 (diff)
downloadswift-bcdafa3831111f334caadd30505f051c81abcb1f.tar.gz
Sleep between object ZBF process forks
We've found that, on fresh systems where the ZBF run completes almost instantaneously, the Swift logs (syslog by default) get filled-up with object ZBF scan start and completion messages. This patch calls self._sleep() between ZBF scan runs to cut-down on these messages and the related unnecessary ZBF scan runs without impacting the integrity of the object auditing process. Change-Id: I057c5ca235467cfa115a7a3d44e21c350900059a
-rw-r--r--swift/obj/auditor.py2
-rw-r--r--test/unit/obj/test_auditor.py22
2 files changed, 20 insertions, 4 deletions
diff --git a/swift/obj/auditor.py b/swift/obj/auditor.py
index 177cfe0c5..13d34c18c 100644
--- a/swift/obj/auditor.py
+++ b/swift/obj/auditor.py
@@ -279,6 +279,8 @@ class ObjectAuditor(Daemon):
if self.conf_zero_byte_fps and pid == zbf_pid and \
len(pids) > 1:
kwargs['device_dirs'] = override_devices
+ # sleep between ZBF scanner forks
+ self._sleep()
zbf_pid = self.fork_child(zero_byte_fps=True, **kwargs)
pids.append(zbf_pid)
pids.remove(pid)
diff --git a/test/unit/obj/test_auditor.py b/test/unit/obj/test_auditor.py
index ada6e3125..ea14540bd 100644
--- a/test/unit/obj/test_auditor.py
+++ b/test/unit/obj/test_auditor.py
@@ -440,9 +440,12 @@ class TestAuditor(unittest.TestCase):
if 'zero_byte_fps' in kwargs:
self.check_device_dir = kwargs.get('device_dirs')
- def mock_sleep(self):
+ def mock_sleep_stop(self):
raise StopForever('stop')
+ def mock_sleep_continue(self):
+ return
+
def mock_audit_loop_error(self, parent, zbo_fps,
override_devices=None, **kwargs):
raise Bogus('exception')
@@ -469,12 +472,12 @@ class TestAuditor(unittest.TestCase):
real_audit_loop = my_auditor.audit_loop
my_auditor.audit_loop = mocker.mock_audit_loop_error
my_auditor.run_audit = mocker.mock_run
- my_auditor._sleep = mocker.mock_sleep
was_fork = os.fork
was_wait = os.wait
os.fork = mocker.mock_fork
os.wait = mocker.mock_wait
try:
+ my_auditor._sleep = mocker.mock_sleep_stop
my_auditor.run_once(zero_byte_fps=50)
my_auditor.logger.exception.assert_called_once_with(
'ERROR auditing: exception')
@@ -489,10 +492,10 @@ class TestAuditor(unittest.TestCase):
self.assertEquals(mocker.check_kwargs['zero_byte_fps'], 50)
self.assertEquals(mocker.fork_called, 0)
- self.assertRaises(SystemExit, my_auditor.run_forever)
+ self.assertRaises(SystemExit, my_auditor.run_once)
self.assertEquals(mocker.fork_called, 1)
self.assertEquals(mocker.check_kwargs['zero_byte_fps'], 89)
- self.assertEquals(mocker.check_device_dir, None)
+ self.assertEquals(mocker.check_device_dir, [])
self.assertEquals(mocker.check_args, ())
device_list = ['sd%s' % i for i in string.ascii_letters[2:10]]
@@ -510,6 +513,17 @@ class TestAuditor(unittest.TestCase):
mocker.fork_called = 0
self.assertRaises(StopForever, my_auditor.run_forever)
+ # Fork is called 2 times since the zbf process is forked just
+ # once before self._sleep() is called and StopForever is raised
+ # Also wait is called just once before StopForever is raised
+ self.assertEquals(mocker.fork_called, 2)
+ self.assertEquals(mocker.wait_called, 1)
+
+ my_auditor._sleep = mocker.mock_sleep_continue
+
+ mocker.fork_called = 0
+ mocker.wait_called = 0
+ my_auditor.run_once()
# Fork is called 3 times since the zbf process is forked twice
self.assertEquals(mocker.fork_called, 3)
self.assertEquals(mocker.wait_called, 3)