mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
retention: Improve logging of transactions.
This commit is contained in:
committed by
Tim Abbott
parent
33fa307c95
commit
468f8cf488
@@ -27,6 +27,7 @@
|
|||||||
# message or group of messages) as we use for message retention policy
|
# message or group of messages) as we use for message retention policy
|
||||||
# deletions.
|
# deletions.
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
@@ -136,9 +137,9 @@ def run_archiving_in_chunks(
|
|||||||
|
|
||||||
message_count = 0
|
message_count = 0
|
||||||
while True:
|
while True:
|
||||||
|
start_time = time.time()
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
archive_transaction = ArchiveTransaction.objects.create(type=type, realm=realm)
|
archive_transaction = ArchiveTransaction.objects.create(type=type, realm=realm)
|
||||||
logger.info("Archiving in %s", archive_transaction)
|
|
||||||
new_chunk = move_rows(
|
new_chunk = move_rows(
|
||||||
Message,
|
Message,
|
||||||
query,
|
query,
|
||||||
@@ -153,11 +154,14 @@ def run_archiving_in_chunks(
|
|||||||
message_count += len(new_chunk)
|
message_count += len(new_chunk)
|
||||||
else:
|
else:
|
||||||
archive_transaction.delete() # Nothing was archived
|
archive_transaction.delete() # Nothing was archived
|
||||||
|
total_time = time.time() - start_time
|
||||||
|
|
||||||
# This line needs to be outside of the atomic block, to capture the actual moment
|
# This line needs to be outside of the atomic block, to capture the actual moment
|
||||||
# archiving of the chunk is finished (since Django does some significant additional work
|
# archiving of the chunk is finished (since Django does some significant additional work
|
||||||
# when leaving the block).
|
# when leaving the block).
|
||||||
logger.info("Finished. Archived %s messages in this transaction.", len(new_chunk))
|
if len(new_chunk) > 0:
|
||||||
|
logger.info("Archived %s messages in %.2fs in transaction %s.",
|
||||||
|
len(new_chunk), total_time, archive_transaction.id)
|
||||||
|
|
||||||
# We run the loop, until the query returns fewer results than chunk_size,
|
# We run the loop, until the query returns fewer results than chunk_size,
|
||||||
# which means we are done:
|
# which means we are done:
|
||||||
|
|||||||
Reference in New Issue
Block a user