SE の雑記

SQL Server の情報をメインに Microsoft 製品の勉強内容を日々投稿

SQL Database で Elastic Scale Preview が公開されました

one comment

SQL Database で Elastic Scale の Preview が公開されました。
Introducing Elastic Scale preview for Azure SQL Database

ぺんぺんししょーが Azure SQL Database Elastic Scale の5大改良点 ? Federationの失敗を糧にしたサービス でまとめてくださっていますので自分メモを少々。

Elastic Scale の詳細については、
Get Started with Azure SQL Database Elastic Scale Preview
Azure SQL Database Elastic Scale Topics
Azure SQL Database Elastic Scale Libraries for .NET
Elastic Scale with Azure SQL Database – Getting Started
Azure SQL Database – Federations Migration

Azure SQL Database Elastic Scale
を見ていただくとよいかと思います。

基本的なライブラリは Nuget で公開されています。
Azure SQL Database Elastic Scale Client Library

Azure SQL Database Elastic Scale Split-Merge Service

なお、サンプルもすでに公開されています。
Elastic Scale with Azure DB – Getting Started
Elastic Scale with Azure DB – Entity Framework Integration
Federations Migration Utility
Elastic Scale for Azure SQL DB ? ShardSqlCmd
Azure SQL Database Elastic Scale: Shard Elasticity

Elastic Scale はライブラリを使用して、水平分割 (シャーディング) を行うものになります。
以前提供されていた Federation が SQL Database の機能としてシャーディングを提供していましたが、それを API として実装したものになる感じでしょうか。

Web / Business の終了に伴いこれらの Edition で Federation を使用している場合には、Elastic Scale または、独自に実装した Federation への移行が必要となってきます。
Federations Migration

Elastic Scale についての基本的な用語は Elastic Scale Glossary に記載されていますので、こちらに目を通しておくとよさそうです。

ベースとなる考え方は Federation に似ているかと思いますので、以前触ったことがある方はイメージがしやすいのではと思っています。

Federation では [USE FEDERATION] を使用して、どのメンバーを使用するかを判断していましたが、Elastic Scale では、Shard Map を用いてどのシャードに接続をするかが管理されています。
分割 (シャーディング) については、範囲 (レンジ) または、リスト (Federation ではなかったシャーディング) を使用することができます。 
Shard Map Management

どのシャードがどの範囲のデータを保持しているかという情報については、Shard Map Manager に保持がされており、この管理情報の実体は SQL Database のデータベースとなります。
サンプルの Elastic Scale with Azure DB – Getting Started  を使用して、Shard Map Manager を作成したものがこちらになります。
サンプルを実行すると、Shard Map Manager として、ElasticScaleStarterKit_ShardMapManagerDb が作成されます。
image

このデータベースに管理用の情報が格納されており、DB への接続はこの Shard Map Manager にシャーディングキーを指定して接続をすることで、対象のデータを保持するシャードに透過的に接続がされるという仕組みになるようです。
USE FEDERATION を指定して対象のフェデレーションメンバーに接続をしていたもの  (SQL Database の機能を利用) を API を使用して (プログラム的に対応) 接続するように変わったという感じでしょうか。間違っていたらごめんなさい。

Multi Shard Query をサポートしており、全シャードに対してクエリの実行をすることが可能です。
各シャードに対してクエリを実行しその結果を結合しているようなので、全体ソートや集計については取得した後に実施する等の考慮が必要なのかなと。
image

Shard Map Manager のデータベースは以下のように構成されています。
image

各テーブルには以下のような情報が格納されています。

SELECT * FROM [__ShardManagement].[OperationsLogGlobal]
SELECT * FROM [__ShardManagement].[ShardedDatabaseSchemaInfosGlobal]
SELECT * FROM [__ShardManagement].[ShardMapManagerGlobal]
SELECT * FROM [__ShardManagement].[ShardMappingsGlobal]
SELECT * FROM [__ShardManagement].[ShardMapsGlobal]
SELECT * FROM [__ShardManagement].[ShardsGlobal]

image

Shard Set を構成するサーバーの情報については [__ShardManagement].[ShardsGlobal] に格納されており、シャードの範囲については、 [__ShardManagement].[ShardMappingsGlobal] に格納されているようですね。

シャーディングの対象と参照テーブル (Reference Table) の情報については、[__ShardManagement].[ShardedDatabaseSchemaInfosGlobal] に XML で格納されているようです。

# SchemaInfo ClassShardedTableInfoReferenceTableInfo を Add して、各テーブルの役割を明示的に指定する必要はあるようですが。

<Schema xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <ReferenceTableSet i:type="ArrayOfReferenceTableInfo">
    <ReferenceTableInfo>
      <SchemaName>dbo</SchemaName>
      <TableName>Regions</TableName>
    </ReferenceTableInfo>
    <ReferenceTableInfo>
      <SchemaName>dbo</SchemaName>
      <TableName>Products</TableName>
    </ReferenceTableInfo>
  </ReferenceTableSet>
  <ShardedTableSet i:type="ArrayOfShardedTableInfo">
    <ShardedTableInfo>
      <SchemaName>dbo</SchemaName>
      <TableName>Customers</TableName>
      <KeyColumnName>CustomerId</KeyColumnName>
    </ShardedTableInfo>
    <ShardedTableInfo>
      <SchemaName>dbo</SchemaName>
      <TableName>Orders</TableName>
      <KeyColumnName>CustomerId</KeyColumnName>
    </ShardedTableInfo>
  </ShardedTableSet>
</Schema>

参照テーブルについてはシャーディング対象ではないが、各データベースで必要となるマスター系のテーブルになり、

Reference tables: Tables that are not sharded but are replicated across shards.

のように説明がされています。

ここでいうレプリケーションなのですが、Split/Merge を実行した際に、新しく作成したシャードに対して、参照テーブルのデータをコピーするというものになるようです。

これについては Splitting and Merging with Elastic Scale で説明がされています。

Reference tables: For reference tables, the split, merge and move operations copy the data from the source to the target shard. Note, however, that no changes occur on the target shard for a given table if any row is already present in this table on the target. The table has to be empty for any reference table copy operation to get processed. 

参照テーブルの管理は全シャードに対して実施するケースもあるかと思いますので、この辺のメンテナンスは考慮しておく必要がありそうです。

参照テーブルについては Foreign Key を使用して整合性を保つ必要があるかもですね。

# サンプルの参照テーブルは Foreign Key が設定されています。

Referential Integrity: The Split/Merge service analyzes dependencies between tables and uses foreign key-primary key relationships to stage the operations for moving reference tables and shardlets. In general, reference tables are copied first in dependency order, then shardlets are copied in order of their dependencies within each batch. This is necessary so that FK-PK constraints on the target shard are honored as the new data arrives.

 

シャードの管理情報は、Shard Map Management によると、Global Shard Map (GSM) / Local Shard Map (LSM) / Application Cache に分類され、Shard Map Manager は GSM になるかと。

各シャードには LSM が保持されており、GSM の自シャード分の情報になるようですね。

image

SELECT * FROM [__ShardManagement].[ShardMapManagerLocal]
SELECT * FROM [__ShardManagement].[ShardMappingsLocal]
SELECT * FROM [__ShardManagement].[ShardMapsLocal]
SELECT * FROM [__ShardManagement].[ShardsLocal]

image

シャードを Split/Merge する仕組みも Splitting and Merging with Elastic Scale 提供されています。

詳しい流れは、Elastic Scale Split and Merge Service Tutorial に記載されていますが、Split-Merge Service 用のクラウドサービス (Worker Role のインスタンス) を構築し、そのエンドポイントに対して管理者が PowerShell 経由で要求を送るまでの一連の作業が記載されています。

また、Azure Automation 用の PowerShell のサンプルも公開されていますね。

Azure SQL Database Elastic Scale: Shard Elasticity

とりあえずはかけるところまでザクッと。

時間があるときに検証をして、後で本投稿を補完しておきたいと思います。

Share

Written by Masayuki.Ozawa

10月 3rd, 2014 at 8:53 am

Posted in SQL Database

Tagged with

One Response to 'SQL Database で Elastic Scale Preview が公開されました'

Subscribe to comments with RSS or TrackBack to 'SQL Database で Elastic Scale Preview が公開されました'.

  1. […] それムッシュが知ってるよ → SQL Database で Elastic Scale Preview が公開されました […]

Leave a Reply