diff --git a/lib/backend.py b/lib/backend.py index 2d7f63a48449640961b7a5ceca4c7699332dc9b0..55aae5ddb1937fd1f4dca2d31504b35c6ac641b4 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -1990,7 +1990,7 @@ def JobQueueRename(old, new): if not (_IsJobQueueFile(old) and _IsJobQueueFile(new)): return False - os.rename(old, new) + utils.RenameFile(old, new, mkdir=True) return True diff --git a/lib/jqueue.py b/lib/jqueue.py index 3734476070fca51806ad0fcc8662434a09b0e125..084368eb3c70713a51dd13568a0f02c0658d5863 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -49,6 +49,7 @@ from ganeti import rpc JOBQUEUE_THREADS = 25 +JOBS_PER_ARCHIVE_DIRECTORY = 10000 class CancelJob(Exception): @@ -714,7 +715,7 @@ class JobQueue(object): @param new: the new name of the file """ - os.rename(old, new) + utils.RenameFile(old, new, mkdir=True) names, addrs = self._GetNodeIp() result = rpc.RpcRunner.call_jobqueue_rename(names, addrs, old, new) @@ -741,6 +742,18 @@ class JobQueue(object): return str(job_id) + @classmethod + def _GetArchiveDirectory(cls, job_id): + """Returns the archive directory for a job. + + @type job_id: str + @param job_id: Job identifier + @rtype: str + @return: Directory name + + """ + return str(int(job_id) / JOBS_PER_ARCHIVE_DIRECTORY) + def _NewSerialUnlocked(self): """Generates a new job identifier. @@ -774,8 +787,8 @@ class JobQueue(object): """ return os.path.join(constants.QUEUE_DIR, "job-%s" % job_id) - @staticmethod - def _GetArchivedJobPath(job_id): + @classmethod + def _GetArchivedJobPath(cls, job_id): """Returns the archived job file for a give job id. @type job_id: str @@ -784,7 +797,8 @@ class JobQueue(object): @return: the path to the archived job file """ - return os.path.join(constants.JOB_QUEUE_ARCHIVE_DIR, "job-%s" % job_id) + path = "%s/job-%s" % (cls._GetArchiveDirectory(job_id), job_id) + return os.path.join(constants.JOB_QUEUE_ARCHIVE_DIR, path) @classmethod def _ExtractJobID(cls, name):