~ubuntu-branches/ubuntu/lucid/desktopcouch/lucid

« back to all changes in this revision

Viewing changes to desktopcouch/replication.py

  • Committer: Bazaar Package Importer
  • Author(s): Chad MILLER
  • Date: 2010-04-12 23:02:01 UTC
  • mfrom: (1.5.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100412230201-d4giwkoobigefqml
Tags: 0.6.4-0ubuntu1
* Upstream release.  Adds all patches that were previously in this packaging.
* Split desktopcouch-service threads into to discrete processes, since they
  do not depend on each other, and because multithreading breaks with recent
  changes to libraries. (LP: #524566, #530605)
* Made desktopcouch more robust when dealing with mergeable lists.
  (LP: #555908)
* If the replication service gives a user_id, then include it in the
  query string, so the service can shard access.
* Add bookmark records support.
* Handle cancelled keyring dialogs.  (LP: #527036)
* Retry when starting couchdb fails.  (LP: #530541)
* debian/patches/0-items-should-expose-private-data-for-now.patch
  - Gwibber demands that some items that are private be exposed, namely
    keys _id and _rev.  These should properly be accessed as attributes
    .record_id and .record_revision in some future release of gwibber.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
 
36
36
known_bad_service_names = set()
37
 
already_replicating = False
38
37
is_running = True
39
38
 
40
39
 
72
71
    log.debug("started replicating")
73
72
    local_uri = couchdb_io.mkuri("localhost", local_port)
74
73
    try:
75
 
        global already_replicating  # Fuzzy, as not really critical,
76
 
        already_replicating = True  #   just trying to be polite.
77
 
 
78
74
        try:
79
75
            # All machines running desktopcouch must advertise themselves with
80
76
            # zeroconf.  We collect those elsewhere and filter out the ones
145
141
 
146
142
                # TODO: push all this into service module.
147
143
                try:
148
 
                    remote_location = db_targetprefix_for_service(sn)
 
144
                    prefix_getter = db_targetprefix_for_service(sn)
 
145
                    remote_location = str(prefix_getter)
 
146
                    if hasattr(prefix_getter, 'user_id'):
 
147
                        user_id = prefix_getter.user_id
 
148
                    else:
 
149
                        user_id = None
149
150
                    urlinfo = urlparse.urlsplit(str(remote_location))
150
151
                except ValueError, e:
151
152
                    log.warn("Can't reach service %s.  %s", sn, e)
174
175
                if to_pull:
175
176
                    for remote_db_name in \
176
177
                            couchdb_io.get_database_names_replicatable(
177
 
                            couchdb_io.mkuri(
 
178
                    couchdb_io.mkuri(
178
179
                            addr, int(port), has_ssl=(urlinfo.scheme=='https')),
179
 
                            oauth_tokens=remote_oauth_data, service=True):
 
180
                            oauth_tokens=remote_oauth_data, service=True,
 
181
                            user_id=user_id):
180
182
                        if not is_running:
181
183
                            return
182
184
                        try:
203
205
            log.exception("replication of services aborted")
204
206
            pass
205
207
    finally:
206
 
        already_replicating = False
207
 
    log.debug("finished replicating")
208
 
 
209
 
 
210
 
def replicate_local_databases_to_paired_hosts(local_port):
211
 
    if already_replicating:
212
 
        log.warn("haven't finished replicating before next time to start.")
213
 
        return False
214
 
 
215
 
    reactor.callInThread(do_all_replication, local_port)
 
208
        log.debug("finished replicating")
 
209
 
216
210
 
217
211
def set_up(port_getter):
218
212
    port = port_getter()
231
225
 
232
226
    dbus_io.maintain_discovered_servers()
233
227
 
234
 
    t = task.LoopingCall(replicate_local_databases_to_paired_hosts, int(port))
 
228
    t = task.LoopingCall(do_all_replication, int(port))
235
229
    t.start(600)
236
230
 
237
231
    # TODO:  port may change, so every so often, check it and