Confidential & Proprietary
CloudSpanner
Cloud Spanner は、エンタープライズ クラスで唯一の、
グローバルに分散され、強整合性を備えたデータベース
サービスです。リレーショナル データベースの構造と
非リレーショナル データベースの水平スケーラビリティを
兼ね備え、クラウドに特化した設計となっています。
Great apps run on great databases.
Confidential & Proprietary
Datais synchronously replicated using Paxos consensus.
Update
Cloud Spanner instance
Zone A Zone B Zone C
DB 1
DB 2
DB 1
DB 2
DB 1
DB 2
Synchronous レプリケーションと高整合性
Confidential & Proprietary
id(PK) name address gender
101 samir tokyo m
102 hassy tokyo m
:
1001
1002
:
2001
2002
Table
Data Split 1
Data Split 2
Data Split 3
Key 101~1000
Key 1001~2000
Key 2001~2999
Split とは?
20.
Confidential & Proprietary
NSNS NS NS
Zone 1 Zone 2
G-NA-F S-ZO-R G-NA-F S-Z O-R
Splits
Node Servers
100% Key Coverage
per Zone
Split のレイアウト
Confidential & Proprietary
CloudSpanner には2種類のトランザクション:
1. Locking read-write transaction (mutation)
a. 悲観的ロック
a. 読み書きするセルのみをロック
2. Read-only transaction
a. 3 種類
i. Strong (デフォルト) :最新のデータを読む
ii. Bounded staleness:指定した範囲から最新のデータを読む
iii. Exact staleness:指定したタイムスタンプのデータを読む
b. ロックを行わない
トランザクションタイプ
Confidential & Proprietary
なぜテーブルを
インターリーブするか
user_id
SELECTuser_name, item_id FROM users INNER JOIN items ON users.user_id = items.user_id WHERE user_id = 1234;
user_id user_name
1111 john
1122 paul
1234 bob
user_id item_id
1111 001
1111 002
1234 001
user_name
user_id
item_id
1111 john
1122 paul
1234 bob
1111 001
1111 002
1234 001
Spanserver A Spanserver B
1111 john
1111 001
1111 002
1122 paul
1234 bob
1234 001
Spanserver A
Logical View Physical View
No interleave
Physical View
With interleave
インタリーブをすると、 JOIN クエリ
が2つのサーバにアクセスすることも
なく、1サーバで済む
Confidential & Proprietary
よく聞かれる2点
●Index を利用するには、明示的に指定する必要がある
FROM MyTable@{FORCE_INDEX=MyTableIndex}
● Index の STORING 機能を利用して、元テーブルにアクセスを避ける
CREATE INDEX AlbumsByAlbumTitle2 ON Albums(AlbumTitle) STORING
(MarketingBudget)
51.
Confidential & Proprietary
QueryPlan Cache
SQL クエリを Spanner で使用する際に、bound parameters を使用す
るのが重要です。
Cloud Spanner のノードは query plan cache の数が限られています。
クエリの中に静的パラメータを使用すると、各クエリが違うものと見られ
て、query plan cache を効果的に活用することができません。この問題
を避けるには、以下の例のようにクエリは parameter binding を利用す
る必要があります。
Statement statement = Statement
.newBuilder("SELECT name WHERE id > @msg_id AND
id < @msg_id + 100")
.bind("msg_id").to(500)
.build();
これ重要!
Confidential & Proprietary
イノベーションのために時間を作ろう!
Focuson value add and
innovation instead of
maintenance.
Simplify costing to better
understand your app.
Ensure your app stays online
and more secure - 99.999%
SLA.