简体   繁体   English

联盟扇出查询

[英]Federation Fan Out Query

I am new in sql azure. 我是SQL Azure中的新手。 Now i am facing a big problem that is because of SQL Azure federation. 现在,我面临一个大问题,这是因为SQL Azure联合身份验证。 In one of my project I want to use federation. 在我的项目之一中,我想使用联合身份验证。 For that I want to read data from all federation. 为此,我想从所有联合会中读取数据。 How can I check total number of federation in the server and read data from the federation? 如何检查服务器中的联盟总数并从联盟读取数据? And also how can I insert data into the federation? 还有如何将数据插入联合身份验证? currently I am using: 目前我正在使用:

string strSQL = @"SELECT f.name, fmc.federation_id, fmc.member_id, fmc.range_low, fmc.range_high " +
                                                            "FROM sys.federations f " +
                                                            "JOIN sys.federation_member_distributions fmc " +
                                                            "ON f.federation_id=fmc.federation_id " +
                                                            "ORDER BY fmc.federation_id, fmc.range_low, fmc.range_high";
        string strTableName = "federation_member_distributions";

        try
        {
            using (SqlConnection connection = new SqlConnection(csb.ToString()))
            {
                connection.Open();
                sbResults.AppendFormat("-- Open {0}\r\n\r\n", csb.ToString());

                data = new DataSet();
                data.Locale = System.Globalization.CultureInfo.InvariantCulture;

                using (SqlCommand command = connection.CreateCommand())
                {
                    // Connect to federation root or federation member
                    command.CommandText = "USE FEDERATION ROOT WITH RESET";
                    command.ExecuteNonQuery();
                    sbResults.AppendFormat("{0}\r\nGO\r\n", command.CommandText);
                }

                //Retrieve federation root metadata, and populate the data to the DataGridView control
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(strSQL, connection);
                sqlDataAdapter.Fill(data, strTableName);
                sbResults.AppendFormat("{0}\r\nGO\r\n", strSQL);
            }

        }
        catch (Exception ex)
        {

        }

but it does not work 但这不起作用

For your above questions you really need to look these articles which talks about how to use SQL Azure Federation: 对于上述问题,您确实需要查看这些文章,这些文章讨论如何使用SQL Azure Federation:

Introduction to Fan-out Queries for Federations in SQL Azure (Part 1): Scalable Queries over Multiple Federation Members, MapReduce Style! SQL Azure中联盟的扇出查询简介(第1部分):多个联盟成员上的可扩展查询,MapReduce样式!

Above you can find Fanout sample tool which has the code that show you how to get data out from Federation(s). 在上方,您可以找到Fanout示例工具 ,该工具的代码向您展示了如何从联盟中获取数据。

The second part of this sample " Fan-out Querying for Federations in SQL Azure (Part 2): Scalable Fan-out Queries with TOP, ORDER BY, DISTINCT and Other Powerful Aggregates, MapReduce Style! " show how you can run fan-out queries with particular examples. 该示例的第二部分“ 在SQL Azure中进行联合查询的扇出查询(第2部分):具有TOP,ORDER BY,DISTINCT和其他强大聚合的可伸缩扇出查询,MapReduce样式! ”展示了如何运行扇出带有特定示例的查询。

Try above sample and let us know if you met any problem. 尝试上述示例,让我们知道您是否遇到任何问题。

I had discussion with Cihan Biyikoglu from SQL Azure Team and following is what he suggested: 我与SQL Azure团队的Cihan Biyikoglu进行了讨论,他的建议如下:

The idea is that you do not have to cache the 'map' of where the data is with federations so you should not have to; 这个想法是,您不必使用联合身份验证来缓存数据所在的“地图”,因此您不必这样做。

Here is the pseudo app code and the actual sample that does the fanout; 这是伪应用程序代码和执行扇出的实际示例; you can try out the code in this UI as well. 您也可以在此用户界面中尝试代码。

http://federationsutility-seasia.cloudapp.net/About.aspx http://federationsutility-seasia.cloudapp.net/About.aspx

Start at the 
@i=MIN_VALUE (of the data_type or federation key like customerID=-1)
While (@i not null)
{
 Try
 {
    -- switch to the next member
    USE FEDERATION fedname(id=@i)...

    -- Run your transaction here for this member 
    SELECT * FROM table join other_table … WHERE fedkeycolumn >= @i group by … order by …

    -- grab the next value
    SELECT @i=range_high FROM sys.federation_member_distributions 
 }
 Catch ()
 {
           If retry_count < total_retries
                          Exit the loop
 }
}

If you still would like to find out the members you can always run the query in the db that contain federations; 如果您仍然想找出成员,则可以始终在包含联合身份验证的数据库中运行查询;

Select * from sys.federation_member_distributions fmd join sys.federations f on fmd.federation_id=f.federation_id 

The problem with this approach is you may miss reading data if there is a split between the time you read the info and finish processing the query. 这种方法的问题是,如果您在读取信息的时间和完成处理查询的时间之间存在时间间隔,则可能会错过读取数据的时间。

The above method without caching the 'map' is not prone to that problem. 没有缓存“地图”的上述方法不容易出现该问题。 It will catch all members regardless of any repartitioning operations. 它将捕获所有成员,而不管任何重新分区操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM