Showing posts with label SQL Server 2008 R2 SP1. Show all posts
Showing posts with label SQL Server 2008 R2 SP1. Show all posts

Wednesday, January 18, 2012

Adding Missing Rows to a SQL Azure Federation with the SQL Azure Federation Data Migration Wizard v1

My Loading Big Data into Federated SQL Azure Tables with the SQL Azure Federation Data Migration Wizard v1.0 post of 1/12/2012 described a problem uploading part of the data for a federation member database in its “Auto-sharding Larger Data Batches” section near the end. This post describes the process I used to determine which of the 398,000 source rows were missing so I could restart the upload process with data for the correct row. The correct data is that which doesn’t cause a primary key constraint conflict and doesn’t result in any missing rows in the resultset.

Update 1/18/2011 9:30 AM PST: Added another 7,958,995 rows to the WADFederation with SQLAzureFedMW v1.2 to reach about 80% full on members 1 and 2. See end of post.

Update 1/16/2012 9:15 AM PST: Completed an 8-million row upload in 10 hours without errors. “See the Investigating Strange Storage Values Reported by Federation Member Pop Ups” section at the end of the post.

Update 1/14/2012 8:45 AM PST: My initial approach wasn’t successful, but executing a MERGE operation succeeded in replacing the missing rows. See the “Executing a MERGE Command to Add Missing Rows” sections near the end of this post.


Background

The Loading Big Data into Federated SQL Azure Tables with the SQL Azure Federation Data Migration Wizard v1.0 post described initially loading 1,000 rows to the federation root database (AzureDiagnostics1), splitting that database into five additional federation members based on CounterId values of 1 through 6. This was limited to 1,000 rows so as to minimize the time required for partitioning but still deliver a reasonable number of rows (166 or 167) to each partition member. The initial Timestamp value of that rowset, created from a WADPerformanceCountersTable-1000rows.txt tab-delimited text file, was 2011-07-25 10:33:21.9432881.

After creating the six-member federation, I uploaded a second rowset created from a WADPerformanceCountersTable-Page-79.txt file with 398,000 rows of data for the time period that immediately preceded the 1,000 row upload. It’s last timestamp value was 2011-07-25 10:33:21.9432881, the same as that for the 1,000-row rowset. (There are several successive rows with identical Timestamp values.) This addition failed for imagefederation member 4 after adding 50,000 rows.

The reason for adding batches of data in reverse chronological order is that I had previously downloaded approximately 8 GB of Windows Azure diagnostic data in 1-GB increments for bulk loading into an SQL Azure 2008 R2 SP1 database in ascending date order. This database was intended for testing uploads on scale similar to that which might be common for large enterprises. Adding later values assured that primary key constraint conflicts wouldn’t occur.


Determining the Federation Member with Missing Rows

SQLAzureFedMW reported Communication link failure errors for only one of the six federation members but didn’t identify the CounterId for offending member. Therefore, I executed the following query in the SQL Azure Management Portal’s query editor (opened by clicking the New Query button in the page header) to count the number of rows in each member:

USE FEDERATION [WADFederation] ([Id] = n) WITH FILTERING = OFF, RESET
GO

SELECT COUNT(*) FROM WADPerfCounters
GO

where n equaled 1, 2, 3, 4, 5 and 6. This resulted in the following row counts:

CounterId Row Count
1 66,501
2 66,500
3 66,500
4 50,167
5 66,500
6 66,499

The member with CounterId = 4 was the obvious culprit. SQLAzureFedMW adds rows in batches of 10,000, as specified by the -b 10000 parameter of:

image

The first addition contributed 167 rows.


Determining the Starting PartitionKey and RowKey Values

I believed that there would be a significant difference in Timestamp values in the rows that represented the junction of the two data sets, so I issued the following query in the query editing window for the member with Id = 4:

SELECT TOP(170) * FROM WADPerfCounters ORDER BY PartitionKey DESC, RowKey DESC

