77
82
""").strip() % (node.node_id, node.node_id, node.node_id)
85
message(outf, "Uninstall node %d" % node.node_id)
80
86
print >> outf, "uninstall node (id=%d);" % node.node_id
84
90
def generate_sync():
85
91
outf = open(outpath('mig_sync.sk'), 'w')
86
print >> outf, "sync (id=1);"
87
print >> outf, "wait for event (origin=1, confirmed=all, wait on=1);"
92
message(outf, "Waiting for sync")
93
print >> outf, "sync (id=@master_node);"
94
print >> outf, dedent("""\
96
origin=@master_node, confirmed=all, wait on=@master_node);
98
108
remaining_nodes = nodes[1:]
100
110
# Initialize the cluster
111
message(outf, "Initializing cluster (node %d)" % first_node.node_id)
101
112
print >> outf, "init cluster (id=%d);" % first_node.node_id
103
114
# Create all the other nodes
104
115
for node in remaining_nodes:
116
message(outf, "Initializing node %d" % node.node_id)
105
117
print >> outf, "store node (id=%d, event node=%d);" % (
106
118
node.node_id, first_node.node_id)
108
120
# Create paths so they can communicate.
121
message(outf, "Storing %d paths" % pow(len(nodes),2))
109
122
for client_node in nodes:
110
123
for server_node in nodes:
132
145
def generate_initialize_set(set_id, set_name, outf):
133
146
origin_node = get_master_node(con, set_id)
134
print >> outf, "create set (id=%d, origin=%d, comment='%s');" % (
135
set_id, origin_node.node_id, set_name)
147
message(outf, "Creating %s origin %d" % (set_name, origin_node.node_id))
148
print >> outf, "create set (id=%d, origin=@%s_origin, comment='%s');" % (
149
set_id, set_name, set_name)
136
150
cur = con.cursor()
138
152
SELECT tab_id, tab_nspname, tab_relname, tab_comment
139
153
FROM _sl.sl_table WHERE tab_set=%s
141
for tab_id, tab_nspname, tab_relname, tab_comment in cur.fetchall():
155
results = cur.fetchall()
156
message(outf, "Adding %d tables to %s" % (len(results), set_name))
157
for tab_id, tab_nspname, tab_relname, tab_comment in results:
142
158
if not tab_comment:
144
160
print >> outf, dedent("""\
146
set id=%d, origin=%d, id=%d,
162
set id=@%s, origin=@%s_origin, id=%d,
147
163
fully qualified name='%s.%s',
150
set_id, origin_node.node_id, tab_id,
166
set_name, set_name, tab_id,
151
167
tab_nspname, tab_relname, tab_comment)
153
169
SELECT seq_id, seq_nspname, seq_relname, seq_comment
154
170
FROM _sl.sl_sequence WHERE seq_set=%s
156
for seq_id, seq_nspname, seq_relname, seq_comment in cur.fetchall():
172
results = cur.fetchall()
173
message(outf, "Adding %d sequences to %s" % (len(results), set_name))
174
for seq_id, seq_nspname, seq_relname, seq_comment in results:
157
175
if not seq_comment:
159
177
print >> outf, dedent("""\
160
178
set add sequence (
161
set id=%d, origin=%d, id=%d,
179
set id=@%s, origin=@%s_origin, id=%d,
162
180
fully qualified name='%s.%s',
165
set_id, origin_node.node_id, seq_id,
183
set_name, set_name, seq_id,
166
184
seq_nspname, seq_relname, seq_comment)
174
192
WHERE sub_set=%s and sub_active is true
176
194
for receiver_id, in cur.fetchall():
195
message(outf, "Subscribing node %d to %s" % (receiver_id, set_name))
177
196
print >> outf, dedent("""\
179
id=%d, provider=%d, receiver=%d,
198
id=%d, provider=@%s_origin, receiver=%d,
180
199
forward=true, omit copy=true);
182
origin=%d, confirmed=all, wait on=%d);
201
origin=@%s_origin, confirmed=all, wait on=@%s_origin);
184
set_id, origin_node.node_id, receiver_id,
185
origin_node.node_id, origin_node.node_id)
203
set_id, set_name, receiver_id,
186
205
print >> outf, "include <mig_sync.sk>;"