def _update_pl_proxy_cluster(existing_config, verbose): existing_shards = _get_current_shards(existing_config) new_shard_configs = partition_config.get_shards() if verbose: print('{0} Existing config {0}'.format('-' * 42)) print(existing_config) print('-' * 100) shards_to_update = get_shards_to_update(existing_shards, new_shard_configs) if not shards_to_update: print('No changes. Exiting.') else: print("Shards to update:") existing_shards_by_id = {shard.id: shard for shard in existing_shards} for new in shards_to_update: print(" {} -> {}".format( existing_shards_by_id[new.id].get_server_option_string(), new.get_server_option_string())) if _confirm("Update these shards?"): alter_sql = _get_alter_server_sql(shards_to_update) if verbose: print(alter_sql) with connections[ partition_config.get_proxy_db()].cursor() as cursor: cursor.execute(alter_sql) else: print('Abort')
def _update_pl_proxy_cluster(existing_config, verbose): existing_shards = _get_current_shards(existing_config) config = PartitionConfig() new_shard_configs = config.get_shards() shards_to_update = get_shards_to_update(existing_shards, new_shard_configs) if not shards_to_update: print 'No changes. Exiting.' else: print "Shards to update:" existing_shards_by_id = {shard.id: shard for shard in existing_shards} for new in shards_to_update: print " {} -> {}".format( existing_shards_by_id[new.id].get_server_option_string(), new.get_server_option_string() ) if _confirm("Update these shards?"): alter_sql = _get_alter_server_sql(shards_to_update) if verbose: print alter_sql with connections[config.get_proxy_db()].cursor() as cursor: cursor.execute(alter_sql) else: print 'Abort'
def test_get_shards_to_update(self): existing = [ ShardMeta(id=0, dbname='db0', host='hqdb0', port=5432), ShardMeta(id=1, dbname='db0', host='hqdb0', port=5432), ShardMeta(id=2, dbname='db1', host='hqdb1', port=5432), ShardMeta(id=3, dbname='db1', host='hqdb1', port=5432), ] new = [ ShardMeta(id=0, dbname='db0', host='hqdb0', port=5432), ShardMeta(id=1, dbname='db2', host='hqdb2', port=5432), # changed ShardMeta(id=2, dbname='db1', host='hqdb1', port=5432), ShardMeta(id=3, dbname='db3', host='hqdb3', port=5432), # changed ] to_update = get_shards_to_update(existing, new) self.assertEqual([new[1], new[3]], to_update)