Merge lp:~hloeung/ubuntu-repository-cache/metadata-peer-sync-retry into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 376
Merged at revision: 375
Proposed branch: lp:~hloeung/ubuntu-repository-cache/metadata-peer-sync-retry
Merge into: lp:ubuntu-repository-cache
Diff against target: 51 lines (+28/-7)
1 file modified
lib/ubuntu_repository_cache/mirror.py (+28/-7)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/metadata-peer-sync-retry
Reviewer Review Type Date Requested Status
James Simpson Approve
Canonical IS Reviewers Pending
Review via email: mp+428673@code.launchpad.net

Commit message

Add retry logic around syncing metadata snapshot to peers

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

376. By Haw Loeung

Break out of retry loop on success

Revision history for this message
James Simpson (jsimpso) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 375

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/ubuntu_repository_cache/mirror.py'
2--- lib/ubuntu_repository_cache/mirror.py 2022-08-20 23:39:48 +0000
3+++ lib/ubuntu_repository_cache/mirror.py 2022-08-21 23:32:03 +0000
4@@ -1,6 +1,8 @@
5 '''Functions relating to mirrored Ubuntu package repository content'''
6
7+import datetime
8 import os
9+import random
10 import sys
11 import time
12 import traceback
13@@ -89,14 +91,33 @@
14 for peer in peers:
15 rsync_dest = '{}@{}:{}'.format(user, peer, dest_dir)
16 LOG('Syncing {} to {}.'.format(source_dir, rsync_dest))
17- try:
18- _rsync(source_dir, rsync_dest, link_dest=link_dir, user=user, retries=10)
19- except Exception:
20- LOG('Sync to {} failed'.format(peer))
21- traceback.print_exc(file=sys.stdout)
22+
23+ errmsgs = []
24+ # Work around Juju instability issues causing juju-run to abort
25+ # (LP:1977798 & LP:1984060).
26+ max_retries = 10
27+ for attempt in range(1, max_retries):
28+ try:
29+ _rsync(source_dir, rsync_dest, link_dest=link_dir, user=user, retries=10)
30+ except Exception as e:
31+ LOG('Sync to {} failed'.format(peer))
32+ LOG(e.output.decode())
33+ errmsgs.append("{}: Sync to {} failed".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), peer))
34+ errmsgs.append(e.output.decode())
35+ # Exponential backoff.
36+ sleep = random.randint(attempt, 10 * attempt)
37+ time.sleep(sleep)
38+ else:
39+ successful_peers.append(peer)
40+ LOG('Sync to {} complete.'.format(peer))
41+ break
42 else:
43- successful_peers.append(peer)
44- LOG('Sync to {} complete.'.format(peer))
45+ print('\n'.join(errmsgs))
46+ msg = "Failed after all available attempts ({}) with peer {}".format(max_retries, peer)
47+ LOG(msg)
48+ print("{}: {}".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), msg))
49+ sys.stdout.flush()
50+
51 return successful_peers
52
53

Subscribers

People subscribed via source and target branches