def ensure_primary_mirror_switched_roles(): results = query_sql( "postgres", "select * from gp_segment_configuration where preferred_role <> role") if results.rowcount != 2: raise Exception("expected 2 segments to not be in preferred roles")
def step_impl(context): result_cursor = query_sql( "postgres", "select datadir from gp_segment_configuration where role='m';") for content_id, result in enumerate(result_cursor.fetchall()): path_to_replslot = os.path.join(result[0], 'pg_replslot') if len(os.listdir(path_to_replslot)) > 0: raise Exception("expected replication slot directory to be empty")
def step_impl(context): result_cursor = query_sql( "postgres", "select pg_get_replication_slots() from gp_dist_random('gp_id') order by gp_segment_id" ) if result_cursor.rowcount != context.current_cluster_size: raise Exception("expected all %d primaries to have replication slots, only %d have slots" % (context.current_cluster_size, results.rowcount)) for content_id, result in enumerate(result_cursor.fetchall()): pg_rep_slot = result[0] if (pg_rep_slot[0], pg_rep_slot[2], pg_rep_slot[4]) != ('internal_wal_replication_slot','physical','t') : raise Exception( "expected replication slot to be active for content id %d, got %s" % (content_id, result[0]) )
def step_impl(context): host, datadir = query_sql("postgres", "SELECT hostname, datadir FROM gp_segment_configuration WHERE role='m' AND content=0" ).fetchone() # NOTE that these commands are manually escaped; beware when adding dollar # signs or double-quotes! cmd = "ps aux | grep '[p]ostgres .* %s' | awk '{print \$2}' | xargs kill -9" % datadir cmd = 'ssh %s "%s"' % (host, cmd) run_command(context, cmd) # If the kill succeeds, recover the mirror when this test is done. def recover(): run_command(context, "gprecoverseg -a") context.add_cleanup(recover) wait_for_unblocked_transactions(context)