]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/vol: reuse code for spawning threads
authorRishabh Dave <ridave@redhat.com>
Mon, 16 Sep 2024 09:16:45 +0000 (14:46 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 24 Oct 2024 13:51:33 +0000 (19:21 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/pybind/mgr/volumes/fs/async_job.py

index 83a119ca5564ccd20d1e3ca01e1ebee8041b8d3a..0f63889cd532850c6feee4e37b87127761cf77f5 100644 (file)
@@ -137,10 +137,17 @@ class AsyncJobs(threading.Thread):
 
         self.threads = []
         for i in range(self.nr_concurrent_jobs):
-            self.threads.append(JobThread(self, volume_client, name="{0}.{1}".format(self.name_pfx, i)))
-            self.threads[-1].start()
+            self.spawn_new_thread(i)
         self.start()
 
+    def spawn_new_thread(self, suffix):
+        t_name = f'{self.name_pfx}.{time.time()}.{suffix}'
+        log.debug(f'spawning new thread with name {t_name}')
+        t = JobThread(self, self.vc, name=t_name)
+        t.start()
+
+        self.threads.append(t)
+
     def set_wakeup_timeout(self):
         with self.lock:
             # not made configurable on purpose
@@ -165,8 +172,7 @@ class AsyncJobs(threading.Thread):
                     # Increase concurrency: create more threads.
                     log.debug("creating new threads to job increase")
                     for i in range(c, self.nr_concurrent_jobs):
-                        self.threads.append(JobThread(self, self.vc, name="{0}.{1}.{2}".format(self.name_pfx, time.time(), i)))
-                        self.threads[-1].start()
+                        self.spawn_new_thread(i)
                 self.cv.wait(timeout=self.wakeup_timeout)
 
     def shutdown(self):