~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to database/replication/initialize.py

  • Committer: Curtis Hovey
  • Date: 2011-08-12 14:39:51 UTC
  • mto: This revision was merged to the branch mainline in revision 13685.
  • Revision ID: curtis.hovey@canonical.com-20110812143951-74vfvrt37gtt4fz2
Sorted imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -S
2
2
#
3
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
5
 
6
6
"""Initialize the cluster.
17
17
 
18
18
import helpers
19
19
 
20
 
from lp.services.config import config
21
 
from lp.services.database.postgresql import (
22
 
    all_sequences_in_schema,
23
 
    all_tables_in_schema,
24
 
    ConnectionString,
25
 
    )
26
 
from lp.services.database.sqlbase import (
27
 
    connect,
28
 
    ISOLATION_LEVEL_AUTOCOMMIT,
29
 
    )
30
 
from lp.services.scripts import (
31
 
    db_options,
32
 
    logger,
33
 
    logger_options,
34
 
    )
35
 
 
 
20
from canonical.config import config
 
21
from canonical.database.sqlbase import connect, ISOLATION_LEVEL_AUTOCOMMIT
 
22
from canonical.database.postgresql import (
 
23
        all_sequences_in_schema, all_tables_in_schema, ConnectionString
 
24
        )
 
25
from canonical.launchpad.scripts import (
 
26
        logger, logger_options, db_options
 
27
        )
36
28
 
37
29
__metaclass__ = type
38
30
__all__ = []
39
31
 
40
32
 
41
 
# Global logger, initialized in main().
42
 
log = None
43
 
 
44
 
# Parsed command line options, initialized in main().
45
 
options = None
46
 
 
47
 
# Shared database cursor to the master, initialized in main().
48
 
cur = None
 
33
log = None # Global logger, initialized in main()
 
34
 
 
35
options = None # Parsed command line options, initialized in main()
 
36
 
 
37
cur = None # Shared database cursor to the master, initialized in main()
49
38
 
50
39
 
51
40
def duplicate_schema():
53
42
    log.info('Duplicating database schema')
54
43
 
55
44
    master_cs = ConnectionString(config.database.rw_main_master)
 
45
    master_cs.user = options.dbuser
56
46
    slave1_cs = ConnectionString(config.database.rw_main_slave)
 
47
    slave1_cs.user = options.dbuser
57
48
 
58
49
    # We can't use pg_dump to replicate security as not all of the roles
59
50
    # may exist in the slave databases' clusters yet.
94
85
 
95
86
def ensure_live():
96
87
    log.info('Ensuring slon daemons are live and propagating events.')
97
 
    # This will exit on failure.
98
 
    helpers.sync(120)
 
88
    helpers.sync(120) # Will exit on failure.
99
89
 
100
90
 
101
91
def create_replication_sets(lpmain_tables, lpmain_sequences):
146
136
        """)
147
137
    helpers.execute_slonik('\n'.join(script), sync=600)
148
138
 
149
 
    # Explode now if we have messed up.
150
 
    helpers.validate_replication(cur)
 
139
    helpers.validate_replication(cur) # Explode now if we have messed up.
151
140
 
152
141
 
153
142
def main():
165
154
 
166
155
    # Generate lists of sequences and tables for our replication sets.
167
156
    log.debug("Connecting as %s" % options.dbuser)
168
 
    con = connect()
 
157
    con = connect(options.dbuser)
169
158
    con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
170
159
    global cur
171
160
    cur = con.cursor()