From ad9ff386278ec399c4f78f81e2a921c61fbe5840 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Tue, 3 Sep 2024 20:04:44 +0530 Subject: [PATCH] mgr/vol: better to call base class __init__() at beginning It is a good practice and a common convention to call base class's __init__() method at the beginning of derived class's __init__(). It ensures proper initialization of base class's attributes and methods. Signed-off-by: Rishabh Dave --- src/pybind/mgr/volumes/fs/async_cloner.py | 3 ++- src/pybind/mgr/volumes/fs/async_job.py | 4 +++- src/pybind/mgr/volumes/fs/purge_queue.py | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/async_cloner.py b/src/pybind/mgr/volumes/fs/async_cloner.py index 463c1000596..1525f57c3f8 100644 --- a/src/pybind/mgr/volumes/fs/async_cloner.py +++ b/src/pybind/mgr/volumes/fs/async_cloner.py @@ -313,6 +313,8 @@ class Cloner(AsyncJobs): the driver. file types supported are directories, symbolic links and regular files. """ def __init__(self, volume_client, tp_size, snapshot_clone_delay, clone_no_wait): + super(Cloner, self).__init__(volume_client, "cloner", tp_size) + self.vc = volume_client self.snapshot_clone_delay = snapshot_clone_delay self.snapshot_clone_no_wait = clone_no_wait @@ -323,7 +325,6 @@ class Cloner(AsyncJobs): SubvolumeStates.STATE_FAILED : handle_clone_failed, SubvolumeStates.STATE_CANCELED : handle_clone_failed, } - super(Cloner, self).__init__(volume_client, "cloner", tp_size) def reconfigure_max_concurrent_clones(self, tp_size): return super(Cloner, self).reconfigure_max_async_threads(tp_size) diff --git a/src/pybind/mgr/volumes/fs/async_job.py b/src/pybind/mgr/volumes/fs/async_job.py index 6834e3e240b..d8c0d0a3fbc 100644 --- a/src/pybind/mgr/volumes/fs/async_job.py +++ b/src/pybind/mgr/volumes/fs/async_job.py @@ -19,11 +19,12 @@ class JobThread(threading.Thread): MAX_RETRIES_ON_EXCEPTION = 10 def __init__(self, async_job, volume_client, name): + threading.Thread.__init__(self, name=name) + self.vc = volume_client self.async_job = async_job # event object to cancel jobs self.cancel_event = threading.Event() - threading.Thread.__init__(self, name=name) def run(self): retries = 0 @@ -117,6 +118,7 @@ class AsyncJobs(threading.Thread): def __init__(self, volume_client, name_pfx, nr_concurrent_jobs): threading.Thread.__init__(self, name="{0}.tick".format(name_pfx)) + self.vc = volume_client # queue of volumes for starting async jobs self.q = deque() # type: deque diff --git a/src/pybind/mgr/volumes/fs/purge_queue.py b/src/pybind/mgr/volumes/fs/purge_queue.py index abace19d029..8917b475ac6 100644 --- a/src/pybind/mgr/volumes/fs/purge_queue.py +++ b/src/pybind/mgr/volumes/fs/purge_queue.py @@ -103,9 +103,10 @@ class ThreadPoolPurgeQueueMixin(AsyncJobs): _all_ threads purging entries for one volume (starving other volumes). """ def __init__(self, volume_client, tp_size): - self.vc = volume_client super(ThreadPoolPurgeQueueMixin, self).__init__(volume_client, "purgejob", tp_size) + self.vc = volume_client + def get_next_job(self, volname, running_jobs): return get_trash_entry_for_volume(self.fs_client, self.vc.volspec, volname, running_jobs) -- 2.39.5