Skip to content

Commit c03bbfe

Browse files
committed
Update database only afer transfer to HPSS
To improve robustness, update database entries only after tar archive has been sucessfully transferred to HPSS. If anything fails before (e.g. zstash is killed), restarting zstash with the 'update' function will archive all missing files and overwrite the incomplete tar archive.
1 parent 4f1da44 commit c03bbfe

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def addfiles(cur, con, itar, files):
5050
# New tar archive in the local cache
5151
if newtar:
5252
newtar = False
53+
archived = []
5354
tarsize = 0
5455
itar += 1
5556
tname = "{0:0{1}x}".format(itar, 6)
@@ -62,9 +63,7 @@ def addfiles(cur, con, itar, files):
6263
logging.info('Archiving %s' % (file[0]))
6364
try:
6465
offset, size, mtime, md5 = addfile(tar, file[0])
65-
cur.execute(u"insert into files values (NULL,?,?,?,?,?,?)",
66-
(file[0], size, mtime, md5, tfname, offset))
67-
con.commit()
66+
archived.append((file[0], size, mtime, md5, tfname, offset))
6867
tarsize += file[1]
6968
except:
7069
logging.error('Archiving %s' % (file[0]))
@@ -81,6 +80,11 @@ def addfiles(cur, con, itar, files):
8180
# Transfer tar archive to HPSS
8281
hpss_put(config.hpss, os.path.join(CACHE, tfname), config.keep)
8382

83+
# Update database with files that have been archived
84+
cur.executemany(u"insert into files values (NULL,?,?,?,?,?,?)",
85+
archived)
86+
con.commit()
87+
8488
# Open new archive next time
8589
newtar = True
8690

0 commit comments

Comments
 (0)