ChunkedBackupDriver: Freeing memory on restore

When restoring many backups, the backup service uses a lot of memory and
when we do many concurrent restores the backup service ends up getting
killed becase the system runs out of memory.

This patch reduces the ref count to the data as soon as possible to let
Python garbage collect it instead of hogging it for the whole chunk
restore.

Related-Bug: #1865011
Change-Id: I942d9d8b3976232ae1cf82b698fb27285fbef13a
(cherry picked from commit 69462315bc)
This commit is contained in:
Gorka Eguileor 2020-02-27 14:04:13 +01:00 committed by David Hill
parent 6dfbec7f74
commit 94db15dd3b
1 changed files with 3 additions and 0 deletions

View File

@ -717,9 +717,12 @@ class ChunkedBackupDriver(driver.BackupDriver):
LOG.debug('decompressing data using %s algorithm',
compression_algorithm)
decompressed = decompressor.decompress(body)
body = None # Allow Python to free it
volume_file.write(decompressed)
decompressed = None # Allow Python to free it
else:
volume_file.write(body)
body = None # Allow Python to free it
# force flush every write to avoid long blocking write on close
volume_file.flush()