so as to include several rows of both resultsets in the grid, which appeared as follows:

image

The two selected rows had significant differences in PartitionKey and Timestamp values:

image

This led me to the conclusion that I could use the Timestamp value to insert rows into a new SQL Server table and then delete the first few rows whose PartitionKey and RowKey values overlapped existing values in the federation member.

The query grid truncates decimal fractions of Datetime2, 7 values, which it should not, so I executed the same query in SQL Server Management Studio (SSMS) 2008 R2 SP1:

image

The initial constraint is Timestamp >= 2011-07-24 23:12:33.9906722.

I then executed the following SELECT … INTO query in SSMS to create the source table for SQLAzureFedMW:

SELECT * 
INTO WADPerfCounters4
FROM WADPerfCounters
WHERE CounterId = 4

which inserted 16,336 rows into the new table. 50,167 + 16,336 = 66,503, which is close to the 66,499 to 66,501 rows of the other five members.

Next, I executed

DELETE TOP(16323) FROM WADPerfCounters4

to remove all but a few rows uploaded to the federation member prior to the error.

I right-clicked the WADPerfCounters4 table icon and selected Edit First 200 Rows, which displayed the following:

image

The 20th row (highlighted above) corresponds to the second selected row in the preceding capture. I confirmed that the resultset was correctly ordered by PartitionKey and RowKey values by observing the values uniformly increased by 6. Thus, deleting the first 20 rows and repeating the upload operation should solve the problem.

I selected and deleted the first 20 rows for a row count of 33,667 and repeated the upload process with the 4th federation member selected in the SQL Azure Federation Target page:

image

I was surprised to encounter a primary key constraint conflict after a few seconds:

image

The problem might be due to this limitation noted in SQL Server 2008 R2 Books Online’s DELETE (Transact-SQL) topic:

The rows referenced in the TOP expression used with INSERT, UPDATE, or DELETE are not arranged in any order.


Interim Conclusion

It would probably be easier and safer to simply delete the rows added by the process that failed and then attempt addition of the entire rowset for the individual member.

To do so for this case, I wanted to delete the last 50,000 rows, which should leave the 167 rows added by the first 1,000-row upload to the initial member with the following statement:

USE FEDERATION [WADFederation] (Id = 4) WITH FILTERING = OFF, RESET
GO

DELETE TOP(50000) FROM WADPerfCounters ORDER BY PartitionKey DESC, RowKey DESC
GO

However, DELETE … FROM doesn’t support an ORDER BY clause. Even if it did, the rows deleted might not be those expected because they “are not arranged in any order.”

I then asked the SQL Azure Federations Team for their recommendations for solving this problem.


Executing a MERGE Command to Add Missing Rows

imageUpdate 1/14/2012 8:45 AM PST: Cihan Biyikoglu (@cihangirb) of the SQL Azure Federations team recommended that I try the new MERGE (Transact-SQL) statement to eliminate the conflicts incurred with the preceding procedure. One of the statement’s options is to add new rows from a reference table to an existing federation member that don’t conflict with the member’s existing rows having the same primary key value.

MSDN’s Inserting, Updating, and Deleting Data by Using MERGE topic explains SQL Server 2008 R2 new command as follows:

In SQL Server 2008, you can perform insert, update, or delete operations in a single statement using the MERGE statement. The MERGE statement allows you to join a data source with a target table or view, and then perform multiple actions against the target based on the results of that join. For example, you can use the MERGE statement to perform the following operations:

  • Conditionally insert or update rows in a target table. If the row exists in the target table, update one or more columns; otherwise, insert the data into a new row.

  • Synchronize two tables. Insert, update, or delete rows in a target table based on differences with the source data.

The MERGE syntax consists of five primary clauses:

  • The MERGE clause specifies the table or view that is the target of the insert, update, or delete operations.

  • The USING clause specifies the data source being joined with the target.

  • The ON clause specifies the join conditions that determine where the target and source match.

  • The WHEN clauses (WHEN MATCHED, WHEN NOT MATCHED BY TARGET, and WHEN NOT MATCHED BY SOURCE) specify the actions to take based on the results of the ON clause and any additional search criteria specified in the WHEN clauses.

  • The OUTPUT clause returns a row for each row in the target that is inserted, updated, or deleted.

For complete details on the syntax and rules, see MERGE (Transact-SQL).

This MERGE option requires:

  1. Adding a reference (source) table with the same structure as the federation member (target)
  2. Using SQLAzureFedMW to upload the rows from the original upload’s source table that have matching CounterId values (4)
  3. Executing the appropriate MERGE statement

Creating an Empty WADPerfCounters4 Reference Data Table in WADFederation Member 4

I navigated to federation member 4, opened a new query and then added a WADPerfCounters4 reference table to the member with the following query:

CREATE TABLE [WADPerfCounters4](
    [PartitionKey] [bigint] NOT NULL,
    [RowKey] [varchar](100) NOT NULL,
    [Timestamp] [datetime2](7) NOT NULL,
    [EventTickCount] [bigint] NOT NULL,
    [DeploymentId] [varchar](50) NOT NULL,
    [Role] [varchar](20) NOT NULL,
    [RoleInstance] [varchar](20) NOT NULL,
    [CounterName] [varchar](100) NOT NULL,
    [CounterValue] [decimal](16,8) NOT NULL,
    [CounterId] [int] NOT NULL,
    CONSTRAINT [PK_WADPerfCounters] PRIMARY KEY CLUSTERED
    (
    [PartitionKey] ASC,
    [RowKey] ASC,
    [CounterId] ASC
    )
)

The above is the same query as that of Creating a SQL Azure Federation in the Windows Azure Platform Portal’s step 15 without the FEDERATED ON (Id = CounterID) instruction:

image


Uploading Data to a Reference Table with SQLAzureFedMW v1

I launched SQLAzureFedMigWiz and specified the local AzureDiagnostics database’s WADPerfCounters4 as the Data Source table, which has 66,333 rows:

image

I selected the Id (4 to 5) member as the SQL Azure Federation Target table:

image

Note: The destination table is specified by the name of the source table in all cases.

Here’s the data for the download from the local database:

image

and for the upload:

image

Here are the first few rows and columns of the table in the Portal’s UI:

image


Executing the MERGE Statement

Cihan Biyikoglu provided me with the the following MERGE statement:

MERGE INTO [WADPerfCounters] as target
USING WADPerfCounters4 as source
ON (target.[PartitionKey]=source.[PartitionKey]
    AND target.[RowKey]=source.[RowKey]
    AND target.[CounterId]=source.[CounterId])
WHEN NOT MATCHED BY TARGET THEN
INSERT ([PartitionKey], [RowKey], [Timestamp], [EventTickCount],
    [DeploymentId], [Role], [RoleInstance], [CounterName], [CounterValue],
    [CounterId])
VALUES(source.[PartitionKey], source.[RowKey], source.[Timestamp],
    source.[EventTickCount], source.[DeploymentId], source.[Role],
    source.[RoleInstance], source.[CounterName], source.[CounterValue],
    source.[CounterId]);

image

Executing the statement produced in a few seconds the following message indicating a successful result:

image

I then verified that the total row count included the 167 rows added by the first operation with 1,000 total rows:

image

All other federation members have 66,500 +/- 1 rows, so correct recovery is confirmed.


Investigating Strange Storage Values Reported by Federation Member Pop Ups

I noticed a strange variation in the space data reported by the pop ups for the boxes representing federation members:

image

The following table reports the row count, used space, free space and % filled values for each of the six presumably identically sized members:

CounterId Row Count Used Space, GB Free Space, GB % Filled
1 66,501 0.0204 0.9796 2.0386
2 66,500 0.0203 0.9797 2.0302
3 66,500 0.0174 0.9826 1.7395
4 66,500 0.0319 0.9681 3.1860
5 66,500 0.0159 0.9841 1.5892
6 66,499 0.0171 0.9829 1.7075

Part of the variation might be due to the relatively small size of the uploaded data, so I’m starting a 2 GB WADPerfCounters upload of 7,959,000 rows on 1/15/2012 at 8:30 AM PST in a single 10-hour batch. I’ve reported the results below.

SQLAzureFedMW created six BCP text files, each containing 1,326,500 rows with the same federation ID, in 00:01:24 and started uploading in parallel at 8:37 AM:

image

Here’s a capture of the federation member 1’s completion of the first batch of 500,000 rows on 1/15/2012 at 1:03 PM PST:

image

and the upload’s completion at 7:05 PM PST at a rate of 65.57 rows/sec:

image

The federation detail window’s member buttons show about 40% filled

image

The following table shows a similar pattern of differences in space statistics:

CounterId Row Count Used Space, GB Free Space, GB % Filled
1 1,393,001 0.4057 0.5943 40.5724
2 1,393,000 0.4057 0.5943 40.5716
3 1,393,000 0.3427 0.6573 34.2659
4 1,393,000 0.3378 0.6672 33.7830
5 1,393,000 0.3131 0.6869 31.3148
6 1,392,999 0.3321 0.6679 33.2146

The only varchar(n) field in the table that varies significantly in length is CounterName:

CounterID CounterName Length
1 \Network Interface(Microsoft Virtual Machine Bus Network Adapter _2)\Bytes Sent/sec 84
2 \Network Interface(Microsoft Virtual Machine Bus Network Adapter _2)\Bytes Received/sec 88
3 \ASP.NET Applications(__Total__)\Requests/Sec 46
4 \TCPv4\Connections Established 31
5 \Memory\Available Mbytes 25
6 \Processor(_Total)\% Processor Time 36

The pattern of Used Space and % Filled data follows the relative length of the CounterName, which might explain the differences. It’s clear that differences in average lengths of rows could play an important part in designing a sharding strategy that minimizes monthly cost.

Update 1/18/2011: Added another 7,958,995 rows to the WADFederation with SQLAzureFedMW v1.2 to reach about 80% full on members 1 and 2:

image

Note: The second group of 20 tab-separated values files used for this upload didn’t have the uniform 398,000 rows per page of the first group, as described in the Generating Big Data for Use with SQL Azure Federations and Apache Hadoop on Windows Azure Clusters post of 1/8/2012. The reason for this difference is clear at present.

The federation is now ready for performance testing of fan-out queries with the online Fan-Out Query Utility as described in Cihan Biyikoglu’s Introduction to Fan-out Queries (PART 1): Querying Multiple Federation Members with Federations in SQL Azure post of 12/29/2011. Stay tuned for a new post on this topic.


Tuesday, January 17, 2012

Loading Big Data into Federated SQL Azure Tables with the SQL Azure Federation Data Migration Wizard v1.2

Updated 1/17/2012 with change from v1.0 to v1.2 with the following release notes:

Release Notes
v1.2

  1. Added FederationInfo.txt to output directory containing Federation member range, member id, and physical database name.
  2. Added FederationMember into to BCP upload status so that you know which federation member data is being uploaded to.
v1.1
  1. SQLAzureMWUtils library 3.8.1
  2. Added error check for 08S01 in app.config file (for BCP retry).

See end of post for new v1.2 features. Although earlier screen captures show v0.3.0, this post was written with v1.0.


Most demonstrations, workshops and hands-on labs for SQL Azure Federations use simple T-SQL INSERT … VALUES() statements executed by copying and pasting into query editing windows of the SQL Azure Management Portal or SQL Server Management Studio 2008 R2 SP1. Obviously that approach won’t work for production applications.

imageGeorge Huey (@gihuey), a Microsoft Data Architect, is the author of the SQL Azure Migration Wizard (SQLAzureMW), which migrates entire SQL Server databases to SQL Azure. I described Using the SQL Azure Migration Wizard v3.3.3 with the AdventureWorksLT2008R2 Sample Database in a detailed 7/18/2010 post. SQLAzureMW was at v3.8 when I wrote this post.

You can use SQLAzureMW to upload data to existing federated SQL Azure tables, but George’s new (as of 12/12/2011) SQL Azure Federation Data Migration Wizard (SQLAzureFedMW) v1.2 is simpler and more straightforward for uploading data, especially Big Data.

For more information about SQL Azure Federations, see MSDN’s Federations in SQL Azure (SQL Azure Database) topic and its subtopics.

This tutorial explains how to use SQLAzureFedMW to load data from a local SQL Server 2008 R2 SP1 WADPerfCounters table into a federated WADPerfCounters table in the AzureDiagnostics1 root member of the WADFederation. Here’s the SQL Azure Portal’s query editing page displaying the first 5 columns of 10 rows from 398,000 rows uploaded in an initial test:

imageClick image for full-size (1024x768) screen captures.

Following is SQLAzureFedMW’s Target Server Response window (edited) displaying the results from the initial upload test:

image 

The 398,000 rows uploaded in 1,956 seconds (203.5 rows/sec) over a 384-kbps (upload) AT&T commercial DSL connection to Microsoft’s South Central US (San Antonio) data center.

About the SQL Azure Federation Data Migration Wizard

SQLAzureFedMW’s CodePlex project page begins as follows:

ProjectDescription
SQL Azure Federation Data Migration Wizard simplifies the process of migrating data from a single database to multiple federation members in SQL Azure Federation.

SQL Azure Federation Data Migration Wizard (SQLAzureFedMW) is an open source application that will help you move your data from a SQL database to (1 to many) federation members in SQL Azure Federation. SQLAzureFedMW is a user interactive wizard that walks a person through the data migration process.

The SQLAzureFedMW tool greatly simplifies the data migration process. …

SQLAzureFedMW Project Details
The SQL Azure Federation Data Migration Wizard (SQLAzureFedMW ) allows you to select a SQL Server database and specify which tables (Data Only) to migrate. The data will be extracted (via BCP) and then uploaded to SQL Azure Federation. The BCP data upload process can be done in a sequential process or parallel process (where you specify the number of parallel threads). See Documentation for more detail.

Note
SQLAzureFedMW expects that your database schema has already been migrated to SQL Azure Federation and that they tables on the source database match the tables in the federated member databases.

SQLAzureFedMW is [from] the SQLAzureMWUtils library found in the codeplex project SQL Azure Migration Wizard

Prerequisites

A Windows Azure account offering at least one 1-GB SQL Azure Web edition database, such as the new 3 Month Free Trial Account with a US$0 Spending Limit. Splitting the federation into six databases, which is optional, requires five more 1-GB databases costing about US$0.33/day each.

  • SQL Server 2008 R2 SP1 Express edition or higher
  • SQL Server Management Studio (SSMS) 2008 R2 SP1 Express edition or higher
  • SQLAzureFedMW v1.0
  • Windows 7 or Windows Server 2008 R2. George says it “should work fine on XP or Vista.”
  • .NET Framework 3.5 SP1 or later
  • The WADPerformanceCountersTable-1000rows.txt source data file from SkyDrive*

SSMS 2008 R2 SP1 is included with SQLEXPRADV_x64_ENU.exe, SQLEXPRADV_x86ENU.exe, SQLEXPRWT_x64_ENU.exe and SQLEXPRWT_x86_ENU.exe. SSMS is required to create the local data file that you upload to SQL Azure.

