Skip to content

Commit 38b2b19

Browse files
committed
fix(linstor): Clarifications, documentations, and more explicit work.
Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
1 parent 46bc6e3 commit 38b2b19

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

drivers/LinstorSR.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,16 +1579,18 @@ def database_backup(self, name="", *, delay=0, fail=False, controller=False):
15791579
"""Generate a new database backup file.
15801580
This operation should not prevent the underlying action to be successful.
15811581
Hence all Exceptions are caught and re-raised only if asked to.
1582+
delay: skip backup if the last one was generated less than delay seconds ago.
1583+
fail: If fail is True, caught Exception are raised after being logged in SMlog.
15821584
controller: operate only if the current host is the Linstor Controller.
1585+
> This will trigger controller-only operations like retention and validation.
15831586
"""
15841587
if not self._linstor:
15851588
self._reconnect()
1586-
if controller:
1587-
if self._linstor.is_controller():
1588-
self._linstor.database_invalidation()
1589-
else:
1590-
return
1589+
if controller and not self._linstor.is_controller():
1590+
return
15911591
try:
1592+
if controller:
1593+
self._linstor.database_invalidation()
15921594
self._linstor.database_backup(name, delay=delay)
15931595
except Exception as e:
15941596
util.SMlog(

drivers/linstorvolumemanager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,18 +2669,18 @@ def _get_volume_properties(self, volume_uuid):
26692669

26702670
def _log_database_backup(self, date, name):
26712671
"""Log a database backup operation: "date name"
2672-
We cannot assume the pool-master is the same as the linstor-master,
2673-
this file is on the pool-master, and serves for the throttling."""
2672+
We cannot assume the Pool Master is the same as the Linstor Controller,
2673+
this file is on the Pool Master, and serves for the throttling."""
26742674
os.makedirs(DATABASE_BACKUP_LOGDIR, mode=0o755, exist_ok=True)
26752675
with open(DATABASE_BACKUP_LOGFILE, "a", encoding="utf8") as f:
2676-
f.write(f"{date} {name}\n")
2676+
f.write(f"{date} {name[:15]}\n")
26772677

26782678
def _get_latest_logged_database_backup_date(self):
26792679
# get last log line if it exists, and return the corresponding date
26802680
try:
26812681
with open(DATABASE_BACKUP_LOGFILE, "rb") as f:
2682-
# seek from the end, with 256 as a most-probable maximum line length
2683-
f.seek(-min(os.stat(DATABASE_BACKUP_LOGFILE).st_size, 256), os.SEEK_END)
2682+
# seek from the end, a line length can't be more than 32
2683+
f.seek(-min(os.stat(DATABASE_BACKUP_LOGFILE).st_size, 32), os.SEEK_END)
26842684
return f.read().decode().splitlines()[-1].split()[0]
26852685
except FileNotFoundError:
26862686
return "20000101_000000"

0 commit comments

Comments
 (0)