397
397
# We also scan for tables and sequences we want to drop and do so using
398
398
# a final slonik script. Instead of dropping tables in the DB patch,
399
399
# we rename them into the ToDrop namespace.
401
# First, remove all todrop.* sequences from replication.
403
SELECT seq_nspname, seq_relname, seq_id from %s
404
WHERE seq_nspname='todrop'
405
""" % fqn(replication.helpers.CLUSTER_NAMESPACE, 'sl_sequence'))
406
seqs_to_unreplicate = set(
407
(fqn(nspname, relname), tab_id)
408
for nspname, relname, tab_id in cur.fetchall())
409
if seqs_to_unreplicate:
410
log.info("Unreplicating sequences: %s" % ', '.join(
411
name for name, id in seqs_to_unreplicate))
412
# Generate a slonik script to remove sequences from the
416
for seq_name, seq_id in seqs_to_unreplicate:
417
if seq_id is not None:
418
print >> sk, dedent("""\
419
echo 'Removing %s from replication';
420
set drop sequence (origin=@master_node, id=%d);
421
""" % (seq_name, seq_id))
422
print >> sk, dedent("""\
425
echo 'Failed to unreplicate sequences. Aborting.';
430
"Generated slonik(1) script to unreplicate sequences. Invoking.")
431
if not replication.helpers.execute_slonik(sk.getvalue()):
432
log.fatal("Aborting.")
433
log.info("slonik(1) script to drop sequences completed.")
435
# Generate a slonik script to remove tables from the replication set,
436
# and a DROP TABLE/DROP SEQUENCE sql script to run after.
401
438
SELECT nspname, relname, tab_id
407
444
tabs_to_drop = set(
408
445
(fqn(nspname, relname), tab_id)
409
446
for nspname, relname, tab_id in cur.fetchall())
411
# Generate a slonik script to remove tables from the replication set,
412
# and a DROP TABLE/DROP SEQUENCE sql script to run after.
414
448
log.info("Dropping tables: %s" % ', '.join(
415
449
name for name, id in tabs_to_drop))
441
475
log.info("slonik(1) script to drop tables completed.")
444
# Now drop sequences. We don't do this at the same time as the tables,
445
# as most sequences will be dropped implicitly with the table drop.
478
# Now drop any remaining sequences. Most sequences will be dropped
479
# implicitly with the table drop.
447
481
SELECT nspname, relname, seq_id