You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by kxepal <gi...@git.apache.org> on 2015/10/07 07:41:11 UTC

[GitHub] couchdb pull request: Retry database creation during cluster setup

Github user kxepal commented on a diff in the pull request:

    https://github.com/apache/couchdb/pull/353#discussion_r41353536
  
    --- Diff: dev/run ---
    @@ -476,17 +476,24 @@ def cluster_setup_with_admin_party(ctx):
         create_system_databases(host, 15984)
     
     
    +def try_request(host, port, meth, path, success_codes, retries=10, retry_dt=1):
    +    while True:
    +        conn = httpclient.HTTPConnection(host, port)
    +        conn.request(meth, path)
    +        resp = conn.getresponse()
    +        if resp.status in success_codes or retries == 0:
    +            return (resp.status,resp.read())
    +        retries -= 1
    +        time.sleep(retry_dt)
    +
     def create_system_databases(host, port):
         for dbname in ['_users', '_replicator', '_metadata', '_global_changes']:
             conn = httpclient.HTTPConnection(host, port)
             conn.request('HEAD', '/' + dbname)
             resp = conn.getresponse()
             if resp.status == 404:
    -            conn = httpclient.HTTPConnection(host, port)
    -            conn.request('PUT', '/' + dbname)
    -            resp = conn.getresponse()
    -            assert resp.status in (201, 202), resp.read()
    -
    +            status, res = try_request(host, port, 'PUT', '/' + dbname, (201, 202, 412))
    +            assert status in (201, 202, 412), res
    --- End diff --
    
    There is no reason now to have this assert here, since it could be in else branch of try_request function.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---