More Related Content Similar to HBase at Ameba (20) More from Toshihiro Suzuki (8) HBase at Ameba1. Developers
Summit
HBase
at
Ameba
~AmebaのおけるHBaseの導入事例~
14-A-2 鈴木俊裕
#devsumiA
株式会社サイバーエージェント
アメーバ事業本部
プラットフォーム部門
Developers Summit 2013 Action !
Ameba Technology Laboratory
2. Developers
Summit
自己紹介
• 鈴木 俊裕(すずき としひろ)
• ソフトウェアエンジニア
• 株式会社サイバーエージェント
– アメーバ事業本部
– プラットフォーム部門
– Ameba
Technology
Laboratory
• Hadoopを使ったログ解析基盤の開発・運用
• HBaseをつかった基盤システムの開発・運用
• Twi;er
@brfrn169
Developers Summit 2013 Action !
3. Developers
Summit
今日話したいこと
• HBaseについて
• AmebaにおけるHBaseの導入事例
– グラフDB「Hornet」
– 社内ライブラリ「Json
Persister」
Developers Summit 2013 Action !
5. Developers
Summit
HBaseとは
• いわゆる「NoSQL」のひとつ
• Googleの基盤ソフトウェアである「Bigtable」の
オープンソースクローン
Developers Summit 2013 Action !
6. Developers
Summit
HBaseとは
• 分散ストレージ
– 高可用性
– 高パフォーマンス
– 多次元ソートマップ
Developers Summit 2013 Action !
7. Developers
Summit
HBaseの使いどころ
• 大量のデータ
– そこまでデータが大きくならないなら必要ない
• Auto
Sharding
– データが自動的に分割され、負荷分散されていく
– 運用コスト削減
Developers Summit 2013 Action !
8. Developers
Summit
HBaseのアーキテクチャ
• マスタ型
HMaster(HBase)
Zookeeper
HRegionServer(HBase)
HRegionServer(HBase)
・・・
HDFS(Hadoop
Distributed
File
System)
Developers Summit 2013 Action !
9. Developers
Summit
HBaseのアーキテクチャ
• HDFS(Hadoop
Distributed
File
System)
– 分散ファイルシステム
– レプリカをデフォルトで3つ持つので信頼性が高い
• HBaseの信頼性はHDFSに依存している
Developers Summit 2013 Action !
10. Developers
Summit
HBaseのデータモデル
・部分的にはRDBに似ている
Column
Value
RowKey
(主キー、辞書順で
ソートされている)
ColumnFamily1
ColumnFamily2
Column1
Column2
Column3
Column4
Column5
row1
row2
row3
row4
row5
aaa
bbb
NULL
ccc
ddd
row6
row7
row8
Developers Summit 2013 Action !
11. Developers
Summit
HBaseのデータモデル
Columnは
ColumFamilyによって
・でもちょっと違う
グルーピング
Valueは複数バージョン
を持つ
ColumnFamily1
ColumnFamily2
Column1
Column2
Column3
Column4
Column5
row1
row2
row3
row4
row5
aaa
▼ bbb
▼ NULL
ccc
▼ ddd
▼
row6
fff
hhh
iii
row7
ggg
jjj
row8
Developers Summit 2013 Action !
12. Developers
Summit
HBaseのデータモデル
・データの分散の単位について
ColumnFamily1
ColumnFamily2
Column1
Column2
Column3
Column4
Column5
row1
row2
row3
row4
row5
row6
row7
row8
Developers Summit 2013 Action !
13. Developers
Summit
HBaseのデータモデル
RowKeyの範囲で
・データの分散の単位について
Regionに分割される
ColumnFamily1
ColumnFamily2
Column1
Column2
Column3
Column4
Column5
row1
Region1
row2
row3
row4
row5
Region2
row6
row7
row8
Developers Summit 2013 Action !
14. Developers
Summit
HBaseのデータモデル
• 各Regionはそれぞれ1つのHRegionServerに
割り当てられる
• Rowの更新処理はアトミックに行われる
– 同じRowは必ず同じHRegionServerに割り当てら
れる
– CASやIncrementもできる
Developers Summit 2013 Action !
15. Developers
Summit
HBaseのデータモデル
・データファイルについて
ColumnFamily1
ColumnFamily2
Column1
Column2
Column3
Column4
Column5
row1
row2
row3
row4
row5
row6
row7
row8
Developers Summit 2013 Action !
16. Developers
Summit
HBaseのデータモデル
・データファイルについて
ColumnFamily1
ColumnFamily2
Column1
Column2
Column3
Column4
Column5
row1
row2
row3
ファイル1
ファイル2
row4
row5
row6
row7
ファイル3
ファイル4
row8
Developers Summit 2013 Action !
17. Developers
Summit
HBaseのデータモデル
• 列指向データフォーマット
• ColumnFamilyはI/Oを分散したいときに使う
Developers Summit 2013 Action !
18. Developers
Summit
HBaseのデータモデル
・各データファイルの実際の構造について
RowKey
+
ColumnFamily
+
Column
+
Timestamp
でソートされている
RowKey
ColumnFamily
Column
Timestamp
value
row1
ColumnFamily1
Column1
100
aaa
row1
ColumnFamily1
Column2
200
bbb
row2
ColumnFamily1
Column1
140
111
row2
ColumnFamily1
Column2
300
rrr
row3
ColumnFamily1
Column1
400
fff
row5
ColumnFamily1
Column1
130
333
row5
ColumnFamily1
Column1
500
uuu
row5
ColumnFamily1
Column2
300
555
Developers Summit 2013 Action !
19. Developers
Summit
HBaseのデータモデル
・各データファイルの実際の構造について
複数Columnを持っているときは、
複数エントリになる
RowKey
ColumnFamily
Column
Timestamp
value
row1
ColumnFamily1
Column1
100
aaa
row1
ColumnFamily1
Column2
200
bbb
row2
ColumnFamily1
Column1
140
111
row2
ColumnFamily1
Column2
300
rrr
row3
ColumnFamily1
Column1
400
fff
row5
ColumnFamily1
Column1
130
333
row5
ColumnFamily1
Column1
500
uuu
row5
ColumnFamily1
Column2
300
555
Developers Summit 2013 Action !
20. Developers
Summit
HBaseのデータモデル
・各データファイルの実際の構造について
ColumnがNULLの場合は、
保存されない
RowKey
ColumnFamily
Column
Timestamp
value
row1
ColumnFamily1
Column1
100
aaa
row1
ColumnFamily1
Column2
200
bbb
row2
ColumnFamily1
Column1
140
111
row2
ColumnFamily1
Column2
300
rrr
row3
ColumnFamily1
Column1
400
fff
row5
ColumnFamily1
Column1
130
333
row5
ColumnFamily1
Column1
500
uuu
row5
ColumnFamily1
Column2
300
555
Developers Summit 2013 Action !
21. Developers
Summit
HBaseのデータモデル
・各データファイルの実際の構造について
複数バージョンを持って
いる場合は、Timestamp
のみ違うエントリになる
RowKey
ColumnFamily
Column
Timestamp
value
row1
ColumnFamily1
Column1
100
aaa
row1
ColumnFamily1
Column2
200
bbb
row2
ColumnFamily1
Column1
140
111
row2
ColumnFamily1
Column2
300
rrr
row3
ColumnFamily1
Column1
400
fff
row5
ColumnFamily1
Column1
130
333
row5
ColumnFamily1
Column1
500
uuu
row5
ColumnFamily1
Column2
300
555
Developers Summit 2013 Action !
22. Developers
Summit
HBaseのデータモデル
• ColumnFamilyは予め定義する必要がある
– ファイルの分割単位
• Columnは後からいくらでも追加することがで
きる
– データファイル内でエントリが増えるだけ
Developers Summit 2013 Action !
23. Developers
Summit
HBaseのデータモデル
• 従来のRDB(むりやり,
インデックスとか無視)
– table
-‐>
SortedMap<PrimaryKey,
Record>
– Record
-‐>
Map<Column,
Value>
• HBase
– table
-‐>
SortedMap<RowKey,
Record>
– Record
-‐>
Map<ColumnFamily,
SortedMap<Column,
SortedMap<Timestamp,
Value>>>
Developers Summit 2013 Action !
24. Developers
Summit
HBaseのAPI
• Get
– Rowの全Columnまたは一部ColumnのValueを取
得
• Put
– Rowの挿入、または更新
• Delete
– Row全体、一部Column、一部バージョンの削除
Developers Summit 2013 Action !
25. Developers
Summit
HBaseのAPI
• Scan
– 任意の行をスキャン
• 範囲を指定
• フィルタを指定
• Increment
– Valueをインクリメント
• CAS
– Compare
And
Swap
– 簡単なトランザクションを実現できる
Developers Summit 2013 Action !
26. Developers
Summit
HBaseの設計の考え方
• RowKeyの範囲でRegionに分割されて負荷分
散される
– RowKeyの設計次第では負荷やデータ量が偏る
可能性がある
• RowKeyで辞書順にソートされている
– 連続したRowはScanでまとめてとることができる
ので、1度に取りたいデータは連続して置いておく
Developers Summit 2013 Action !
27. Developers
Summit
HBaseの設計の考え方
• RowのColumnをいくらでも増やすことができる
し、ソートもされている。しかも更新処理がアト
ミック
– ただし、データが偏る可能性あり
• Joinがない
– 非正規化がほぼ前提
Developers Summit 2013 Action !
28. Developers
Summit
HBaseの設計の考え方
• クエリに対してスキーマが決まる
– RDBのようにデータ設計を最初にやらない
– まずクエリを考えてから、どういうスキーマにして
いくかを考える
Developers Summit 2013 Action !
29. Developers
Summit
参考までに
• CodeZineの連載「初めてのHBase」
– h;p://codezine.jp/argcle/corner/473
Developers Summit 2013 Action !
31. Developers
Summit
背景
• 昨年、「Ameba」のスマートフォン向けプラット
フォームをリリース
Developers Summit 2013 Action !
32. Developers
Summit
背景
• デカグラフ構想
– 各サービスのユーザー層を「ミニグラフ」と位置づ
け、1つの巨大なスマートフォン向けサービス(デ
カグラフ)を構築するという構想
ミニグラフ
デカグラフ
ミニグラフ
ミニグラフ
ミニグラフ
ミニグラフ
ミニグラフ
Developers Summit 2013 Action !
33. Developers
Summit
背景
• そこで、ユーザのグラフ構造を保持するデー
タベースが必要
– データが大量になるのでスケールするデータベー
ス
– オンライン処理
• 低レスポンスタイム
• 高スループット
Developers Summit 2013 Action !
34. Developers
Summit
背景
• 今までは、MySQL
+
Sharding
Ameba
Pigg
Ameba
グルっぽ
Ameba
なう
Developers Summit 2013 Action !
35. Developers
Summit
背景
• MySQL
+
Sharding
– 書き込みがスケールしにくい
– Shardの管理が大変
HBase
Developers Summit 2013 Action !
36. Developers
Summit
なぜHBaseか
• スケールする
• 書き込みが速い、そこそこの読み込み速度
• Range
Scan
• CAS、Increment
• Auto
Sharding
• ログ解析基盤にHadoopを用いていたため、ノ
ウハウがあった
Developers Summit 2013 Action !
37. Developers
Summit
Hornetのデータモデル
• プロパティグラフ
リレーションシップ
ノード
リレーションシップのtype
ノードID
2
follow
1
date
2013-‐01-‐01
Name
Ichiro
favorite
true
Age
29
Name
Toshihiro
age
29
follow
date
2013-‐01-‐10
3
ノードの
favorite
false
プロパティ
Name
Masahiro
リレーションシップの
Age
27
Developers Summit 2013 Action !
プロパティ
38. Developers
Summit
Hornetのアーキテクチャ
• HBase
+
Gateway(Java)
Client
RPC
Gateway Gateway Gateway
HBase
HDFS
Developers Summit 2013 Action !
39. Developers
Summit
HornetのJava
API
・ノードの作成
Node
user1
=
graphDbService.createNode();
Developers Summit 2013 Action !
40. Developers
Summit
HornetのJava
API
・ノードのプロパティのセット
user1.setProperty("name",
Bytes.toBytes("Toshihiro"));
Developers Summit 2013 Action !
41. Developers
Summit
HornetのJava
API
・リレーションの作成(typeは”follow”)
Node
user1
=
graphDbService.createNode();
Node
user2
=
graphDbService.createNode();
Relagonship
rel
=
user1.createRelagonshipTo(user2,
"follow");
Developers Summit 2013 Action !
42. Developers
Summit
HornetのJava
API
・リレーションのプロパティのセット
rel.setProperty("date",
Bytes.toBytes(System.currentTimeMillis()));
Developers Summit 2013 Action !
43. Developers
Summit
HornetのJava
API
・隣接ノードの取得
//
user1が“follow”している人を取得する
List<Result>
res
=
user1.select("follow",
Direcgon.OUTGOING).getAll();
//
user1を“follow”している人を取得する
res
=
user1.select("follow",
Direcgon.INCOMING).getAll();
Developers Summit 2013 Action !
44. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• RowKey:
– hash(startNodeId)
+
startNodeId
+
type
+
direcgon
+
(Long.MAX_VALUE
-‐
gmestamp)
+
endNodeId
• ColumnFamily:
– “h”
• Column:
– “”
(空のバイト配列)
• Value:
– シリアライズしたプロパティ
Developers Summit 2013 Action !
45. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの追加(1が2をフォローする)
2
follow
1
date
2013-‐01-‐01
Name
Ichiro
favorite
true
Age
29
Name
Toshihiro
age
29
3
Name
Masahiro
Developers Summit 2013 Action !
Age
27
47. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの追加(1が2をフォローする)
RowKey
Column
value
Key
hash(1)
+
1
+
follow
+
OUTGOING
+
200
+
2
h:
date=2013-‐01-‐01,
favorite=true
hash(2)
+
2
+
follow
+
INCOMING
+
200
+
1
h:
date=2013-‐01-‐01,
favorite=true
方向
ノードID
ノードID
プロパティの値
タイプ
Long.MAX_VALUE
-‐
ノードIDのハッシュ値
gmstamp
Developers Summit 2013 Action !
48. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの追加(1が3をフォローする)
2
follow
1
date
2013-‐01-‐01
Name
Ichiro
favorite
true
Age
29
Name
Toshihiro
follow
age
29
date
2013-‐01-‐10
favorite
false
3
Name
Masahiro
Developers Summit 2013 Action !
Age
27
49. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの追加(1が3をフォローする)
RowKey
Column
value
Key
hash(1)
+
1
+
follow
+
OUTGOING
+
200
+
2
h:
date=2013-‐01-‐01,
favorite=true
hash(2)
+
2
+
follow
+
INCOMING
+
200
+
1
h:
date=2013-‐01-‐01,
favorite=true
Developers Summit 2013 Action !
50. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの追加(1が3をフォローする)
RowKey
Column
value
Key
hash(1)
+
1
+
follow
+
OUTGOING
+
100
+
3
h:
date=2013-‐01-‐10,
favorite=false
hash(1)
+
1
+
follow
+
OUTGOING
+
200
+
2
h:
date=2013-‐01-‐01,
favorite=true
hash(3)
+
3
+
follow
+
INCOMING
+
100
+
1
h:
date=2013-‐01-‐10,
favorite=false
hash(2)
+
2
+
follow
+
INCOMING
+
200
+
1
h:
date=2013-‐01-‐01,
favorite=true
Developers Summit 2013 Action !
51. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの取得(1がフォローしてる人を取得)
2
follow
1
date
2013-‐01-‐01
Name
Ichiro
favorite
true
Age
29
Name
Toshihiro
follow
age
29
date
2013-‐01-‐10
favorite
false
3
Name
Masahiro
Developers Summit 2013 Action !
Age
27
52. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの取得(1がフォローしてる人を取得)
hash(1)
+
1
+
follow
+
OUTGOING
でプレフィックススキャン
RowKey
Column
value
Key
hash(1)
+
1
+
follow
+
OUTGOING
+
100
+
3
h:
date=2013-‐01-‐10,
favorite=false
hash(1)
+
1
+
follow
+
OUTGOING
+
200
+
2
h:
date=2013-‐01-‐01,
favorite=true
hash(3)
+
3
+
follow
+
INCOMING
+
100
+
1
h:
date=2013-‐01-‐10,
favorite=false
hash(2)
+
2
+
follow
+
INCOMING
+
200
+
1
h:
date=2013-‐01-‐01,
favorite=true
Developers Summit 2013 Action !
53. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの取得(1がフォローしてる人を取得)
hash(1)
+
1
+
follow
+
OUTGOING
でプレフィックススキャン
RowKey
Column
value
Key
hash(1)
+
1
+
follow
+
OUTGOING
+
100
+
3
h:
date=2013-‐01-‐10,
favorite=false
hash(1)
+
1
+
follow
+
OUTGOING
+
200
+
2
h:
date=2013-‐01-‐01,
favorite=true
hash(3)
+
3
+
follow
+
INCOMING
+
100
+
1
h:
date=2013-‐01-‐10,
favorite=false
hash(2)
+
2
+
follow
+
INCOMING
+
200
+
1
h:
date=2013-‐01-‐01,
favorite=true
Developers Summit 2013 Action !
54. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの取得(2をフォローしてる人を取得)
2
follow
1
date
2013-‐01-‐01
Name
Ichiro
favorite
true
Age
29
Name
Toshihiro
follow
age
29
date
2013-‐01-‐10
favorite
false
3
Name
Masahiro
Developers Summit 2013 Action !
Age
27
55. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの取得(2をフォローしてる人を取得)
hash(2)
+
2
+
follow
+
INCOMING
でプレフィックススキャン
RowKey
Column
value
Key
hash(1)
+
1
+
follow
+
OUTGOING
+
100
+
3
h:
date=2013-‐01-‐10,
favorite=false
hash(1)
+
1
+
follow
+
OUTGOING
+
200
+
2
h:
date=2013-‐01-‐01,
favorite=true
hash(3)
+
3
+
follow
+
INCOMING
+
100
+
1
h:
date=2013-‐01-‐10,
favorite=false
hash(2)
+
2
+
follow
+
INCOMING
+
200
+
1
h:
date=2013-‐01-‐01,
favorite=true
Developers Summit 2013 Action !
56. Developers
Summit
Hornetのスキーマ(リレーションシップ)
• 例:リレーションシップの取得(2をフォローしてる人を取得)
hash(2)
+
2
+
follow
+
INCOMING
でプレフィックススキャン
RowKey
Column
value
Key
hash(1)
+
1
+
follow
+
OUTGOING
+
100
+
3
h:
date=2013-‐01-‐10,
favorite=false
hash(1)
+
1
+
follow
+
OUTGOING
+
200
+
2
h:
date=2013-‐01-‐01,
favorite=true
hash(3)
+
3
+
follow
+
INCOMING
+
100
+
1
h:
date=2013-‐01-‐10,
favorite=false
hash(2)
+
2
+
follow
+
INCOMING
+
200
+
1
h:
date=2013-‐01-‐01,
favorite=true
Developers Summit 2013 Action !
57. Developers
Summit
まとめ
• HBaseを用いたグラフDB「Hornet」
– スキーマ設計について
• 今後
– オープンソースで公開したい
Developers Summit 2013 Action !
59. Developers
Summit
背景
• 弊社ではサービスを複数ラインで同時に開発
している
• スピード感は命であり、いかに開発スピードを
あげられるかが非常に重要
Developers Summit 2013 Action !
60. Developers
Summit
背景
• データベースに着目
• 一部基盤化はされているものの
• 各サービスでデータベースを立てている状況
– MySQL
– Redis
– …etc
Developers Summit 2013 Action !
61. Developers
Summit
背景
• ここに、HBaseを使うことは出来ないか
– スケールする
– 高可用性
– 高パフォーマンス
– Auto
Sharding
• HBaseを1つ作って全てのサービスのデータを
入れることで運用を一元化できたら良さそう
Developers Summit 2013 Action !
62. Developers
Summit
背景
• とはいえ、HBaseは結構難しい
• いかに簡単にするか
• RDBに慣れているエンジニア
Developers Summit 2013 Action !
63. Developers
Summit
Json
Persister
• 社内ライブラリ
• JavaオブジェクトをJsonデータとして永続化するフ
レームワーク
• Javaオブジェクトを直接save、loadするシンプルな
API
• データストア層は切り替えられるようになってい
る
– もともとあったのはMySQL版
Developers Summit 2013 Action !
64. Developers
Summit
Java
API
• シリアライズするクラス
@Persistable
public
class
UserData
{
主キーの設定
@PrimaryKey
private
String
userName;
@Indexed
インデックスの
private
Integer
age;
設定
private
Date
date;
...省略
}
Developers Summit 2013 Action !
65. Developers
Summit
Java
API
• 保存(save)
UserData
userData
=
new
UserData();
userData.setUserName("yuhsaku");
userData.setAge(32);
userData.setDate(new
Date());
jsonPersister.save(userData);
Developers Summit 2013 Action !
66. Developers
Summit
Java
API
• 主キーで取得(load)
UserData
userData
=
new
UserData();
userData.setUserName("yuhsaku");
UserData
result
=
jsonPersister.load(userData);
Developers Summit 2013 Action !
67. Developers
Summit
Java
API
• 取得(list)
UserData
query
=
new
UserData();
query.setAge(32);
インデックスで検索
Criteria<UserData>
criteria
=
Criteria.createCriteria(UserData.class).andEquals(query);
List<UserData>
resultList
=
jsonPersister.list(criteria);
Developers Summit 2013 Action !
68. Developers
Summit
Json
Persister
• シンプル
• このインターフェースにのせれば簡単に
HBaseを扱えそう
HBase実装を開発
Developers Summit 2013 Action !
69. Developers
Summit
スキーマ設計(主キー)
• RowKey:
– 主キー名
+
主キーの値
• ColumnFamily:
– “h”
• Column:
– “”
(空のバイト配列)
• Value:
– Json
Developers Summit 2013 Action !
70. Developers
Summit
スキーマ設計(インデックス)
• RowKey:
– インデックス名
+
インデックス値
+
主キーの値
• ColumnFamily:
– “h”
• Column:
– “”
(空のバイト配列)
• Value:
– Json
Developers Summit 2013 Action !
71. Developers
Summit
例
• 保存(save)
UserData
userData
=
new
UserData();
userData.setUserName(”yusaku");
userData.setAge(32);
userData.setDate(new
Date());
jsonPersister.save(userData);
Developers Summit 2013 Action !
73. Developers
Summit
例
インデックスの
インデックス名
主キーの値
Json
値
RowKey
Column
value
Key
Age
+
32
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
UserName
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
主キー名
主キーの値
Json
Developers Summit 2013 Action !
74. Developers
Summit
例
• 保存(save)
UserData
userData
=
new
UserData();
userData.setUserName(”taro");
userData.setAge(32);
userData.setDate(new
Date());
jsonPersister.save(userData);
Developers Summit 2013 Action !
75. Developers
Summit
例
RowKey
Column
value
Key
Age
+
32
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
UserName
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
Developers Summit 2013 Action !
76. Developers
Summit
例
RowKey
Column
value
Key
Age
+
32
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
Age
+
32
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
UserName
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
UserName
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
Developers Summit 2013 Action !
77. Developers
Summit
例
• 主キーで取得(load)
UserData
userData
=
new
UserData();
userData.setUserName("yuhsaku");
UserData
result
=
jsonPersister.load(userData);
Developers Summit 2013 Action !
78. Developers
Summit
例
• RowKeyがUserName
+
”yusaku”
RowKey
Column
value
Key
Age
+
32
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
Age
+
32
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
UserName
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
UserName
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
Developers Summit 2013 Action !
79. Developers
Summit
例
• RowKeyがUserName
+
”yusaku”
RowKey
Column
value
Key
Age
+
32
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
Age
+
32
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
UserName
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
UserName
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
Developers Summit 2013 Action !
80. Developers
Summit
例
• 取得(list)
UserData
query
=
new
UserData();
query.setAge(32);
Criteria<UserData>
criteria
=
Criteria.createCriteria(UserData.class).andEquals(query);
List<UserData>
resultList
=
jsonPersister.list(criteria);
Developers Summit 2013 Action !
81. Developers
Summit
例
• RowKeyがAge
+
32
でプレフィックススキャン
RowKey
Column
value
Key
Age
+
32
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
Age
+
32
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
UserName
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
UserName
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
Developers Summit 2013 Action !
82. Developers
Summit
例
• RowKeyがAge
+
32
でプレフィックススキャン
RowKey
Column
value
Key
Age
+
32
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
Age
+
32
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
UserName
+
“taro”
h:
{UserName
:
“taro”,
age
:
32,
date
:
234567}
UserName
+
“yusaku”
h:
{UserName
:
“yusaku”,
age
:
32,
date
:
123445}
Developers Summit 2013 Action !
83. Developers
Summit
まとめ
• 社内ライブラリ「Json
Persister」のHBase版を
実装
– スキーマ設計
• 今後
– オープンソースで公開したい
Developers Summit 2013 Action !
85. Developers
Summit
HBaseを触ってみよう
M Y
R E C O M M E N D
N E X T
A C T I O N !
• 書籍「HBase」
– h;p://www.amazon.co.jp/dp/4873115663
Developers Summit 2013 Action !
86. Developers
Summit
HBaseを触ってみよう
M Y
R E C O M M E N D
N E X T
A C T I O N !
• CodeZineの連載「初めてのHBase」
– h;p://codezine.jp/argcle/corner/473
Developers Summit 2013 Action !