*This file is 258 KB in size and contains 1,000 rows of data with primary key values greater than those of the other WADPerformanceCountersTable*.txt files, which are 102+ MB and contain 398,000 rows. 1,000 rows reduces upload time to a few seconds with a reasonably fast DSL connection and minimizes time to split the federated tables by CounterId. You don’t need to delete the existing rows to prevent primary key violations when uploading other WADPerformanceCountersTable*.txt files in sequence, if you choose to do so.

Background

imageMy (@rogerjenn) Generating Big Data for Use with SQL Azure Federations and Apache Hadoop on Windows Azure Clusters post of 1/6/2012 describes how to create large data files containing historical Windows Azure Diagnostics (WAD) performance counter data. You can download from my SkyDrive account the text files of WAD data generated by Cerebrata Software’s Cloud Storage Studio and scripts to create the required WADPerfCounts table in a local SQL Server 2008 R2 SP1 [Express] instance, import the data into the table, and add/populate the CounterId federation key column.

Warning: Don’t use WADPerformanceCountersTable-Page-3.txt from WADPerformanceCountersTable-Page-3.zip; it throws data truncation errors, as described in the “Attempting to Deal with CounterValue Truncation Problems” section near the end of the above post.

My Creating a SQL Azure Federation in the Windows Azure Platform Portal post of 1/10/2012 shows you how create a new federation (WADFederation) and the required federation root database (AzureDiagnostics1) into which you import the data.

Installing SQLAzureFedMW

Download SQLAzureFedMW v1.0 Release Binary, open SQLAzureFedMW v1.0 Release Binary.zip, and extract its files to a \Program Files (x86)\SQLAzureFedMW folder or a folder of your choice.

Editing SQLAzureFedMW.exe Arguments in SQLAzureFedMW.exe.config to Prevent String Truncation Errors

Installing SQLAzureFedMW adds a SQLAzureFedMW.exe.config file in the directory containing SQLAzureFedMW.exe, the program’s executable. You must open SQLAzureFedMW.exe.config in Visual Studio (by default) or a text editor, such as Notepad, and change two Bulk Copy Protocol (BCP) -n arguments to -c as shown in the two red circles near the end of the <configuration> section:

image

Note: If you don’t change the -n arguments, you incur multiple string truncation errors when you attempt to upload data to the Federation and no data migrates. See MSDN’s bcp Utility topic for more information on bcp and its arguments, as well as Using Native Format to Import or Export Data (-n) and Using Character Format to Import or Export Data (-c).

Optionally, add your server name (after you create it) to the TargetServerName  value, administrative logon ID to the TargetUserName element, administrative password to the TargetPassword  element and AzureDiagostics1 to the TargetDatabase element after you create it to replace the default values in the Connect to Server dialogs.

Create a Local AzureDiagnostics Database with a WADPerfCounters Table

Refer to the “Creating the WADPerfCounters Table and Indexes” and “Testing the T-SQL BULK INSERT Command with a 1,000-row Sample File” sections of Generating Big Data for Use with SQL Azure Federations and Apache Hadoop on Windows Azure Clusters for instructions.

Change the C:\Users\Administrator\My Documents\Cerebrata\WADPerformanceCountersTable-Page-1.txt folder file path to where you stored the downloaded file and specify

SET DATEFORMAT ymd
BULK INSERT dbo.WADPerfCounters
FROM “C:\YourFilePath\WADPerformanceCountersTable-1000rows.txt”
WITH
(
FIRSTROW = 2,
LASTROW = 1001,
BATCHSIZE = 1000,
FIELDTERMINATOR = '\t'
)

as the command to load the data.

In the “Dealing with Non-Numeric Columns as Federation Keys” section, add the CounterId column with the int data type after the CounterValue column and change Network Adapter _2 to Network Adapter _3 in the two places emphasized below:

UPDATE dbo.WADPerfCounters SET CounterId =
    (CASE
        WHEN CounterName = '\Network Interface(Microsoft Virtual Machine Bus Network Adapter _3)\Bytes Sent/sec' THEN 1
        WHEN CounterName = '\Network Interface(Microsoft Virtual Machine Bus Network Adapter _3)\Bytes Received/sec' THEN 2
        WHEN CounterName = '\ASP.NET Applications(__Total__)\Requests/Sec' THEN 3
        WHEN CounterName = '\TCPv4\Connections Established' THEN 4
        WHEN CounterName = '\Memory\Available Mbytes' THEN 5
        WHEN CounterName = '\Processor(_Total)\% Processor Time' THEN 6
        ELSE 0
    END)
FROM dbo.WADPerfCounters

The number of virtualized Network Adapters changed while the diagnostics were collected.

Right-click the table and choose Select Top 1000 rows. Verify that the CounterId column values range from 1 to 6:

image

Create the AzureDiagnostics1 Database and the WADFederation

Follow all 19 steps in the Creating a SQL Azure Federation in the Windows Azure Platform Portal post to create the WADFederation and its AzureDiagnostics1 root member.

Connect to the Local Database and Create the BCP Data (*.dat) File

1. Launch SQLAzureFedMW.exe and, with the default Data Source tab displayed, click the Connect to Server button to open the eponymous dialog:

image

2. Accept the defaults and click Connect to open the Select Servers page. Select [AzureDiagnostics] and [dbo].[WADPerfCounters]:

image

3. Click the SQL Azure Federation Target tab and the Connect to Server dialog. Type your server name, administrative user name, @ and the server name, your password, and AzureDiagnostics1 in the Connect to Server dialog’s text boxes:

image

4. Click Connect and accept the default WADFederation and Id (Min to Max) settings:

image

5. Click Next and click Yes when asked “Are you ready to download data?” (from the local database to a BCP *.dat file) to display BCP Output Results:

image

6. Click Next and click Yes when asked “Are you ready to upload data?” (from the BCP *.dat file to the federated WADPerfCounters table in the AzureDiagnostics1 root database) to display Target Server Response Results:

image

7. Click Exit to close SQLAzureFedMW.

8. Return to the Windows Azure Management Portal and, if necessary, select the WADFederation1 item, and the right-arrow key to open the 1 Federation Member page, click the root federation box to open the WADFederation(LOW..HIGH) context menu, and select Query:

image 

9. Click the New Query link to open the query editing page in the context of the federation root member.

10. Type SELECT TOP(10) * FROM WADPerfCounters in the editing pane, click the Run button, and scroll to display the CounterId column:

image

11. Verify that CounterId values range between 1 and 6 by typing SELECT MIN(CounterId) FROM WADPerfCounters, clicking Run and SELECT MAX(CounterId)FROM WADPerfCounters, and clicking Run.

Split CounterId Values >  1 to Five More Member Databases

You must split the the WADFederation into a total of six members to gain the maximum benefit of horizontal partitioning afforded by Windows Azure Federations for the design imposed when you selected CounterID as the federation key early in the Generating Big Data for Use with SQL Azure Federations and Apache Hadoop on Windows Azure Clusters process.

Warning: If you have a 90 Day Trial Subscription, this will cost you ~US$1.65 per day until you delete the added member databases. If your subscription derives from a Visual Studio Ultimate MSDN subscription, you have five free 1-GB Web databases (if you haven’t used them), so the cost will be only ~US$0.33 per day.

1. Click the X and OK buttons to close the page without saving changes, open the context menu, select Split, and type 2 as the value on which to split:

image

2. Click the Split button and wait for completion. If you receive an error message regarding inability to connect to context, return to the main SQL Azure Portal page, click Manage and log on again:

image

Notice that the WADFederation count has increased to 2 from 1.

3. Click the right-arrow button to display the 2 Federations page which has gained a new box:

image

4. Click the LOW box, and repeat the preceding section’s step 10 to verify that only rows with a CounterId value of 1 appear:

image

5. Click the X and OK buttons to close the query editing window.

6. Repeat steps 1 through 4 four more times, starting with the newly added federation members box, incrementing the Split at value in step 2, and incrementing the verification value in step 4. Click the Refresh button to display the progress of the split operation.

image

Notice that the [Id] = # expression’s value increases by 1 for each operation when you run the SELECT TOP(10) * FROM WADPerfCounters query.

7. Your 6 Federation Members page appears as follows when you complete the operation:

image

Displaying Federation Metadata

MSDN’s Managing Database Federations (SQL Azure Database) topic offers links to five tables that provide federation metadata:

Federation Metadata Table Description
sys.federations (SQL Azure Database) Returns the federations within a database.
sys.federation_members (SQL Azure Database) Returns the federation members within a federation.
sys.federation_distributions (SQL Azure Database) Returns the distribution type and data types used by a federation.
sys.federation_member_distributions (SQL Azure Database) Returns the distribution name and range covered by a federation member.
sys.federated_table_columns (SQL Azure Database) Returns federation specific information on federated tables.

The most interesting of these tables is sys.federation_member_distributions. Querying federation metadata tables requires executing

USE FEDERATION ROOT WITH RESET
GO

before the SELECT statement:

image

You can specify a single range value explicitly by updating the -2147483648 range_low value for the first member with 1, and updating all numeric range_high values with null.

Auto-sharding Larger Data Batches

After you partition your federation, uploading additional rows with all six CounterId values automatically distributes the rows to one of the six federation members. The SkyDrive folder includes a WADPerformanceCountersTable-Page-79.zip file that contains a *.txt file with the 398,000 rows preceding the 1,000 you uploaded earlier. You can use this field to test autosharding without encountering primary key violations.

1. Download and extract WADPerformanceCountersTable-Page-79.txt from WADPerformanceCountersTable-Page-79.zip to the same folder you created earlier in this tutorial.

2. Launch SSMS, connect to your server, delete all rows from the WADPerfCounters table, and delete the CounterId column.

3. Repeat the process of the “Create a Local AzureDiagnostics Database with a WADPerfCounters Table” but replace 1000rows.txt with Page-79.txt.

4. Repeat steps 1 through 7 of the earlier “Connect to the Local Database and Create the BCP Data (*.dat) File” section. In step 4, select all six federation members:

image


5. When you click Yes to upload data in step 6, the Target Server Response window generates a tab for each of the six shards and uploads them simultaneously on six different threads:

image

Note: The number of threads supported is set by the NumberOfBCPThreads key of the SQLAzureFedMW.exe.config file.

6. During upload, the following error messages appeared in the rightmost page:

image

Note: Error code 08S01 indicates a network failure. Several early SQL Azure adopters have reported similar communication link failures with conventional (not federated) tables. See the comments to Wayne Walter Berry’s BCP and SQL Azure post of 5/21/2011 to the SQL Azure blog.

7. Clicking the Results tab displayed the following page:

image

66,333 * 6 = 397,998, which is within 2 of the total row count of 398,000.

36.47 rows/sec * 6 = 218.82 rows/sec which is close to that of the first example at the beginning of this post, 203.5 rows/sec.

8. Clicking Retry on the page with errors resumed uploading rows, but the upload failed with a primary key constraint violation because some :

image

9. Clicking Skip stopped the attempted upload and reported Done:

image 

10. According to George, you can trap and retry on the 08S01 error by adding it to the SQLAzureFedMW.exe.config file’s BCPSQLAzureErrorCodesRetry element, as shown here:

image

Update 1/17/2012: As of v1.1, retry for error 08S01 is included in the BCPSQLAzaureErrorCodesRetry list.

A new post about recovering from errors such as this has been added as Adding Missing Rows to a SQL Azure Federation with the SQL Azure Federation Data Migration Wizard v1 updated 1/15/2012. In most cases, you should add missing rows before you attempt to add more rows to federation members.

Update 1/17/2012: Following is the range Id value added to the Target Server Response delay:

image