Merge ~hloeung/ubuntu-repository-cache:fixes into ubuntu-repository-cache:master

Proposed by Haw Loeung
Status: Merged
Approved by: Paul Collins
Approved revision: 7e366e1f957ee0f35f27f329a9b810f7af7af25e
Merged at revision: 54d4058f2031d0b63ba4d97c96a3e483b04d47f8
Proposed branch: ~hloeung/ubuntu-repository-cache:fixes
Merge into: ubuntu-repository-cache:master
Diff against target: 92 lines (+10/-10)
2 files modified
lib/ubuntu_repository_cache/metadata_peers_sync.py (+4/-4)
lib/ubuntu_repository_cache/mirror.py (+6/-6)
Reviewer Review Type Date Requested Status
Paul Collins lgtm Approve
Canonical IS Reviewers Pending
Review via email: mp+432212@code.launchpad.net

Commit message

Allow overriding timeouts and drop it for single file sync to peers

To post a comment you must log in.
Revision history for this message
Paul Collins (pjdc) :
review: Approve (lgtm)
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.

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

Change successfully merged at revision 54d4058f2031d0b63ba4d97c96a3e483b04d47f8

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/ubuntu_repository_cache/metadata_peers_sync.py b/lib/ubuntu_repository_cache/metadata_peers_sync.py
2index 5be276f..7ab5bd1 100644
3--- a/lib/ubuntu_repository_cache/metadata_peers_sync.py
4+++ b/lib/ubuntu_repository_cache/metadata_peers_sync.py
5@@ -53,14 +53,14 @@ def ubuntu_repository_cache_sync(environment, log):
6
7 # Push ubuntu_next/ symlink to avoid metadata cleanup
8 log('Pushing ubuntu_next symlink to peers')
9- mirror.rsync_to_peers(link_next, apache_data, peers=peers, log=log)
10+ mirror.rsync_to_peers(link_next, apache_data, peers=peers, timeout=60, log=log)
11
12 # Push the metadata to peers
13 dest = '/'.join((apache_data, meta_ver))
14 link_dir = '/'.join((apache_data, 'ubuntu_active'))
15 log('Pushing updates to peers ({})'.format(meta_ver))
16 source = meta_dir + '/'
17- successful_peers = mirror.rsync_to_peers(source, dest, link_dir=link_dir, peers=peers, log=log)
18+ successful_peers = mirror.rsync_to_peers(source, dest, link_dir=link_dir, peers=peers, timeout=3600, log=log)
19
20 if sorted(successful_peers) != sorted(peers):
21 log('Failed to sync latest metadata to all peers, aborting')
22@@ -69,12 +69,12 @@ def ubuntu_repository_cache_sync(environment, log):
23 # Push metaversion_good canary to indicate a complete sync
24 canary = '_'.join((meta_dir, 'good'))
25 log('Pushing canary files to peers ({})'.format(canary))
26- mirror.rsync_to_peers(canary, apache_data, peers=successful_peers, log=log)
27+ mirror.rsync_to_peers(canary, apache_data, peers=successful_peers, timeout=60, log=log)
28
29 # Update ubuntu_active/ symlink
30 log('Updating ubuntu_active symlink')
31 util.update_active_symlink(os.path.basename(meta_dir), apache_root)
32- mirror.rsync_to_peers(link_dir, apache_data, peers=successful_peers, log=log)
33+ mirror.rsync_to_peers(link_dir, apache_data, peers=successful_peers, timeout=60, log=log)
34
35 duration = time.time() - start_time
36 metric_name = 'ubuntu_repository_cache_metadata_sync_peers_duration'
37diff --git a/lib/ubuntu_repository_cache/mirror.py b/lib/ubuntu_repository_cache/mirror.py
38index cf07c4b..1cfa171 100644
39--- a/lib/ubuntu_repository_cache/mirror.py
40+++ b/lib/ubuntu_repository_cache/mirror.py
41@@ -45,7 +45,7 @@ def rsync(from_path, to_path, flags='-r', options=None, timeout=None, log=None):
42 return subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode('UTF-8').strip()
43
44
45-def _rsync(source, dest, link_dest=None, optlist=None, user='www-sync', retries=1, log=None):
46+def _rsync(source, dest, link_dest=None, optlist=None, user='www-sync', retries=1, timeout=4800, log=None):
47 '''Perform an rsync as a specified user'''
48
49 options = [
50@@ -69,7 +69,7 @@ def _rsync(source, dest, link_dest=None, optlist=None, user='www-sync', retries=
51 attempt = 0
52 while True:
53 try:
54- rsync(source, dest, options=options, timeout=4800, log=log)
55+ rsync(source, dest, options=options, timeout=timeout, log=log)
56 except CalledProcessError as excp:
57 log('rsync failed({}): {}'.format(excp.returncode, excp.output))
58 if not metadata_sync.rsync_should_giveup(excp):
59@@ -88,7 +88,7 @@ def _rsync(source, dest, link_dest=None, optlist=None, user='www-sync', retries=
60
61
62 @util.run_as_user('www-sync')
63-def rsync_to_peers(source_dir, dest_dir, link_dir=None, user='www-sync', peers=None, log=None):
64+def rsync_to_peers(source_dir, dest_dir, link_dir=None, user='www-sync', peers=None, timeout=4800, log=None):
65 """
66 Use rsync to push a directory to all configured peers.
67
68@@ -117,7 +117,7 @@ def rsync_to_peers(source_dir, dest_dir, link_dir=None, user='www-sync', peers=N
69 max_retries = 10
70 for attempt in range(1, max_retries):
71 try:
72- _rsync(source_dir, rsync_dest, link_dest=link_dir, user=user, retries=10, log=log)
73+ _rsync(source_dir, rsync_dest, link_dest=link_dir, user=user, retries=10, timeout=timeout, log=log)
74 except Exception as e:
75 util.send_to_influx(util.render_influx(metric_name, label, attempt))
76 failures = attempt
77@@ -153,7 +153,7 @@ def rsync_to_peers(source_dir, dest_dir, link_dir=None, user='www-sync', peers=N
78
79
80 @util.run_as_user('www-sync')
81-def rsync_from_peer(source_dir, dest_dir, peer_ip, link_dir=None, user='www-sync', log=None):
82+def rsync_from_peer(source_dir, dest_dir, peer_ip, link_dir=None, user='www-sync', timeout=4800, log=None):
83 '''Use rsync to pull a directory from a configured peer.'''
84
85 if not log:
86@@ -161,7 +161,7 @@ def rsync_from_peer(source_dir, dest_dir, peer_ip, link_dir=None, user='www-sync
87
88 rsync_source = '{}@{}:{}'.format(user, peer_ip, source_dir)
89 log('Syncing {} to {}.'.format(rsync_source, dest_dir))
90- _rsync(rsync_source, dest_dir, link_dest=link_dir, user=user, retries=10, log=log)
91+ _rsync(rsync_source, dest_dir, link_dest=link_dir, user=user, retries=10, timeout=timeout, log=log)
92 log('Sync to {} complete.'.format(peer_ip))
93
94

Subscribers

People subscribed via source and target branches