Merge lp:~daniel-thewatkins/charms/trusty/ubuntu-repository-cache/add-rsync-timeout into lp:charms/trusty/ubuntu-repository-cache

Proposed by Dan Watkins on 2015-06-08
Status: Merged
Merge reported by: Adam Israel
Merged at revision: not available
Proposed branch: lp:~daniel-thewatkins/charms/trusty/ubuntu-repository-cache/add-rsync-timeout
Merge into: lp:charms/trusty/ubuntu-repository-cache
Diff against target: 107 lines (+38/-15)
2 files modified
hooks/hooks.py (+3/-2)
lib/ubuntu_repository_cache/mirror.py (+35/-13)
To merge this branch: bzr merge lp:~daniel-thewatkins/charms/trusty/ubuntu-repository-cache/add-rsync-timeout
Reviewer Review Type Date Requested Status
Robert C Jennings (community) 2015-06-08 Approve on 2015-07-09
Adam Israel 2015-06-08 Approve on 2015-06-25
Review via email: mp+261424@code.launchpad.net

Description of the Change

This does a couple of rsync-related things: it adds a 120 second timeout (which should deal with the hangs seen in the attached) bug, and also firms up the logic for syncing to peers to avoid telling a failed peer it was successful.

Specifically, we have three phases to the peer update:
 (1) transfer the mirror payload to all peers,
 (2) transfer a file to each peer that tells them that they have a good version of the files, and then
 (3) change a relationship variable, to trigger the actual switch.

This ensures that if a transfer in (1) fails, then that peer won't be included in the transfer for (2).

To post a comment you must log in.
Adam Israel (aisrael) wrote :

Hi Dan,

I had a chance to review this MP. The changes here look good, and you have a +1 from me on that, with the caveat that it's dependent on lp:262072 and lp:261356 being merged.

review: Approve
Robert C Jennings (rcj) wrote :

Reviewed and the changes look clean. I have not had a chance to test independently.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2015-02-24 15:41:56 +0000
3+++ hooks/hooks.py 2015-06-08 16:18:05 +0000
4@@ -84,12 +84,13 @@
5 link_dir = '/'.join((apache_data, 'ubuntu_active'))
6 LOG('Pushing updates to peers', hookenv.DEBUG)
7 source = meta_dir + '/'
8- mirror.rsync_to_peers(source, dest, link_dir=link_dir)
9+ successful_peers = mirror.rsync_to_peers(
10+ source, dest, link_dir=link_dir)
11
12 # Push metaversion_good canary to indicate a complete sync
13 canary = '_'.join((meta_dir, 'good'))
14 LOG('Pushing canary files to peers', hookenv.DEBUG)
15- mirror.rsync_to_peers(canary, apache_data)
16+ mirror.rsync_to_peers(canary, apache_data, peers=successful_peers)
17
18 # Update 'meta_version' relation setting
19 LOG('', hookenv.DEBUG)
20
21=== modified file 'lib/ubuntu_repository_cache/mirror.py'
22--- lib/ubuntu_repository_cache/mirror.py 2015-03-13 15:29:57 +0000
23+++ lib/ubuntu_repository_cache/mirror.py 2015-06-08 16:18:05 +0000
24@@ -5,7 +5,9 @@
25 import glob
26 import os
27 import socket
28+import sys
29 import time
30+import traceback
31
32 from collections import OrderedDict
33 from datetime import datetime
34@@ -330,6 +332,7 @@
35 '--compress',
36 '--delete',
37 '--delete-during',
38+ '--timeout=120',
39 '-e', 'sudo -u {} ssh -l {}'.format(user, user),
40 ]
41 if optlist:
42@@ -364,21 +367,34 @@
43 @util.run_as_user('www-sync')
44 def rsync_to_peers(source_dir, dest_dir, link_dir=None, user='www-sync',
45 peers=None):
46- '''Use rsync to push a directory to all configured peer.
47+ """
48+ Use rsync to push a directory to all configured peers.
49
50 Peers are configured in the 'cluster' relationship using
51- charmhelpers.contrib.unison.ssh_authorized_peers().
52- '''
53-
54- if not peers:
55+ charmhelpers.contrib.unison.ssh_authorized_peers(); this list can be
56+ overridden with the peers parameter.
57+
58+ A list of the peers whose transfers were successful will be
59+ returned.
60+ """
61+
62+ if peers is None:
63 peers = unison.collect_authed_hosts(peer_interface='cluster')
64
65+ successful_peers = []
66 for peer in peers:
67 rsync_dest = '{}@{}:{}'.format(user, peer, dest_dir)
68 LOG('Syncing {} to {}.'.format(source_dir, rsync_dest))
69- _rsync(source_dir, rsync_dest, link_dest=link_dir,
70- user=user, retries=10)
71- LOG('Sync to {} complete.'.format(peer))
72+ try:
73+ _rsync(source_dir, rsync_dest, link_dest=link_dir,
74+ user=user, retries=10)
75+ except Exception:
76+ LOG('Sync to {} failed'.format(peer))
77+ traceback.print_exc(file=sys.stdout)
78+ else:
79+ successful_peers.append(peer)
80+ LOG('Sync to {} complete.'.format(peer))
81+ return successful_peers
82
83
84 @util.run_as_user('www-sync')
85@@ -505,11 +521,17 @@
86 active_dir = '/'.join((apache_data, 'ubuntu_active'))
87 source = meta_dir + '/'
88 dest = meta_dir
89- rsync_from_peer(source, dest,
90- leader_rel.get('private-address'),
91- link_dir=active_dir)
92- util.update_active_symlink(meta_ver)
93- service.unpause()
94+ try:
95+ rsync_from_peer(source, dest,
96+ leader_rel.get('private-address'),
97+ link_dir=active_dir)
98+ except CalledProcessError:
99+ traceback.print_exc()
100+ LOG('Failed to pull metadata from leader; service stopped'
101+ ' until next update from leader.')
102+ else:
103+ util.update_active_symlink(meta_ver)
104+ service.unpause()
105
106 # Do nothing. Service is stopped until next update from leader
107 else:

Subscribers

People subscribed via source and target branches

to all changes: