Commit c4beba1c authored by Iustin Pop's avatar Iustin Pop
Browse files

Make the job storage init reuse a serial file

This will be needed for master failover. If we don't have a valid queue
directory, we need to reinitialize it, but we should keep the existing
serial number.

As such, we abstract the reading of the serial and if we find a valid
serial, we do not reset it.

Reviewed-by: imsnah
parent 42ff3343
......@@ -309,12 +309,31 @@ class JobStorage(object):
finally:
version_fd.close()
serial_fd = open(constants.JOB_QUEUE_SERIAL_FILE, "r")
self._last_serial = self._ReadSerial()
if self._last_serial is None:
raise errors.ConfigurationError("Can't read/parse the job queue serial"
" file")
@staticmethod
def _ReadSerial():
"""Try to read the job serial file.
@rtype: None or int
@return: If the serial can be read, then it is returned. Otherwise None
is returned.
"""
try:
# Read last serial
self._last_serial = int(serial_fd.read(1024).strip())
finally:
serial_fd.close()
serial_fd = open(constants.JOB_QUEUE_SERIAL_FILE, "r")
try:
# Read last serial
serial = int(serial_fd.read(1024).strip())
finally:
serial_fd.close()
except (ValueError, EnvironmentError):
serial = None
return serial
def Close(self):
assert self.lock_fd, "Queue should be open"
......@@ -327,8 +346,9 @@ class JobStorage(object):
utils.WriteFile(constants.JOB_QUEUE_VERSION_FILE,
data="%s\n" % constants.JOB_QUEUE_VERSION)
utils.WriteFile(constants.JOB_QUEUE_SERIAL_FILE,
data="%s\n" % 0)
if self._ReadSerial() is None:
utils.WriteFile(constants.JOB_QUEUE_SERIAL_FILE,
data="%s\n" % 0)
def _NewSerialUnlocked(self):
"""Generates a new job identifier.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment