[223] h base consistent secondary indexing

86
HBase Consistent secondary Indexing 이름: Jeongmin Kim 소속: Naver

Transcript of [223] h base consistent secondary indexing

Page 1: [223] h base consistent secondary indexing

HBaseConsistent secondary Indexing

이름: Jeongmin Kim소속: Naver

Page 2: [223] h base consistent secondary indexing

Contents1. HBase, 보조인덱스 & the index consistency2. Consistent secondary indexing3. HBase환경에서 보조인덱스 시스템 구현하기: HIM4. Nosql과 보조인덱스 시스템

Page 3: [223] h base consistent secondary indexing

1.HBase, 보조인덱스& the index Consistency

3

Page 4: [223] h base consistent secondary indexing

rowkeybio: fam:

career:����������� ������������������  

name birth sex hometown spouse occupation debutYear

Brad����������� ������������������  pitt Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963

M oklahoma Angelina����������� ������������������  Jolie

Actor 1987

Leonardo����������� ������������������  Dicaprio

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989

Tom����������� ������������������  Cruise Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY Katie����������� ������������������  Holmes Actor 1981

Table����������� ������������������  :����������� ������������������  movieStar

HBase����������� ������������������  table

4

Page 5: [223] h base consistent secondary indexing

rowkeybio: fam:

career:����������� ������������������  

name birth sex hometown spouse occupation debutYear

Brad����������� ������������������  pitt Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963

M oklahoma Angelina����������� ������������������  Jolie

Actor 1987

Leonardo����������� ������������������  Dicaprio

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989

Tom����������� ������������������  Cruise Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY Katie����������� ������������������  Holmes Actor 1981

rowkey����������� ������������������  기준으로����������� ������������������  사전순으로����������� ������������������  정렬����������� ������������������  

Table����������� ������������������  :����������� ������������������  movieStar

HBase����������� ������������������  table

5

Page 6: [223] h base consistent secondary indexing

rowkeybio: fam:

career:����������� ������������������  

name birth sex hometown spouse occupation debutYear

Brad����������� ������������������  pitt Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963

M oklahoma Angelina����������� ������������������  Jolie

Actor 1987

Leonardo����������� ������������������  Dicaprio

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989

Tom����������� ������������������  Cruise Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY Katie����������� ������������������  Holmes Actor 1981

값을����������� ������������������  기준으로����������� ������������������  데이터를����������� ������������������  찾는다면?����������� ������������������  ����������� ������������������   Full����������� ������������������  scan이����������� ������������������  필요하다.����������� ������������������  

(hbase에서는����������� ������������������  보조인덱스가����������� ������������������  없기����������� ������������������  때문)

Table����������� ������������������  :����������� ������������������  movieStar

HBase����������� ������������������  table

rowkey����������� ������������������  기준으로����������� ������������������  사전순으로����������� ������������������  정렬����������� ������������������  

6

Page 7: [223] h base consistent secondary indexing

rowkeybio: fam:

career:����������� ������������������  

name birth sex hometown spouse occupation debutYear

Brad����������� ������������������  pitt Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963

M oklahoma Angelina����������� ������������������  Jolie

Actor 1987

Leonardo����������� ������������������  Dicaprio

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989

Tom����������� ������������������  Cruise Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY Katie����������� ������������������  Holmes Actor 1981

Table����������� ������������������  :����������� ������������������  movieStar

HBase����������� ������������������  table

값을����������� ������������������  기준으로����������� ������������������  데이터를����������� ������������������  찾는다면?����������� ������������������  ����������� ������������������   Full����������� ������������������  scan이����������� ������������������  필요하다.����������� ������������������  

(hbase에서는����������� ������������������  보조인덱스가����������� ������������������  없기����������� ������������������  때문)

rowkey����������� ������������������  기준으로����������� ������������������  사전순으로����������� ������������������  정렬����������� ������������������  

secondary indexes require additional cluster space and processing. This is precisely

what happens in an RDBMS because the act of creating an alternate index requires both

space and processing cycles to update. RBDMS products are more advanced in this

regard to handle alternative index management out of the box. However, HBase scales

better at larger data volumes, so this is a feature trade-off.

source : http://hbase.apache.org/book/secondary.indexes.html

7

Page 8: [223] h base consistent secondary indexing

Request]����������� ������������������  ����������� ������������������  spouse를����������� ������������������  기준으로����������� ������������������  인덱스����������� ������������������  생성

rowkeybio:����������� ������������������  birth

bio:����������� ������������������  sex

bio:����������� ������������������  hometown

fam:����������� ������������������  spouse

career:����������� ������������������  occupation

career:����������� ������������������  debutYear

Brad����������� ������������������  pitt

dec.����������� ������������������  18,����������� ������������������  1963

Moklahoma

Angelina����������� ������������������  Jolie

Actor 1987

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974

M LA,����������� ������������������  CA Actor 1989

Tom����������� ������������������  Cruise

July����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  NY

Katie����������� ������������������  Holmes

Actor 1981

movieStar movieStar.index.spouse

indexing( {} : seperator )

rowkey

Angelina����������� ������������������  Jolie{}Brad����������� ������������������  pitt

Katie����������� ������������������  Holmes{}Tom����������� ������������������  Cruise

{}Leonardo����������� ������������������  Dicaprio

1.����������� ������������������  indexTable����������� ������������������  생성

2.����������� ������������������  [값+값의rowkey]의����������� ������������������  ����������� ������������������  새로운����������� ������������������  rowkey생성

3.����������� ������������������  값을����������� ������������������  기준으로����������� ������������������  매핑����������� ������������������  정보가����������� ������������������  정렬된다.

직접����������� ������������������  Index����������� ������������������  생성하기����������� ������������������  [1/2]

value{}rowkey

8

Page 9: [223] h base consistent secondary indexing

rowkey

Angelina����������� ������������������  Jolie{}Brad����������� ������������������  pitt

Katie����������� ������������������  Holmes{}Tom����������� ������������������  Cruise

{}Leonardo����������� ������������������  Dicaprio

rowkeybio:����������� ������������������  birth

bio:����������� ������������������  sex

bio:����������� ������������������  hometown

fam:����������� ������������������  spouse

career:����������� ������������������  occupation

career:����������� ������������������  debutYear

Brad����������� ������������������  pittdec.����������� ������������������  18,����������� ������������������  1963

M oklahomaAngelina����������� ������������������  Jolie

Actor 1987

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974

M LA,����������� ������������������  CA Actor 1989

Tom����������� ������������������  Cruise

July����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  

NYKatie����������� ������������������  

HolmesActor 1981

movieStarmovieStar.index.spouse

( {} : seperator )

Request]����������� ������������������  ����������� ������������������  미혼인����������� ������������������  배우����������� ������������������  정보

직접����������� ������������������  Index����������� ������������������  생성하기����������� ������������������  [2/2]

1.����������� ������������������  원하는����������� ������������������  값으로����������� ������������������  ����������� ������������������  index를����������� ������������������  range����������� ������������������  Scan

2.����������� ������������������  index에서����������� ������������������  추출된����������� ������������������  rowkey로����������� ������������������  데이터����������� ������������������  획득

9

Page 10: [223] h base consistent secondary indexing

• client는����������� ������������������  dataTable과����������� ������������������  indexTable에서����������� ������������������  동일한����������� ������������������  데이터를����������� ������������������  보아야한다.

Index����������� ������������������  Consistency

User1

DataTable IndexTable

뭔가����������� ������������������  이상한데?

dataA_v1dataA_v2

dataA_v1

dataA_v2

10

Page 11: [223] h base consistent secondary indexing

rowkeybio:����������� ������������������  birth

bio:����������� ������������������  sex

bio:����������� ������������������  hometown

fam:����������� ������������������  spouse

career:����������� ������������������  occupation

career:����������� ������������������  debutYear

career:����������� ������������������  earning

Brad����������� ������������������  pittdec.����������� ������������������  18,����������� ������������������  1963

Moklahoma

Angelina����������� ������������������  Jolie

Actor 1987 25M

Christian����������� ������������������  Bale

Jan����������� ������������������  30,����������� ������������������  1974

M UKSibi����������� ������������������  Blazic

Actor 1982 20M

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974

M LA,����������� ������������������  CA Actor 1989 39M

Tom����������� ������������������  Cruise

July����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  NY

Katie����������� ������������������  Holme

s

Actor 1981 35M

rowkey

Angelina����������� ������������������  Jolie{}Brad����������� ������������������  pitt

Katie����������� ������������������  Holmes{}Tom����������� ������������������  Cruise

{}Leonardo����������� ������������������  Dicaprio

movieStar movieStar.index.spouse

( {} : seperator )

새로운 데이터 유입

Indexing

index 정보 실종

!

FAIL!

1]����������� ������������������  Put하는����������� ������������������  도중의����������� ������������������  Indexing����������� ������������������  지연/실패

Index����������� ������������������  consistency가����������� ������������������  깨어지는����������� ������������������  3가지����������� ������������������  경우

11

Page 12: [223] h base consistent secondary indexing

rowkey

Angelina����������� ������������������  Jolie{}Brad����������� ������������������  pitt

Katie����������� ������������������  Holmes{}Tom����������� ������������������  CruiseSibi����������� ������������������  Blazic{}

Christian����������� ������������������  Bale{}Leonardo����������� ������������������  Dicaprio

{}Tom����������� ������������������  Cruise

( {} : seperator )

데이터 수정 Indexing

out-date된 데이터 존재

2]����������� ������������������  지워지지����������� ������������������  않은����������� ������������������  예전����������� ������������������  Index����������� ������������������  정보

Index����������� ������������������  consistency가����������� ������������������  깨어지는����������� ������������������  3가지����������� ������������������  경우

rowkeybio:����������� ������������������  birth

bio:����������� ������������������  sex

bio:����������� ������������������  hometown

fam:����������� ������������������  spouse

career:����������� ������������������  occupation

career:����������� ������������������  debutYear

career:����������� ������������������  earning

Brad����������� ������������������  pittdec.����������� ������������������  18,����������� ������������������  1963

Moklahoma

Angelina����������� ������������������  Jolie

Actor 1987 25M

Christian����������� ������������������  Bale

Jan����������� ������������������  30,����������� ������������������  1974

M UKSibi����������� ������������������  Blazic

Actor 1982 20M

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974

M LA,����������� ������������������  CA Actor 1989 39M

Tom����������� ������������������  Cruise

July����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  NY

Actor 1981 35M

movieStar movieStar.index.spouse

12

Page 13: [223] h base consistent secondary indexing

rowkeybio:����������� ������������������  birth

bio:����������� ������������������  sex

bio:����������� ������������������  hometown

fam:����������� ������������������  spouse

career:����������� ������������������  occupation

career:����������� ������������������  debutYear

career:earning

Brad����������� ������������������  pittdec.����������� ������������������  18,����������� ������������������  1963

Moklahoma

Angelina����������� ������������������  Jolie

Actor 1987 25M

Christian����������� ������������������  Bale

Jan����������� ������������������  30,����������� ������������������  1974

M UKSibi����������� ������������������  Blazic

Actor 1982 20M

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974

M LA,����������� ������������������  CA Actor 1989 39M

Tom����������� ������������������  Cruise

July����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  NY

Actor 1981 35M

rowkey

20M{}Christian����������� ������������������  Bale

25M{}Brad����������� ������������������  Pitt

39M{}Leonardo����������� ������������������  Dicaprio

35M{}Tom����������� ������������������  Cruise

movieStarmovieStar.index.earning

( {} : seperator )

$30M����������� ������������������  이하의����������� ������������������  연소득����������� ������������������  ����������� ������������������  배우����������� ������������������  리스트는?

3]����������� ������������������  IndexTable을����������� ������������������  읽는����������� ������������������  도중����������� ������������������  발생한����������� ������������������  데이터����������� ������������������  갱신

1. index Scan

Index����������� ������������������  consistency가����������� ������������������  깨어지는����������� ������������������  3가지����������� ������������������  경우

User1

13

Page 14: [223] h base consistent secondary indexing

rowkeybio:����������� ������������������  birth

bio:����������� ������������������  sex

bio:����������� ������������������  hometown

fam:����������� ������������������  spouse

career:����������� ������������������  occupation

career:����������� ������������������  debutYear

career:earning

Brad����������� ������������������  pittdec.����������� ������������������  18,����������� ������������������  1963

Moklahoma

Angelina����������� ������������������  Jolie

Actor 1987 25M

Christian����������� ������������������  Bale

Jan����������� ������������������  30,����������� ������������������  1974

M UKSibi����������� ������������������  Blazic

Actor 1982 45M

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974

M LA,����������� ������������������  CA Actor 1989 39M

Tom����������� ������������������  Cruise

July����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  NY

Actor 1981 35M

rowkey

25M{}Brad����������� ������������������  Pitt

35M{}Tom����������� ������������������  Cruise

39M{}Leonardo����������� ������������������  Dicaprio

45M{}Christian����������� ������������������  Bale

User2

다크나이트가����������� ������������������  ����������� ������������������  성공해서����������� ������������������  ����������� ������������������  소득이����������� ������������������  올랐지!

Index����������� ������������������  consistency가����������� ������������������  깨어지는����������� ������������������  3가지����������� ������������������  경우

3]����������� ������������������  IndexTable을����������� ������������������  읽는����������� ������������������  도중����������� ������������������  발생한����������� ������������������  데이터����������� ������������������  갱신

movieStarmovieStar.index.earning

2. Update data( {} : seperator )

14

Page 15: [223] h base consistent secondary indexing

User1

3. data Scan

Index����������� ������������������  consistency가����������� ������������������  깨어지는����������� ������������������  3가지����������� ������������������  경우

3]����������� ������������������  IndexTable을����������� ������������������  읽는����������� ������������������  도중����������� ������������������  발생한����������� ������������������  데이터����������� ������������������  갱신

rowkey

25M{}Brad����������� ������������������  Pitt

35M{}Tom����������� ������������������  Cruise

39M{}Leonardo����������� ������������������  Dicaprio

45M{}Christian����������� ������������������  Bale

( {} : seperator )

rowkeybio:����������� ������������������  birth

bio:����������� ������������������  sex

bio:����������� ������������������  hometown

fam:����������� ������������������  spouse

career:����������� ������������������  occupation

career:����������� ������������������  debutYear

career:earning

Brad����������� ������������������  pittdec.����������� ������������������  18,����������� ������������������  1963

Moklahoma

Angelina����������� ������������������  Jolie

Actor 1987 25M

Christian����������� ������������������  Bale

Jan����������� ������������������  30,����������� ������������������  1974

M UKSibi����������� ������������������  Blazic

Actor 1982 45M

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974

M LA,����������� ������������������  CA Actor 1989 39M

Tom����������� ������������������  Cruise

July����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  NY

Actor 1981 35M

movieStar.index.earning movieStar

15

Page 16: [223] h base consistent secondary indexing

rowkeybio:����������� ������������������  birth

bio:����������� ������������������  sex

bio:����������� ������������������  hometown

fam:����������� ������������������  spouse

career:����������� ������������������  occupation

career:����������� ������������������  debutYear

career:earning

Brad����������� ������������������  pittdec.����������� ������������������  18,����������� ������������������  1963

Moklahoma

Angelina����������� ������������������  Jolie

Actor 1987 25M

Christian����������� ������������������  Bale

Jan����������� ������������������  30,����������� ������������������  1974

M UKSibi����������� ������������������  Blazic

Actor 1982 45M

요청과 맞지

않은 결과

Result����������� ������������������  :

$30M����������� ������������������  이하의����������� ������������������  연소득����������� ������������������  배우����������� ������������������  ����������� ������������������  리스트는?

Index����������� ������������������  consistency가����������� ������������������  깨어지는����������� ������������������  3가지����������� ������������������  경우

3]����������� ������������������  IndexTable을����������� ������������������  읽는����������� ������������������  도중����������� ������������������  발생한����������� ������������������  데이터����������� ������������������  갱신

User1

16

Page 17: [223] h base consistent secondary indexing

HBase에서����������� ������������������  동작하는����������� ������������������  보조인덱스����������� ������������������  시스템����������� ������������������  • 검색����������� ������������������  노출제어시스템(H**)에서����������� ������������������  사용할����������� ������������������  목적����������� ������������������  

• 인덱스에서����������� ������������������  획득하는����������� ������������������  데이터의����������� ������������������  정확성과����������� ������������������  일관성이����������� ������������������  필수����������� ������������������  

• 대규모����������� ������������������  데이터(수백억����������� ������������������  단위의����������� ������������������  row)����������� ������������������  

• 높은����������� ������������������  throughput����������� ������������������  

• 실시간����������� ������������������  처리����������� ������������������  

• 선형����������� ������������������  확장성����������� ������������������  

• DataTable과����������� ������������������  Index에서����������� ������������������  HBase가����������� ������������������  제공하는����������� ������������������  기능����������� ������������������  사용����������� ������������������  

• CURD,����������� ������������������  exist(Get[]),����������� ������������������  batch(Mutation[]),����������� ������������������  setFilter(),increment(),����������� ������������������  checkAndPut(),����������� ������������������  

CheckAndDelete(),����������� ������������������  …⋯

우리가����������� ������������������  찾고����������� ������������������  있던����������� ������������������  것은...

17

Page 18: [223] h base consistent secondary indexing

직접����������� ������������������  구현하자����������� ������������������  •시중에����������� ������������������  나와있는����������� ������������������  오픈����������� ������������������  소스����������� ������������������  들이����������� ������������������  요구사항에����������� ������������������  맞지����������� ������������������  않다.����������� ������������������  

•이름짓기:����������� ������������������  HIM����������� ������������������  

•작명����������� ������������������  센스없이����������� ������������������  편히����������� ������������������  불렀던����������� ������������������  이름이...����������� ������������������  

• H**����������� ������������������  Index����������� ������������������  Manager����������� ������������������  

• 검색데이터노출제어시스템(H**)의����������� ������������������  index����������� ������������������  관리����������� ������������������  Util로����������� ������������������  시작����������� ������������������  

•후에����������� ������������������  범용적인����������� ������������������  적용을����������� ������������������  생각하여����������� ������������������  이름����������� ������������������  변경����������� ������������������  :����������� ������������������  HBase����������� ������������������  Index����������� ������������������  Manager

우리가����������� ������������������  찾고����������� ������������������  있던����������� ������������������  것은...

18

Page 19: [223] h base consistent secondary indexing

1.����������� ������������������  데이터와����������� ������������������  인덱스의����������� ������������������  갱신이����������� ������������������  atomic하지����������� ������������������  않다����������� ������������������  • Client가����������� ������������������  요청하는����������� ������������������  시점에����������� ������������������  따라����������� ������������������  index의����������� ������������������  consistency가����������� ������������������  깨여질����������� ������������������  수����������� ������������������  있다.����������� ������������������  

• Index와����������� ������������������  Data가����������� ������������������  동시점에����������� ������������������  유효해����������� ������������������  져야����������� ������������������  한다.����������� ������������������  

• Indexing과정에는����������� ������������������  과거의����������� ������������������  index도����������� ������������������  정리����������� ������������������  되어야����������� ������������������  한다.(Clean-up과정)����������� ������������������  

• Indexing에����������� ������������������  실패하면����������� ������������������  Data도����������� ������������������  업데이트����������� ������������������  되지����������� ������������������  않아야����������� ������������������  한다.

DataTable IndexTable데이터가����������� ������������������  유효한����������� ������������������  시점

index가

����������� ������������������  유효한����������� ������������������  시점

1. data put 2. indexing

Index����������� ������������������  Consistency가����������� ������������������  깨어진����������� ������������������  이유

19

Page 20: [223] h base consistent secondary indexing

2.����������� ������������������  데이터와����������� ������������������  인덱스����������� ������������������  정보의����������� ������������������  유효성을����������� ������������������  알수����������� ������������������  없다.����������� ������������������  • 획득한����������� ������������������  Index����������� ������������������  정보와����������� ������������������  data를����������� ������������������  조회하는����������� ������������������  시점은����������� ������������������  다르다.����������� ������������������  

• index정보를����������� ������������������  확인해야����������� ������������������  data의����������� ������������������  rowkey를����������� ������������������  알����������� ������������������  수����������� ������������������  있으므로����������� ������������������  

• 서로����������� ������������������  다른����������� ������������������  시점에����������� ������������������  획득한����������� ������������������  두����������� ������������������  정보의����������� ������������������  유효성을����������� ������������������  알����������� ������������������  수����������� ������������������  없다.����������� ������������������  

• 유효성을����������� ������������������  검증할����������� ������������������  방법이����������� ������������������  필요하다.

Index����������� ������������������  Consistency가����������� ������������������  깨어진����������� ������������������  이유

DataTableIndexTableindex로 데이터 요청

index가 유효한 시점

지금도 인덱

스가 유효할까

?

데이터 획득index정보 획득

20

Page 21: [223] h base consistent secondary indexing

2.ConsistentSecondary indexing

Page 22: [223] h base consistent secondary indexing

HBase의����������� ������������������  오픈소스����������� ������������������  Transaction����������� ������������������  시스템들을����������� ������������������  이용하여����������� ������������������  구현하면?����������� ������������������  • haeinsa,����������� ������������������  tephra,����������� ������������������  각종����������� ������������������  row����������� ������������������  lock����������� ������������������  시스템들����������� ������������������  …⋯����������� ������������������  

• 데이터의����������� ������������������  정확성과����������� ������������������  일관성����������� ������������������  보장����������� ������������������  가능����������� ������������������  

• 하지만����������� ������������������  각각����������� ������������������  우리����������� ������������������  시스템과����������� ������������������  맞지����������� ������������������  않는����������� ������������������  부분들이����������� ������������������  있다.����������� ������������������  

• 특정����������� ������������������  row에����������� ������������������  집중된����������� ������������������  update에����������� ������������������  취약����������� ������������������  

• setFilter(),incrementColumnByValue(),����������� ������������������  checkAndPut(),����������� ������������������  CheckAndDelete(),����������� ������������������  

exist(Get[]),����������� ������������������  batch()����������� ������������������  등의����������� ������������������  사용제약����������� ������������������  

• 대규모����������� ������������������  row에����������� ������������������  대한����������� ������������������  scan����������� ������������������  및����������� ������������������  transaction����������� ������������������  

=>����������� ������������������  좀����������� ������������������  더����������� ������������������  보조인덱스에����������� ������������������  특화된����������� ������������������  효율적인����������� ������������������  방법이����������� ������������������  없을까?

어떻게����������� ������������������  만들까?

22

Page 23: [223] h base consistent secondary indexing

rowkeytimestamp bio: fam: career:

name birth sex hometown spouse occupation debutYear

Tom Cruise

3 Tom cruise July 3, 1962 M Syracuse, NY Nicole Kidman Actor 19814 null Actor, Producer5 Katie Holmes6 null

hbase(main):002:0> get ‘movieStar’, ‘Tom Cruise’

Tom Cruise Tom cruise July 3, 1962 M Syracuse, NY null Actor, Producer 1981Result:

hbase(main):002:0> get ‘movieStar’, ‘Tom Cruise’, {TIMERANGE => [0, 6]}

Tom Cruise Tom cruise July 3, 1962 M Syracuse, NY Katie Holmes Actor, Producer 1981Result:

hbase(main):002:0> get ‘movieStar’, ‘Tom Cruise’, {TIMERANGE => [5, 6]}

Tom Cruise Katie HolmesResult:

MVCC(Multi-version����������� ������������������  concurrency����������� ������������������  control)

•Hbase의����������� ������������������  데이터는����������� ������������������  여러����������� ������������������  버전의����������� ������������������  데이터를����������� ������������������  가진다.����������� ������������������  

•Client는����������� ������������������  timestamp값을����������� ������������������  설정하여����������� ������������������  특정����������� ������������������  version의����������� ������������������  데이터를����������� ������������������  획득할����������� ������������������  수����������� ������������������  있다.

23

Page 24: [223] h base consistent secondary indexing

Versioned����������� ������������������  Index

rowkey timestamp bio:birth

bio:sex

bio:hometown

fam:spouse

career:occupation

career:debutYear

Brad pitt 3 dec. 18, 1963 M oklahoma Angelina

Jolie Actor 1987

Leonardo Dicaprio 12 Nov 11,

1974 M LA, CA Actor 1989

Tom Cruise 5 July 3,

1962 M Syracuse, NY

Katie Holmes Actor 1981

movieStar movieStar.index.spouse

rowkey timestamp

Angelina Jolie{}Brad pitt 3

Katie Holmes{}Tom Cruise 5

{}Leonardo Dicaprio 12

3가지의����������� ������������������  timestamp의����������� ������������������  비교를����������� ������������������  통한����������� ������������������  index����������� ������������������  consistency����������� ������������������  구현����������� ������������������  1.����������� ������������������  data’s����������� ������������������  timestamp����������� ������������������  :����������� ������������������  dataTable의����������� ������������������  data가����������� ������������������  가지는����������� ������������������  본연의����������� ������������������  timestamp����������� ������������������  

2.����������� ������������������  index’s����������� ������������������  timestamp����������� ������������������  :����������� ������������������  indexing한����������� ������������������  대상����������� ������������������  data가����������� ������������������  가졌던����������� ������������������  timestamp

24

Page 25: [223] h base consistent secondary indexing

Versioned����������� ������������������  Index

3.����������� ������������������  him:timestamp����������� ������������������  :����������� ������������������  현재����������� ������������������  유효한����������� ������������������  데이터와����������� ������������������  인덱스의����������� ������������������  timestamp값����������� ������������������  

• 데이터����������� ������������������  Put����������� ������������������  및����������� ������������������  indexing과정이����������� ������������������  모두����������� ������������������  성공했을����������� ������������������  경우����������� ������������������  업데이트된다.����������� ������������������  

• 이����������� ������������������  값이����������� ������������������  업데이트����������� ������������������  되어야����������� ������������������  해당����������� ������������������  version의����������� ������������������  index와����������� ������������������  data가����������� ������������������  유효화된다.����������� ������������������  

• 해당����������� ������������������  버전의����������� ������������������  데이터와����������� ������������������  인덱스가����������� ������������������  유효함을����������� ������������������  인증

rowkey timestamp bio:birth

bio:sex

bio:hometown

fam:spouse

career:occupation

career:debutYear

him:timestamp

Brad pitt 3 dec. 18, 1963 M oklahoma Angelina

Jolie Actor 1987 3

Leonardo Dicaprio 12 Nov 11,

1974 M LA, CA Actor 1989 12

Tom Cruise 5 July 3,

1962 M Syracuse, NY

Katie Holmes Actor 1981 5

movieStar movieStar.index.spouse

rowkey timestamp

Angelina Jolie{}Brad pitt 3

Katie Holmes{}Tom Cruise 5

{}Leonardo Dicaprio 12

25

Page 26: [223] h base consistent secondary indexing

1.����������� ������������������  데이터와����������� ������������������  인덱스의����������� ������������������  갱신을����������� ������������������  atomic하게(Put/Delete)����������� ������������������  • him:timestamp����������� ������������������  값이����������� ������������������  버전인����������� ������������������  데이터와����������� ������������������  인덱스가����������� ������������������  유효하다.����������� ������������������  

• client가����������� ������������������  get/scan시에����������� ������������������  유효한����������� ������������������  버전의����������� ������������������  데이터����������� ������������������  만을����������� ������������������  전달한다.����������� ������������������  

• Index와����������� ������������������  Data가����������� ������������������  동시점에����������� ������������������  유효해����������� ������������������  진다.����������� ������������������  

• 일부가����������� ������������������  유효하지����������� ������������������  않다면����������� ������������������  전체가����������� ������������������  유효하지����������� ������������������  않다.����������� ������������������  

• Indexing이����������� ������������������  실패하면����������� ������������������  him:timestamp가����������� ������������������  업데이트����������� ������������������  되지����������� ������������������  않는다.����������� ������������������  

• Put을����������� ������������������  요청한����������� ������������������  Client는����������� ������������������  IOException을����������� ������������������  전달����������� ������������������  받는다.

DataTable IndexTable1. data put 2. indexing

Versioned����������� ������������������  Index와����������� ������������������  index����������� ������������������  consistency

3. him:timestamp 입력index&data가 동시에 유효화

26

Page 27: [223] h base consistent secondary indexing

2.����������� ������������������  데이터와����������� ������������������  인덱스����������� ������������������  정보의����������� ������������������  유효성����������� ������������������  검증(Get/Scan)����������� ������������������  • Client는����������� ������������������  접근하는����������� ������������������  경로에����������� ������������������  상관없이����������� ������������������  유효한����������� ������������������  버전의����������� ������������������  데이터를����������� ������������������  획득한다.����������� ������������������  

• 획득한����������� ������������������  Index����������� ������������������  정보가����������� ������������������  data를����������� ������������������  조회하는����������� ������������������  시점에����������� ������������������  유효한����������� ������������������  것을����������� ������������������  확인한다.����������� ������������������  

• him:timestamp와����������� ������������������  index’s����������� ������������������  timestamp를����������� ������������������  비교하면����������� ������������������  index의����������� ������������������  유효성을����������� ������������������  알����������� ������������������  수����������� ������������������  있다.����������� ������������������  

• Client에게는����������� ������������������  항상����������� ������������������  유효한����������� ������������������  버전의����������� ������������������  데이터����������� ������������������  제공

DataTableIndexTable1. get data from index

index가 유효한 시점

지금도 인덱

스가 유효할까

? 확인!

2. timestamp 비교

4-B. Client에게 유효한 버전의 데이터 전달4-A. 유효하지 않은 값은 버린다.

3. 인덱스는 유효한 상태인가?

Versioned����������� ������������������  Index와����������� ������������������  index����������� ������������������  consistency

27

Page 28: [223] h base consistent secondary indexing

Put

동작방식����������� ������������������  1. dataTable에����������� ������������������  데이터를����������� ������������������  Put한다.����������� ������������������  

2. indexTable들에����������� ������������������  인덱싱����������� ������������������  한다.����������� ������������������  

3. him:timestamp����������� ������������������  값을����������� ������������������  업데이트����������� ������������������  한다.����������� ������������������  

• 이����������� ������������������  과정에서����������� ������������������  실패����������� ������������������  발생시����������� ������������������  

• Put한����������� ������������������  Client에게����������� ������������������  IOException으로����������� ������������������  알림����������� ������������������  

• him:timestamp값은����������� ������������������  업데이트����������� ������������������  되지����������� ������������������  않는다.

28

Page 29: [223] h base consistent secondary indexing

rowkeytimestamp

bio: fam: career:����������� ������������������   him

name birth sex hometown

spouse occupation

debutYear

timestamp

Brad����������� ������������������  pitt 3 Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963

M oklahoma Angelina����������� ������������������  Jolie

Actor 1987 3

Leonardo����������� ������������������  Dicaprio 12

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989 12

Tom����������� ������������������  Cruise

5 Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY

Katie����������� ������������������  Holmes Actor 19815

16 Tom����������� ������������������  cruise

July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY

Actor 1981

HBase Table : movieStar1.dataTable에����������� ������������������  데이터����������� ������������������  put

movieStar.index.spouserowkey

timestamp him

rowkeyAngelina����������� ������������������  Jolie{}Brad����������� ������������������  pitt 3 Brad����������� ������������������  pitt

Katie����������� ������������������  Holmes{}Tom����������� ������������������  Cruise 5 Tom����������� ������������������  Cruise

{}Leonardo����������� ������������������  Dicaprio 12 Leonardo����������� ������������������  Dicaprio

Put

29

Page 30: [223] h base consistent secondary indexing

Put

2.indexTable들에����������� ������������������  indexing����������� ������������������  

HBase Table : movieStar

movieStar.index.spouse

rowkeytimestamp

bio: fam: career:����������� ������������������   him

name birth sex hometown

spouse occupation

debutYear

timestamp

Brad����������� ������������������  pitt 3 Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963

M oklahoma Angelina����������� ������������������  Jolie

Actor 1987 3

Leonardo����������� ������������������  Dicaprio 12

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989 12

Tom����������� ������������������  Cruise

5 Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY

Katie����������� ������������������  Holmes Actor 19815

16 Tom����������� ������������������  cruise

July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY

Actor 1981

rowkeytimestamp him

rowkeyAngelina����������� ������������������  Jolie{}Brad����������� ������������������  pitt 3 Brad����������� ������������������  pitt

Katie����������� ������������������  Holmes{}Tom����������� ������������������  Cruise 5 Tom����������� ������������������  Cruise

{}Leonardo����������� ������������������  Dicaprio 12 Leonardo����������� ������������������  Dicaprio{}Tom����������� ������������������  Cruise 16 Tom����������� ������������������  Cruise

data가����������� ������������������  가진����������� ������������������  timestamp로����������� ������������������  ����������� ������������������  index정보가����������� ������������������  입력

30

Page 31: [223] h base consistent secondary indexing

Put

3.him:timestamp����������� ������������������  업데이트

HBase Table : movieStarrowkey

timestamp

bio: fam: career:����������� ������������������   him

name birth sex hometown

spouse occupation

debutYear

timestamp

Brad����������� ������������������  pitt 3 Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963

M oklahoma Angelina����������� ������������������  Jolie

Actor 1987 3

Leonardo����������� ������������������  Dicaprio 12

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989 12

Tom����������� ������������������  Cruise

5 Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY

Katie����������� ������������������  Holmes Actor 198116

16 Tom����������� ������������������  cruise

July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY

Actor 1981

Indexing이����������� ������������������  모두����������� ������������������  성공적이었을����������� ������������������  때����������� ������������������  him:timestamp가����������� ������������������  업데이트된다.

rowkeytimestamp him

rowkeyAngelina����������� ������������������  Jolie{}Brad����������� ������������������  pitt 3 Brad����������� ������������������  pitt

Katie����������� ������������������  Holmes{}Tom����������� ������������������  Cruise 5 Tom����������� ������������������  Cruise

{}Leonardo����������� ������������������  Dicaprio 12 Leonardo����������� ������������������  Dicaprio{}Tom����������� ������������������  Cruise 16 Tom����������� ������������������  Cruise

movieStar.index.spouse

31

Page 32: [223] h base consistent secondary indexing

dataTable에서����������� ������������������  Scan/Get

동작방식����������� ������������������  1. dataTable에서����������� ������������������  데이터를����������� ������������������  획득한다.����������� ������������������  

2. him:timestamp����������� ������������������  값의����������� ������������������  데이터를����������� ������������������  리턴한다.����������� ������������������  

•대부분의����������� ������������������  경우����������� ������������������  him:timestamp=data’s����������� ������������������  timestamp����������� ������������������  ����������� ������������������  

•그대로����������� ������������������  데이터����������� ������������������  리턴����������� ������������������  

•만약����������� ������������������  data’s����������� ������������������  timestamp����������� ������������������  >����������� ������������������  him:timestamp����������� ������������������  이라면����������� ������������������  

•him:timestamp가����������� ������������������  버전인����������� ������������������  데이터를����������� ������������������  리턴한다.����������� ������������������  

기준����������� ������������������  •him:timestamp����������� ������������������  버전의����������� ������������������  데이터가����������� ������������������  유효한����������� ������������������  값이므로����������� ������������������  이����������� ������������������  버전의����������� ������������������  데이터를����������� ������������������  리턴

32

Page 33: [223] h base consistent secondary indexing

Request:����������� ������������������  rowkey가����������� ������������������  "Tom����������� ������������������  Cuise”인����������� ������������������  data.����������� ������������������  

Result:

rowkeytimestamp

bio: fam: career:����������� ������������������   him

name birth sex hometown

spouse occupation

debutYear

timestamp

Brad����������� ������������������  pitt 3 Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963

M oklahoma Angelina����������� ������������������  Jolie Actor 1987 3

Leonardo����������� ������������������  Dicaprio 12

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989 12

Tom����������� ������������������  Cruise

5 Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 MSyracuse,����������� ������������������  

NYKatie����������� ������������������  Holmes Actor 1981

516

Tom����������� ������������������  cruise

July����������� ������������������  3,����������� ������������������  1962 MSyracuse,����������� ������������������  

NYActor 1981

HBase����������� ������������������  Table����������� ������������������  :����������� ������������������  movieStar

현재����������� ������������������  유효한����������� ������������������  timestamp=5의����������� ������������������  ����������� ������������������  데이터를����������� ������������������  반환한다.

case1.����������� ������������������  data’s����������� ������������������  timestamp����������� ������������������  >����������� ������������������  him:timestamp

Valid

16����������� ������������������  >����������� ������������������  5����������� ������������������  :����������� ������������������  Invalid

dataTable에서����������� ������������������  Scan/Get

Tom����������� ������������������  Cruise 5 Tom����������� ������������������  

cruiseJuly����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  

NYKatie����������� ������������������  Holmes

Actor 1981

33

Page 34: [223] h base consistent secondary indexing

rowkeytimestamp

bio: fam: career:����������� ������������������   him

name birth sex hometown

spouse occupation

debutYear

timestamp

Brad����������� ������������������  pitt 3 Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963

M oklahoma Angelina����������� ������������������  Jolie Actor 1987 3

Leonardo����������� ������������������  Dicaprio 12

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989 12

Tom����������� ������������������  Cruise

5 Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 MSyracuse,����������� ������������������  

NYKatie����������� ������������������  Holmes Actor 1981

1616

Tom����������� ������������������  cruise

July����������� ������������������  3,����������� ������������������  1962 MSyracuse,����������� ������������������  

NYActor 1981

HBase����������� ������������������  Table����������� ������������������  :����������� ������������������  movieStar

현재����������� ������������������  유효한����������� ������������������  timestamp=16의����������� ������������������  ����������� ������������������  데이터를����������� ������������������  반환한다.

case2.����������� ������������������  data’s����������� ������������������  timestamp����������� ������������������  =����������� ������������������  him:timestamp

Invalid

16����������� ������������������  =����������� ������������������  16����������� ������������������  :����������� ������������������  Valid

dataTable에서����������� ������������������  Scan/Get

Request:����������� ������������������  rowkey가����������� ������������������  "Tom����������� ������������������  Cuise”인����������� ������������������  data.����������� ������������������  

Result:Tom����������� ������������������  Cruise 16 Tom����������� ������������������  

cruiseJuly����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  

NYActor 1981

34

Page 35: [223] h base consistent secondary indexing

indexTable에서����������� ������������������  Scan/Get

동작방식����������� ������������������  1. indexTable에서����������� ������������������  인덱스����������� ������������������  정보를����������� ������������������  가져온다.����������� ������������������  

2. 1.에서����������� ������������������  추출한����������� ������������������  rowkey로����������� ������������������  dataTable에서����������� ������������������  데이터를����������� ������������������  가져온다.����������� ������������������  

3. 2.에서����������� ������������������  him:timestamp값과����������� ������������������  1.에서����������� ������������������  index’s����������� ������������������  timestamp값을����������� ������������������  비교한다.����������� ������������������  

•index’s����������� ������������������  timestamp����������� ������������������  =����������� ������������������  him:timestamp����������� ������������������  :����������� ������������������  인덱스����������� ������������������  유효����������� ������������������  

•index’s����������� ������������������  timestamp����������� ������������������  <����������� ������������������  him:timestamp����������� ������������������  :����������� ������������������  유효하지����������� ������������������  않은����������� ������������������  인덱스����������� ������������������  

•index’s����������� ������������������  timestamp����������� ������������������  >����������� ������������������  him:timestamp����������� ������������������  :����������� ������������������  추가����������� ������������������  확인����������� ������������������  필요����������� ������������������  

-����������� ������������������  해당����������� ������������������  index에����������� ������������������  him:timestamp����������� ������������������  버전이����������� ������������������  존재하면?����������� ������������������  해당����������� ������������������  index가����������� ������������������  유효����������� ������������������  

-����������� ������������������  해당����������� ������������������  index에����������� ������������������  him:timestamp����������� ������������������  버전이����������� ������������������  존재하지����������� ������������������  않으면?����������� ������������������  유효하지����������� ������������������  않은����������� ������������������  인덱스����������� ������������������  

4. 유효한����������� ������������������  인덱스라면����������� ������������������  유효한����������� ������������������  버전의����������� ������������������  데이터를����������� ������������������  Client에����������� ������������������  전달����������� ������������������  

35

Page 36: [223] h base consistent secondary indexing

data����������� ������������������  Result

case1.����������� ������������������  the����������� ������������������  index’s����������� ������������������  timestamp����������� ������������������  =����������� ������������������  him:timestampindex����������� ������������������  Result

rowkeytimestamp him

rowkey

{}Leonardo����������� ������������������  Dicaprio 12 Leonardo����������� ������������������  Dicaprio

{}Brad����������� ������������������  Pitt 1 Brad����������� ������������������  Pitt

{}Tom����������� ������������������  Cruise 16 Tom����������� ������������������  Cruise

Leonardo����������� ������������������  :����������� ������������������  index’s����������� ������������������  timestamp����������� ������������������  12����������� ������������������  =����������� ������������������  12����������� ������������������  him:timestamp

indexTable에서����������� ������������������  Scan/Get

2~3.����������� ������������������  데이터����������� ������������������  조회����������� ������������������  및����������� ������������������  유효성����������� ������������������  판별

Request]����������� ������������������  ����������� ������������������  미혼인����������� ������������������  배우����������� ������������������  목록

rowkeytimestamp bio: fam:

career:����������� ������������������  him

name birth sex hometown spouse occupation debutYear timestamp

Leonardo����������� ������������������  Dicaprio 12

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989 12

36

Page 37: [223] h base consistent secondary indexing

rowkeytimestamp him

rowkey

{}Leonardo����������� ������������������  Dicaprio 12 Leonardo����������� ������������������  Dicaprio

{}Brad����������� ������������������  Pitt 1 Brad����������� ������������������  Pitt

{}Tom����������� ������������������  Cruise 16 Tom����������� ������������������  Cruise

data����������� ������������������  Result

index����������� ������������������  Result

Brad����������� ������������������  pitt����������� ������������������  :����������� ������������������  index’s����������� ������������������  timestamp����������� ������������������  1����������� ������������������  <����������� ������������������  3����������� ������������������  him:timestamp

case2.����������� ������������������  the����������� ������������������  index’s����������� ������������������  timestamp����������� ������������������  <����������� ������������������  him:timestamp

Invalid:����������� ������������������  skip

indexTable에서����������� ������������������  Scan/Get

2~3.����������� ������������������  데이터����������� ������������������  조회����������� ������������������  및����������� ������������������  유효성����������� ������������������  판별

Request]����������� ������������������  ����������� ������������������  미혼인����������� ������������������  배우����������� ������������������  목록

rowkeytimestamp bio: fam:

career:����������� ������������������  him

name birth sex hometown spouse occupation debutYear timestamp

Brad����������� ������������������  Pitt 3 Brad����������� ������������������  pittdec.����������� ������������������  18,����������� ������������������  1963

Moklahom

aAngelina����������� ������������������  Jolie

Actor 1987 3

37

Page 38: [223] h base consistent secondary indexing

rowkeytimestamp him

rowkey

{}Leonardo����������� ������������������  Dicaprio 12 Leonardo����������� ������������������  Dicaprio

{}Brad����������� ������������������  Pitt 1 Brad����������� ������������������  Pitt

{}Tom����������� ������������������  Cruise 16 Tom����������� ������������������  Cruise

data����������� ������������������  Result

index����������� ������������������  Resultcase3.����������� ������������������  the����������� ������������������  index’s����������� ������������������  timestamp����������� ������������������  >����������� ������������������  him:timestamp

indexTable에서����������� ������������������  Scan/Get

2~3.����������� ������������������  데이터����������� ������������������  조회����������� ������������������  및����������� ������������������  유효성����������� ������������������  판별

Request]����������� ������������������  ����������� ������������������  미혼인����������� ������������������  배우����������� ������������������  목록

rowkeytimestamp bio: fam:

career:����������� ������������������  him

name birth sex hometown spouse occupation debutYear timestamp

Tom����������� ������������������  Cruise

5Tom����������� ������������������  cruise

July����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  

NYKatie����������� ������������������  Holmes Actor 1981

516 Tom����������� ������������������  

cruiseJuly����������� ������������������  3,����������� ������������������  1962

M Syracuse,����������� ������������������  NY

Actor 1981

Tom����������� ������������������  :����������� ������������������  index’s����������� ������������������  timestamp����������� ������������������  16����������� ������������������  >����������� ������������������  5����������� ������������������  him:timestamp

Invalid:����������� ������������������  skip

38

Page 39: [223] h base consistent secondary indexing

rowkey timestamp himrowkey

Katie����������� ������������������  Holmes{}Tom����������� ������������������  Cruise 5 Tom����������� ������������������  Cruise

{}Leonardo����������� ������������������  Dicaprio 12 Leonardo����������� ������������������  Dicaprio

{}Brad����������� ������������������  Pitt 1 Brad����������� ������������������  Pitt

{}Tom����������� ������������������  Cruise 16 Tom����������� ������������������  Cruise

data����������� ������������������  Result

index����������� ������������������  Resultcase3.����������� ������������������  the����������� ������������������  index’s����������� ������������������  timestamp����������� ������������������  >����������� ������������������  him:timestamp

indexTable에서����������� ������������������  Scan/Get

2~3.����������� ������������������  데이터����������� ������������������  조회����������� ������������������  및����������� ������������������  유효성����������� ������������������  판별

Request]����������� ������������������  ����������� ������������������  미혼인����������� ������������������  배우����������� ������������������  목록

Invalid:����������� ������������������  skip

Invalid:����������� ������������������  skip{}Tom����������� ������������������  Cruise가����������� ������������������  timestamp����������� ������������������  5에서����������� ������������������  존재하는지?����������� ������������������  ����������� ������������������  

검사결과����������� ������������������  :����������� ������������������  없다.����������� ������������������  Invalid

rowkeytimestamp bio: fam:

career:����������� ������������������  him

name birth sex hometown spouse occupation debutYear timestamp

Tom����������� ������������������  Cruise

5Tom����������� ������������������  cruise

July����������� ������������������  3,����������� ������������������  1962

MSyracuse,����������� ������������������  

NYKatie����������� ������������������  Holmes Actor 1981

516 Tom����������� ������������������  

cruiseJuly����������� ������������������  3,����������� ������������������  1962

M Syracuse,����������� ������������������  NY

Actor 1981 39

Page 40: [223] h base consistent secondary indexing

Result:����������� ������������������  

index����������� ������������������  Result

indexTable에서����������� ������������������  Scan/Get

4.����������� ������������������  최종����������� ������������������  결과

Request]����������� ������������������  ����������� ������������������  미혼인����������� ������������������  배우����������� ������������������  목록

rowkeytimestamp him

rowkey

{}Leonardo����������� ������������������  Dicaprio 12 Leonardo����������� ������������������  Dicaprio

{}Brad����������� ������������������  Pitt 1 Brad����������� ������������������  Pitt

{}Tom����������� ������������������  Cruise 16 Tom����������� ������������������  Cruise

index����������� ������������������  Result

Invalid:����������� ������������������  skip

{}Leonardo����������� ������������������  Dicaprio 12

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989

Invalid:����������� ������������������  skip

40

Page 41: [223] h base consistent secondary indexing

3.HBase환경에서보조인덱스 시스템 구현하기:HIM

Page 42: [223] h base consistent secondary indexing

•분산����������� ������������������  환경에서의����������� ������������������  보조인덱스����������� ������������������  구성시����������� ������������������  대표적인����������� ������������������  구현����������� ������������������  방법����������� ������������������  

•Local����������� ������������������  Indexing����������� ������������������  :����������� ������������������  data와����������� ������������������  index정보가����������� ������������������  같은����������� ������������������  regionServer에����������� ������������������  존재����������� ������������������  

•Global����������� ������������������  Indexing����������� ������������������  :����������� ������������������  data와����������� ������������������  index정보의����������� ������������������  위치는����������� ������������������  상관하지����������� ������������������  않음

Local����������� ������������������  vs����������� ������������������  Global����������� ������������������  indexing

Local����������� ������������������  indexing Global����������� ������������������  indexing

dataRegion1

indexOfdata1

dataRegion2

indexOfdata2

RegionServer1

dataRegion3

indexOfdata3

dataRegion4

indexOfdata4

RegionServer2

dataRegion1

Index2

dataRegion2

Index4

RegionServer1

dataRegion3

Index1

dataRegion4

Index3

RegionServer2

Data와����������� ������������������  index가����������� ������������������  같은����������� ������������������  RegionServer에����������� ������������������  존재

Data와����������� ������������������  Index가����������� ������������������  서로����������� ������������������  다른����������� ������������������  RegionServer에����������� ������������������  존재할����������� ������������������  수����������� ������������������  있다. 42

Page 43: [223] h base consistent secondary indexing

data와����������� ������������������  index가����������� ������������������  같은����������� ������������������  리전����������� ������������������  서버에����������� ������������������  •hbase에서����������� ������������������  table의����������� ������������������  데이터는����������� ������������������  Region����������� ������������������  단위로����������� ������������������  구분����������� ������������������  

•dataRegion마다����������� ������������������  각각의����������� ������������������  index를����������� ������������������  생성한다.����������� ������������������  

•각각의����������� ������������������  Index를����������� ������������������  dataRegion의����������� ������������������  regionServer에����������� ������������������  할당

(LoadBalancer)����������� ������������������  

data의����������� ������������������  Region단위로����������� ������������������  인덱스����������� ������������������  생성하기����������� ������������������  •dataRegion과����������� ������������������  index리전의����������� ������������������  start/endRowkey를����������� ������������������  동일하게����������� ������������������  

•index’s����������� ������������������  rowkey:����������� ������������������  region’s����������� ������������������  startrow+value+rowkey����������� ������������������  

Local����������� ������������������  indexing

a����������� ������������������  …⋯����������� ������������������  b

a{}value.MIN����������� ������������������  …⋯����������� ������������������  a{}value.MAX

c����������� ������������������  …⋯����������� ������������������  g

h����������� ������������������  …⋯����������� ������������������  

c{}value.MIN����������� ������������������  …⋯����������� ������������������  c{}value.MAX

dataRegion1

indexOfRegion1

dataRegion2 dataRegion3

indexOfRegion2

43

Page 44: [223] h base consistent secondary indexing

IndexTable에서의����������� ������������������  range����������� ������������������  Scan����������� ������������������  •indexTable이����������� ������������������  값에����������� ������������������  의해����������� ������������������  정렬되어����������� ������������������  있지����������� ������������������  않다.����������� ������������������  

-����������� ������������������  dataTable의����������� ������������������  region개수만큼����������� ������������������  반복적으로����������� ������������������  scan����������� ������������������  

-����������� ������������������  2000개의����������� ������������������  리전����������� ������������������  =>����������� ������������������  2000번의����������� ������������������  scan����������� ������������������  

Region����������� ������������������  split����������� ������������������  •해당����������� ������������������  indexRegion의����������� ������������������  rowkey����������� ������������������  변경����������� ������������������  발생

Local����������� ������������������  indexing

a����������� ������������������  …⋯����������� ������������������  b

a{}value.MIN����������� ������������������  …⋯����������� ������������������  a{}value.MAX

c����������� ������������������  …⋯����������� ������������������  g

h����������� ������������������  …⋯����������� ������������������  

c{}value.MIN����������� ������������������  …⋯����������� ������������������  c{}value.MAX

dataRegion1

indexOfRegion1

dataRegion2 dataRegion3

indexOfRegion2

44

Page 45: [223] h base consistent secondary indexing

Local����������� ������������������  Indexing

Local����������� ������������������  indexing

dataRegion1

indexOfdata1

dataRegion2

indexOfdata2

RegionServer1

dataRegion3

indexOfdata3

dataRegion4

indexOfdata4

RegionServer2

Network비용이����������� ������������������  절약된다.

Pros����������� ������������������  •data����������� ������������������  <->����������� ������������������  index����������� ������������������  간의����������� ������������������  네트웍����������� ������������������  비용����������� ������������������  감소����������� ������������������  

•Network����������� ������������������  비용����������� ������������������  감소->����������� ������������������  전체����������� ������������������  성능����������� ������������������  향상����������� ������������������  

•hdfs����������� ������������������  level의����������� ������������������  network비용은����������� ������������������  별도����������� ������������������  

•hdfs����������� ������������������  replication…⋯,����������� ������������������  Data����������� ������������������  locality…⋯����������� ������������������  

Cons����������� ������������������  •Load����������� ������������������  Balancer를����������� ������������������  직접����������� ������������������  제작해야����������� ������������������  한다.����������� ������������������  

•Region����������� ������������������  관리가����������� ������������������  복잡하고����������� ������������������  효율성이����������� ������������������  떨어진다.����������� ������������������  

•값에����������� ������������������  의한����������� ������������������  인덱스����������� ������������������  스캔시에����������� ������������������  비효율����������� ������������������  

•Region����������� ������������������  split����������� ������������������  비용����������� ������������������  증가

45

Page 46: [223] h base consistent secondary indexing

Global����������� ������������������  Indexing

Pros����������� ������������������  •값을����������� ������������������  기준으로����������� ������������������  index가����������� ������������������  정렬되어����������� ������������������  있다.����������� ������������������  

•값에����������� ������������������  대한����������� ������������������  scan이����������� ������������������  더����������� ������������������  편하고����������� ������������������  자유롭다.����������� ������������������  

•추가적인����������� ������������������  리전����������� ������������������  관리����������� ������������������  비용이����������� ������������������  없다.����������� ������������������  

•사용����������� ������������������  방법이����������� ������������������  직관적이다.����������� ������������������  

Cons����������� ������������������  •Indexing과정과����������� ������������������  데이터����������� ������������������  조회����������� ������������������  과정에서����������� ������������������  추가적인����������� ������������������  

network����������� ������������������  비용이����������� ������������������  있다.����������� ������������������  

•HIM은����������� ������������������  Global����������� ������������������  Indexing����������� ������������������  방식으로����������� ������������������  구현

Global����������� ������������������  indexing

dataRegion1

Index2

dataRegion2

Index4

RegionServer1

dataRegion3

Index1

dataRegion4

Index3

RegionServer2

index와����������� ������������������  data가����������� ������������������  다른����������� ������������������  regionServer에����������� ������������������  존재하면����������� ������������������  추가적인����������� ������������������  Network����������� ������������������  비용이����������� ������������������  발생한다.

46

Page 47: [223] h base consistent secondary indexing

Coprocessor����������� ������������������  regionObserver

Operation����������� ������������������  (put,����������� ������������������  get,����������� ������������������  scan,����������� ������������������  …⋯)

preOp����������� ������������������  

postOp����������� ������������������  

Coprocessor를����������� ������������������  사용하여����������� ������������������  server-side����������� ������������������  구현����������� ������������������  •Client-side����������� ������������������  vs����������� ������������������  Server-side����������� ������������������  

•client����������� ������������������  side����������� ������������������  :����������� ������������������  hbase의����������� ������������������  client가����������� ������������������  HIM����������� ������������������  lib를����������� ������������������  사용하는����������� ������������������  방식����������� ������������������  

•server-side(coprocessor)����������� ������������������  :����������� ������������������  모든����������� ������������������  로직을����������� ������������������  서버쪽에����������� ������������������  구현

47

Page 48: [223] h base consistent secondary indexing

Coprocessor����������� ������������������  regionObserver

Operation����������� ������������������  (put,����������� ������������������  get,����������� ������������������  scan,����������� ������������������  …⋯)

preOp����������� ������������������  

postOp����������� ������������������  

Coprocessor를����������� ������������������  사용하여����������� ������������������  server-side����������� ������������������  구현����������� ������������������  •Coprocessor����������� ������������������  사용시����������� ������������������  장점����������� ������������������  

•성능����������� ������������������  개선����������� ������������������  (네트워크����������� ������������������  부하����������� ������������������  감소)����������� ������������������  

•hbase-server����������� ������������������  API����������� ������������������  사용����������� ������������������  

•compaction/open/close등의����������� ������������������  서버����������� ������������������  동작에����������� ������������������  따른����������� ������������������  동작가능����������� ������������������  

•table에����������� ������������������  접근����������� ������������������  하는����������� ������������������  모든����������� ������������������  사용자가����������� ������������������  HIM����������� ������������������  모듈을����������� ������������������  거치도록����������� ������������������  강제����������� ������������������  

•client의����������� ������������������  사용성����������� ������������������  증대����������� ������������������  

•hbase����������� ������������������  client����������� ������������������  API����������� ������������������  사용

48

Page 49: [223] h base consistent secondary indexing

HTableInterface htable = conn.getTable("movieStar");Put put = new Put(rowkey);put.add("bio".getbytes(), "sex".getBytes(), "Male".getBytes());...htable.put(put);htable.checkAndPut(put);

HTableInterface htable = conn.getTable("movieStar");Scan scan = new Scan();scan.setFilter(filter);ResultScanner rs = table.getScanner(scan);Result result = rs.next();…

dataTable에서의����������� ������������������  Put/Get/Scan

• hbase-client����������� ������������������  API를����������� ������������������  그대로����������� ������������������  사용한다.����������� ������������������  

• 기존����������� ������������������  사용����������� ������������������  방법����������� ������������������  그대로����������� ������������������  ����������� ������������������  

• 모든����������� ������������������  indexing관련����������� ������������������  로직은����������� ������������������  RegionServer에서����������� ������������������  발생����������� ������������������  

• hbase����������� ������������������  API가����������� ������������������  기본����������� ������������������  제공하는����������� ������������������  Filter,����������� ������������������  checkAndPut등의����������� ������������������  기능����������� ������������������  동작

49

Page 50: [223] h base consistent secondary indexing

HTableInterface indexTable = conn.getTable(“movieStar.index.spouse”);Scan indexTableScan = new Scan(“Angelina".getBytes());indexTableScan.setStopRow(“Angelinb”.getBytes());scan.setFilter(filter);ResultScanner indexTableScanner = indexTable.get(dataTableGet);Result result = indexTableScanner.next();for (Cell cell : result.listCells()) {

System.out.println(Bytes.toString(cell.getFamilyArray()) + "\t"+ Bytes.toString(cell.getQualifierArray()) + “\t" +Bytes.toString(cell.getValueArray()));

}

IndexTable의����������� ������������������  Get/Scan

• hbase-client����������� ������������������  API를����������� ������������������  그대로����������� ������������������  사용한다.����������� ������������������  

• TableName����������� ������������������  :����������� ������������������  indexTable의����������� ������������������  이름����������� ������������������  

• startRow/StopRow����������� ������������������  :����������� ������������������  조회할����������� ������������������  값의����������� ������������������  Range����������� ������������������  

• hbase����������� ������������������  API가����������� ������������������  기본����������� ������������������  제공하는����������� ������������������  기능����������� ������������������  동작

50

Page 51: [223] h base consistent secondary indexing

List<Result>����������� ������������������  by����������� ������������������  scanner����������� ������������������  from����������� ������������������  ‘movieStars’����������� ������������������  dataTable

List<Result>����������� ������������������  by����������� ������������������  scanner����������� ������������������  from����������� ������������������  ‘movieStars.index.spouse’����������� ������������������  indexTable

rowkeybio: fam: career:����������� ������������������  

name birth sex hometown spouse occupation debutYear

Angelina����������� ������������������  Jolie{}Brad����������� ������������������  pitt

Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963 M oklahoma Angelina����������� ������������������  Jolie Actor 1987

Katie����������� ������������������  Holmes{}Tom����������� ������������������  Cruise

Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY Katie����������� ������������������  Holmes Actor 1981

{}Leonardo����������� ������������������  Dicaprio

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989

rowkeybio: fam: career:����������� ������������������  

name birth sex hometown spouse occupation debutYear

Brad����������� ������������������  pitt Brad����������� ������������������  pitt dec.����������� ������������������  18,����������� ������������������  1963 M oklahoma Angelina����������� ������������������  Jolie Actor 1987

Leonardo����������� ������������������  Dicaprio

Leonardo����������� ������������������  Dicaprio

Nov����������� ������������������  11,����������� ������������������  1974 M LA,����������� ������������������  CA Actor 1989

Tom����������� ������������������  Cruise Tom����������� ������������������  cruise July����������� ������������������  3,����������� ������������������  1962 M Syracuse,����������� ������������������  NY Katie����������� ������������������  Holmes Actor 1981

Scan/Get����������� ������������������  결과의����������� ������������������  Result객체

• DataTable과����������� ������������������  IndexTable을����������� ������������������  접근했을때����������� ������������������  동일한����������� ������������������  Result를����������� ������������������  얻게����������� ������������������  된다.

51

Page 52: [223] h base consistent secondary indexing

Filter

•Filter를����������� ������������������  통해����������� ������������������  

•Filter����������� ������������������  데이터를����������� ������������������  filtering하고����������� ������������������  

•Modify����������� ������������������  리턴할����������� ������������������  데이터를����������� ������������������  수정하고����������� ������������������  

•Skip����������� ������������������  다음에����������� ������������������  읽을����������� ������������������  데이터를����������� ������������������  건너뛸����������� ������������������  수����������� ������������������  있다.����������� ������������������  

•사용자가����������� ������������������  customise����������� ������������������  할����������� ������������������  수����������� ������������������  있다.

52

Page 53: [223] h base consistent secondary indexing

•HIM에서����������� ������������������  데이터를����������� ������������������  읽을����������� ������������������  때����������� ������������������  

•Filter����������� ������������������  유효하지����������� ������������������  않은����������� ������������������  데이터를����������� ������������������  거르고����������� ������������������  

•Modify����������� ������������������  index정보를����������� ������������������  유효한����������� ������������������  데이터로����������� ������������������  바꿔주고����������� ������������������  

•Skip����������� ������������������  유효하지����������� ������������������  않은����������� ������������������  index는����������� ������������������  건너뛴다.����������� ������������������  

•HIM은����������� ������������������  customFilter를����������� ������������������  이용한다.

Filter

53

Page 54: [223] h base consistent secondary indexing

Coprocessor����������� ������������������  +����������� ������������������  Custom����������� ������������������  Filter����������� ������������������  

54

Page 55: [223] h base consistent secondary indexing

데이터����������� ������������������  입력시����������� ������������������  인덱스를����������� ������������������  Clean-up����������� ������������������  하지����������� ������������������  않는다면?����������� ������������������  • 여전히����������� ������������������  consistent하다.����������� ������������������  (Versioned����������� ������������������  Index)����������� ������������������  

• index����������� ������������������  scan이����������� ������������������  느려진다.����������� ������������������  (유효하지����������� ������������������  않은����������� ������������������  데이터를����������� ������������������  읽게되므로)����������� ������������������  

• Put����������� ������������������  성능이����������� ������������������  빨라진다.movieStar.index.spouse

rowkeytimestamp him.index.meta

rowkey timestamp

Angelina Jolie{}Brad pitt 3 Brad pitt 3

Katie Holmes{}Tom Cruise 5 Tom Cruise 5

{}Leonardo Dicaprio 12 Leonardo Dicaprio 12

{}Tom Cruise 6 Tom Cruise 6

Out-datedScan.next()

Discard

Scan.next()

Scan.next()

clean-up

55

Page 56: [223] h base consistent secondary indexing

Lazy����������� ������������������  clean-up

Put도����������� ������������������  빠르게,����������� ������������������  Index����������� ������������������  Scan도����������� ������������������  빠르게?����������� ������������������  • Put����������� ������������������  할때는����������� ������������������  clean-up하지����������� ������������������  않는다.����������� ������������������  

• Index는����������� ������������������  주기적으로����������� ������������������  Clean-up한다.����������� ������������������  

• Compaction����������� ������������������  중에����������� ������������������  (default)����������� ������������������  

• index����������� ������������������  scan중����������� ������������������  유효하지����������� ������������������  않은����������� ������������������  것이����������� ������������������  발견될����������� ������������������  때����������� ������������������  (optional)����������� ������������������  

• MR로����������� ������������������  사용자가����������� ������������������  직접����������� ������������������  (optional)

56

Page 57: [223] h base consistent secondary indexing

operation local put global put local get global get total

vanilla hbase put 1 1 put

vanilla hbase get 1 1 get

him put 1 1 + n (n: indexes) 1 2+n puts, 1get

him dataTable get(scan) 1 1 gets

him indexTable get(scan) 2 2 gets

Operation����������� ������������������  counts

57

Page 58: [223] h base consistent secondary indexing

Put����������� ������������������  성능

(put

s/m

in)

0

400,000

800,000

1,200,000

1,600,000

2,000,000

2,400,000

vanilla HBase HIM on HBase

1,989,7962,304,256 -13%

HIM����������� ������������������  설치후����������� ������������������  Put성능이����������� ������������������  약����������� ������������������  10%����������� ������������������  하락����������� ������������������  •index����������� ������������������  consistency����������� ������������������  보장����������� ������������������  비용����������� ������������������  

•2+n����������� ������������������  번의����������� ������������������  Put����������� ������������������  과����������� ������������������  1번의����������� ������������������  Get����������� ������������������  발생����������� ������������������  (����������� ������������������  n:����������� ������������������  index����������� ������������������  개수)����������� ������������������  

11 regionServers of Linux 2.6.32-431.11.2.el6.x86_64 Intel(R) Xeon(R) CPU L5640 @ 2.27GHz * 24

49414044kb RAM 58

Page 59: [223] h base consistent secondary indexing

Index����������� ������������������  개수와����������� ������������������  비례하여����������� ������������������  최대����������� ������������������  성능����������� ������������������  하락����������� ������������������  •hbase����������� ������������������  cluster는����������� ������������������  network����������� ������������������  bandwidth가����������� ������������������  병목����������� ������������������  

•indexing에����������� ������������������  따른����������� ������������������  네트웍����������� ������������������  부하로����������� ������������������  총����������� ������������������  put����������� ������������������  count����������� ������������������  하락����������� ������������������  

Index����������� ������������������  개수에����������� ������������������  따른����������� ������������������  Put����������� ������������������  성능

(puts����������� ������������������  /����������� ������������������  m

in)

0

1,000,000

2,000,000

(number����������� ������������������  of����������� ������������������  full����������� ������������������  indexes)

0 1 2 3 4

1,989,796

1,710,952

1,308,224

1,002,752

739,692

-15%-23%

-23%

-24%

59

Page 60: [223] h base consistent secondary indexing

Scan����������� ������������������  latency

Latency(m

sec)

0

3.75

7.5

11.25

15

18.75

22.5

26.25

30

plain����������� ������������������  hbase him/data him/index

Get Scan Get Scan Get Scan

10

5.24.7

26

9

7

•dataTable의����������� ������������������  scan/get시에����������� ������������������  성능����������� ������������������  하락은����������� ������������������  크지����������� ������������������  않다.����������� ������������������  

•indexTable의����������� ������������������  get때에는����������� ������������������  dataTable����������� ������������������  scan대배����������� ������������������  약����������� ������������������  2~3배의����������� ������������������  성능����������� ������������������  하락����������� ������������������  

•총����������� ������������������  2번의����������� ������������������  random����������� ������������������  get����������� ������������������  발생����������� ������������������  

•보조����������� ������������������  인덱스가����������� ������������������  없다면����������� ������������������  dataTable을����������� ������������������  full����������� ������������������  scan해야할����������� ������������������  상황

60

Page 61: [223] h base consistent secondary indexing

4.Nosql과보조인덱스

Page 62: [223] h base consistent secondary indexing

HIM����������� ������������������  HBase����������� ������������������  Nosql

62

Page 63: [223] h base consistent secondary indexing

NoSql

Big����������� ������������������  data����������� ������������������  

Schema����������� ������������������  Free

63

Page 64: [223] h base consistent secondary indexing

Big����������� ������������������  index����������� ������������������  

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  Schema����������� ������������������  Free����������� ������������������  index

NoSql,����������� ������������������  Index

Big����������� ������������������  data����������� ������������������  

Schema����������� ������������������  Free

64

Page 65: [223] h base consistent secondary indexing

• Sub-Index

• Dynamic����������� ������������������  &����������� ������������������  easy����������� ������������������  index����������� ������������������  Drop/Creation/Modification����������� ������������������  • Tag

NoSql,����������� ������������������  Index����������� ������������������  &����������� ������������������  HIM

Big����������� ������������������  data����������� ������������������  

Schema����������� ������������������  Free

Big����������� ������������������  index����������� ������������������  

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  Schema����������� ������������������  Free����������� ������������������  index

65

Page 66: [223] h base consistent secondary indexing
Page 67: [223] h base consistent secondary indexing

HBaseTable = PaperBook rowkey = page_num + word_seq value = word

: FullScan 하면 책 한권의 contents를 얻을수 있다.

한권의����������� ������������������  책을����������� ������������������  HBase����������� ������������������  Table에����������� ������������������  넣는다면?

67

Page 68: [223] h base consistent secondary indexing

HBaseTable = PaperBook rowkey = page_num + word_seq value = word

IndexTable = PaperBook’s index indexRowkey = hotKeyword{}page_num

Index는?

68

Page 69: [223] h base consistent secondary indexing

HBaseTable = PaperBook rowkey = page_num + word_seq value = word

IndexTable = PaperBook’s index indexRowkey = hotKeyword{}page_num

책의����������� ������������������  모든����������� ������������������  단어를����������� ������������������  Indexing하지는����������� ������������������  않는다.

모든����������� ������������������  데이터를����������� ������������������  Indexing하지����������� ������������������  않는다.

69

Page 70: [223] h base consistent secondary indexing

Big����������� ������������������  dataBig����������� ������������������  indexMore����������� ������������������  disks����������� ������������������  

More����������� ������������������  networks����������� ������������������  

More����������� ������������������  operations����������� ������������������  

More����������� ������������������  region����������� ������������������  overheads:����������� ������������������  

-����������� ������������������  More����������� ������������������  compactions����������� ������������������  

-����������� ������������������  More����������� ������������������  splits����������� ������������������  

-����������� ������������������  More����������� ������������������  flushes����������� ������������������  

-����������� ������������������  More����������� ������������������  replays����������� ������������������  

…⋯Index를����������� ������������������  통해����������� ������������������  데이터를����������� ������������������  찾지����������� ������������������  않는다면����������� ������������������  ����������� ������������������  

모든����������� ������������������  비용은����������� ������������������  쓸모가����������� ������������������  없다.

Full����������� ������������������  index����������� ������������������  비용

70

Page 71: [223] h base consistent secondary indexing

X필요한����������� ������������������  데이터만����������� ������������������  Indexing하기

Sub-index란?

71

Page 72: [223] h base consistent secondary indexing

General����������� ������������������  Index->����������� ������������������  

Non-conditional����������� ������������������  Index->����������� ������������������  

Column-based����������� ������������������  Index->����������� ������������������  

Full����������� ������������������  Index->

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  Purpose����������� ������������������  orientated����������� ������������������  Index����������� ������������������  

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  Multi-Conditional����������� ������������������  Index����������� ������������������  

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  Cell(Column+Value)����������� ������������������  based����������� ������������������  Index����������� ������������������  

����������� ������������������  Sub-Index

Full-index에서����������� ������������������  Sub-index로

72

Page 73: [223] h base consistent secondary indexing

EQUAL����������� ������������������  NOT_EQUAL����������� ������������������  

GREAT_OR_EQUAL����������� ������������������  SMALL_THAN����������� ������������������  

NULL����������� ������������������  NOT_NULL����������� ������������������  

…⋯

String����������� ������������������  int����������� ������������������  long����������� ������������������  short����������� ������������������  float����������� ������������������  byte[]����������� ������������������  …⋯

&

sub����������� ������������������  index����������� ������������������  조건과����������� ������������������  데이터타입

73

Page 74: [223] h base consistent secondary indexing

HTableInterface indexTable = conn.getTable(“movieStar.index.singleAndYoung”);ResultScanner indexTableScanner =

indexTable.scan(new Scan());…

HTableInterface indexTable = conn.getTable(“movieStar.index.spouse”);Scan scan = new Scan();scan.setStartRowkey(“{}”.getBytes());scan.setStopRowkey(“{~”.getBytes()));SingleColumnValueFilter filter =

new SingleColumnValueFilter(“bio”.getBytes(), “age”.getBytes(), CompareOp.LESS, new BinaryComparator(Bytes.toBytes(35)));

scan.setFilter(filter);ResultScanner indexTableScanner =

indexTable.scan(scan);…

( {} : seperator )

Request] 35살 이하, 결혼하지 않은 배우 정보 리스트- Full����������� ������������������  index����������� ������������������  movieStar.index.spouse����������� ������������������  - “spouse”����������� ������������������  컬럼으로����������� ������������������  indexing

- Sub-index����������� ������������������  movieStar.index.singleAndYoung����������� ������������������  - indexing����������� ������������������  when����������� ������������������  spouse����������� ������������������  is����������� ������������������  null����������� ������������������  and����������� ������������������  age����������� ������������������  <����������� ������������������  35

Purpose����������� ������������������  orientated����������� ������������������  index

74

Page 75: [223] h base consistent secondary indexing

작고����������� ������������������  많은����������� ������������������  수의����������� ������������������  인덱스����������� ������������������  vs����������� ������������������  크고����������� ������������������  적은����������� ������������������  수의����������� ������������������  인덱스����������� ������������������  • indexing에����������� ������������������  발생하는����������� ������������������  부하량에����������� ������������������  따라����������� ������������������  성능차이가����������� ������������������  발생����������� ������������������  

• indexTable개수와는����������� ������������������  상관없이����������� ������������������  indexing에����������� ������������������  의해����������� ������������������  발생하는����������� ������������������  부하가����������� ������������������  성능을����������� ������������������  결정����������� ������������������  

• 작은����������� ������������������  Sub-index들이,����������� ������������������  개수가����������� ������������������  많더라도����������� ������������������  Full����������� ������������������  index보다����������� ������������������  효율적이다.

dataTable.index.condition1����������� ������������������  

dataTable.index.condition2����������� ������������������  

dataTable.index.condition3����������� ������������������  

…⋯����������� ������������������  

dataTable.index.condition29����������� ������������������  

dataTable.index.condition30dataTable.index.full����������� ������������������  

<1,710,952����������� ������������������  

����������� ������������������  puts����������� ������������������  per����������� ������������������  minute2,146,554����������� ������������������  

����������� ������������������  puts����������� ������������������  per����������� ������������������  minute

1����������� ������������������  Full����������� ������������������  Index 30����������� ������������������  of����������� ������������������  0.1%����������� ������������������  sub-Indices

Purpose����������� ������������������  orientated����������� ������������������  index

75

Page 76: [223] h base consistent secondary indexing

Performance:����������� ������������������  작고����������� ������������������  많은����������� ������������������  sub-Indices

(����������� ������������������  puts����������� ������������������  /����������� ������������������  m

in����������� ������������������  )

0

1,100,000

2,200,000

number����������� ������������������  of����������� ������������������  0.1%����������� ������������������  sub����������� ������������������  indexes

0 10 20 30

1,911,9641,989,796 2,009,020

2,146,544

•table의����������� ������������������  개수가����������� ������������������  성능에����������� ������������������  영향을����������� ������������������  미치지����������� ������������������  않는다.����������� ������������������  

•성능은����������� ������������������  network����������� ������������������  부하와����������� ������������������  관련이����������� ������������������  깊은����������� ������������������  것으로����������� ������������������  나타난다.

76

Page 77: [223] h base consistent secondary indexing

•10%����������� ������������������  sub-index����������� ������������������  =����������� ������������������  전체����������� ������������������  데이터의����������� ������������������  1/10����������� ������������������  정도가����������� ������������������  indexing����������� ������������������  대상����������� ������������������  

•성능은����������� ������������������  network����������� ������������������  부하와����������� ������������������  관련이����������� ������������������  깊은����������� ������������������  것으로����������� ������������������  나타난다.

Performance:����������� ������������������  10%����������� ������������������  sub����������� ������������������  indices

(puts/m

in)

0

1,000,000

2,000,000

number����������� ������������������  of����������� ������������������  10%����������� ������������������  sub-indexes

0 10 20

1,911,964

1,738,544

1,341,936

77

Page 78: [223] h base consistent secondary indexing

•10����������� ������������������  *����������� ������������������  10%����������� ������������������  subIndex����������� ������������������  부하량����������� ������������������  =����������� ������������������  1����������� ������������������  full����������� ������������������  index의����������� ������������������  부하량����������� ������������������  

•실제로����������� ������������������  indexing되는����������� ������������������  데이터����������� ������������������  양에����������� ������������������  비례해서����������� ������������������  성능����������� ������������������  감소가����������� ������������������  나타난다.

Performance:����������� ������������������  10%����������� ������������������  sub����������� ������������������  indices

(puts/m

in)

0

1,000,000

2,000,000

number����������� ������������������  of����������� ������������������  10%����������� ������������������  sub-indexes

0 10 20

1,911,964

1,738,544

1,341,936

1,989,796

1,710,952

1,308,224

0����������� ������������������  full����������� ������������������  index

1����������� ������������������  full����������� ������������������  index

2����������� ������������������  full����������� ������������������  indices

78

Page 79: [223] h base consistent secondary indexing

Disk����������� ������������������  Usage

•Sub-index를����������� ������������������  사용하여����������� ������������������  disk����������� ������������������  사용량����������� ������������������  및����������� ������������������  리전����������� ������������������  관리����������� ������������������  비용들을����������� ������������������  줄일����������� ������������������  수����������� ������������������  있다.

하늘색����������� ������������������  :����������� ������������������  dataTable

파랑색:����������� ������������������  Full����������� ������������������  index나머지색����������� ������������������  :����������� ������������������  Sub����������� ������������������  indices

region����������� ������������������  servers

79

Page 80: [223] h base consistent secondary indexing

RegionRegionRegionRegionRegionRegionRegionRegion

HIMHIMHIMHIMHIMHIMHIMHIM

Zookeeper

Dynamic����������� ������������������  &����������� ������������������  Flexible

유연하고����������� ������������������  동적인����������� ������������������  구조라면����������� ������������������  • 동적인����������� ������������������  Index의����������� ������������������  생성/삭제/수정����������� ������������������  

• 서비스의����������� ������������������  interrupt나����������� ������������������  dataTable과����������� ������������������  다른����������� ������������������  indexTable들의����������� ������������������  disable없이����������� ������������������  

• 모든����������� ������������������  region들에서����������� ������������������  즉시����������� ������������������  적용되도록����������� ������������������  

• Zookeeper의����������� ������������������  Watcher����������� ������������������  활용

80

Page 81: [223] h base consistent secondary indexing

SNS의����������� ������������������  #HashTag와����������� ������������������  유사한����������� ������������������  기능����������� ������������������  •Client가����������� ������������������  직접����������� ������������������  tag할����������� ������������������  name을����������� ������������������  입력����������� ������������������  

•특정����������� ������������������  column의����������� ������������������  특정����������� ������������������  값에����������� ������������������  종속되지����������� ������������������  않음����������� ������������������  

•사용자가����������� ������������������  원하는����������� ������������������  기준으로����������� ������������������  데이터를����������� ������������������  찾을����������� ������������������  수����������� ������������������  있다.����������� ������������������  

•인덱스����������� ������������������  테이블����������� ������������������  생성/삭제등의����������� ������������������  관리와����������� ������������������  많은����������� ������������������  수의����������� ������������������  index����������� ������������������  생성이����������� ������������������  불필요

#Tag

Tag

81

Page 82: [223] h base consistent secondary indexing

Tagging/untaggingtag/untag����������� ������������������  ����������� ������������������  •setAttributes(String,����������� ������������������  byte[])를����������� ������������������  사용����������� ������������������  •Get,����������� ������������������  Scan,����������� ������������������  Put에서����������� ������������������  모두����������� ������������������  사용����������� ������������������  •데이터����������� ������������������  수정없이����������� ������������������  tagging����������� ������������������  가능����������� ������������������  

•him.tag.action����������� ������������������  •tag����������� ������������������  :����������� ������������������  tagName으로����������� ������������������  tagging����������� ������������������  •untag����������� ������������������  :����������� ������������������  tagName으로����������� ������������������  untagging����������� ������������������  •untagAll����������� ������������������  :����������� ������������������  해당����������� ������������������  row의����������� ������������������  tag����������� ������������������  모두����������� ������������������  제거����������� ������������������  •tagCurrent����������� ������������������  :����������� ������������������  현재����������� ������������������  버전의����������� ������������������  데이터만����������� ������������������  tag����������� ������������������  

(row의����������� ������������������  업데이트시����������� ������������������  자동����������� ������������������  tag삭제)����������� ������������������  

Put put = new Put(rowkey);put.setAttributes(“him.tag.action”, “tag”);put.setAttributes(“him.tag.name”, “age 32”);...

Get get = new Get(rowkey);put.setAttributes(“him.tag.action”, “untag”);put.setAttributes(“him.tag.name”, “age 32”);...

Scan scan = new Scan();scan.setFilter(filter);put.setAttributes(“him.tag.action”, “untagAll”);...

82

Page 83: [223] h base consistent secondary indexing

Get����������� ������������������  by����������� ������������������  tag����������� ������������������  name

table = conn.getTable("movieStar.tags");Scan scan = new Scan("age 30".getBytes());scan.setStopRow("age 40".getBytes());scanner = table.getScanner(scan);…

Scan scan2 = new Scan("age 30".getBytes());scan2.setStopRow("age 40".getBytes());scanner2 = table.getScanner(scan);

Scan����������� ������������������  by����������� ������������������  Tag����������� ������������������  •TagTable을����������� ������������������  tagName을����������� ������������������  range로����������� ������������������  scan

83

Page 84: [223] h base consistent secondary indexing

• 내����������� ������������������  시스템에����������� ������������������  index의����������� ������������������  consistency가����������� ������������������  필요할까?����������� ������������������  

• HBase에서����������� ������������������  Table����������� ������������������  스키마와����������� ������������������  rowkey����������� ������������������  디자인은����������� ������������������  중요하다����������� ������������������  

• 성능과����������� ������������������  사용패턴을����������� ������������������  결정����������� ������������������  

• 보조����������� ������������������  인덱스가����������� ������������������  필요����������� ������������������  없을����������� ������������������  수도����������� ������������������  있다����������� ������������������  

• index에도����������� ������������������  design이����������� ������������������  필요할����������� ������������������  때가����������� ������������������  있다.����������� ������������������  

• hotspot은����������� ������������������  피하고����������� ������������������  

• 사용형태에����������� ������������������  맞춰서����������� ������������������  indexing할����������� ������������������  값의����������� ������������������  형태를����������� ������������������  맞추거나����������� ������������������  

• 여러����������� ������������������  필드의����������� ������������������  조합,����������� ������������������  sub-indexing,����������� ������������������  tag����������� ������������������  

• 성능테스트&튜닝����������� ������������������  

• hbase의����������� ������������������  다른����������� ������������������  테이블들을����������� ������������������  만들����������� ������������������  때처럼����������� ������������������  튜닝&설정변경����������� ������������������  

• 사용����������� ������������������  패턴에����������� ������������������  맞는����������� ������������������  설정과����������� ������������������  구조는����������� ������������������  성능을����������� ������������������  높여준다.

마무리:보조인덱스����������� ������������������  구축시����������� ������������������  고려할����������� ������������������  점

84

Page 85: [223] h base consistent secondary indexing

Q&A

Page 86: [223] h base consistent secondary indexing

Thank You