SlideShare a Scribd company logo
LENMAN-YAO concurrent  B-Tree (a.k.a B-Link-Tree) 油井 誠  (Makoto YUI)
  BEGIN;
B-Link Tree とは (history) A variant of B*-Tree (they call)  actually.. a B+-tree? (data stored in leaf only) 1981 年  PHILIP.L. LEHMAN , S.BING  YAO   ” Efficient  Locking  for  Concurrent  Operations on B-Trees ” という論文で発表 当時,複数の プロセス で同時実効性を持つデータベースの構築が流行りだった ( らしい 論文の主眼は如何に効率のよく高い同時実効性を有する索引を構築するか.
B*-Tree an elegant(?) variant on B+-tree keep  pages at least 2/3 full, guaranteed .  The benefit over B+-trees is not large, a worst case reduction in page usage of  16.67% メモリが安く早くなりつつあるので、メモリスペースを節約するアルゴリズムから脱却すべきではないだろうか. 沢山のメモリを利用することで、レイテンシーが問題がなることがある.よりエレガントなアルゴリズムが必要になってくる. これは既に、バスのキャパシティを CPU スピードが追い越すことで起こっていることである. http://www.cise.ufl.edu/~jhammer/classes/b_star.html
B-Link-Tree (Key issue) No Read-Lock !! 複数のプロセスが同時に更新した場合に,少数のノードをロックする ロックの競合は稀である ロックの粒度が高く,開放が早い (non-2PL) ロック自体は update 時に Binary Lock (simple) デッドロックはないが,分散システムを考えるとよくないかも (? Additional Value to B*-Tree right-link  ,  high key   Breadth-first search (横型探索 ) が可能 . ノードにたどり着く Alternative way が存在する . Tree traversing operation search: top-down, left-to-right  insert:  bottom-up
デッドロック ( 待ちグラフ ) T2 T1 T3 2 層ロック ( トランザクション内で処理する オブジェクトを順にロックする ) では, 巡回経路ができ,デッドロックが発生する. 巡回閉路
B-link-Tree Structure (a) Leaf( 実際のデータへのポインタを有す ) への 距離は一定 (of course, well balanced) (b)  各ノードは基本的に 最低 K+1 の子 ( への pointer) を 持つ ただし、 Root は常に最低 2 つの子を持つ (c)  各ノードは 最高 2k+1(exclude High-Key) の子を 持つ  “ High-key ” と呼ばれる追加エントリを持つこともある (+1) (d) key は leaf ノードに存在 key はデータベースのレコードへのポインタを有す .  ( 各レコードがキーと関連付けられている )
B*-Tree Node Structure (with no  “ high key ” ) Internal use only.
Leaf
P i は Subtree T i を指す  T i に含まれるキー値は K i-1  < v <= K i Leaf と non-leaf ノードの構造が同一 ( シンプル ) M は Leaf であることを識別する Marker
High-key ノードが溢れる時 (Split) ,ノードの右端に付加される Rightmost-link を辿る時に使われる.
Set (51, 74) High-Key
更新時の処理 (basis) x: 物理ページ (Logical ノードと呼んでいる ) Lock(x); //  ページ X を更新する際にマーキング //  もし既にロックされていたら wait() A <- get(x);  // Disk からメモリに読み込む  Modify data in A  //  メモリ内の A を更新 Put(A, x) //  メモリから Disk の sync Unlock(x); //  ロックを解除
Native approach ロックする必要がある. (read rock) Top-Down locking. 操作ノード下子孫をロック 15 の探索中に 9 が Insert され, Split されたケース Wait
Rightmost-link B-link-Tree は各ノードに Single Link Pointer を持つ. 各レベルが単方向リスト . 目的 目的のノードに到達するための Alternative way を提供する どのノードもたどり着く為の 2 つの Pointer を持つ Overflow Replaced by two New  node. (usually, the two nodes Are on the same physical page) Essentially same as A single node until the Parent pointer is added.
Use high-key 74 74 63 HighKey HighKey Split 直後 ( 親へのリンクポインタが修正されていない ) 72 を探すケースを考えてみる. ここの中に High Key があるはずだが, Split されてない. この時, Link Pointer を辿る必要がある. この条件を High-Key と Search Key の比較によって行う. Search key が High key 以上ならポインタを辿る
An structure example of B-link-Tree Additional advantage: level-major order での取得が早い (Leaf をすべて取得する場合など )
Search Algorithm current = root; /* root の pointer を設定  */ A = get(current); /*  ノードを memory に読み込む */   while (current is not a leaf)  /* leaf に到達するまでループ */   current = scannode1(v, A); /* v をキーに memory bloak A を走査  */ /*  リンクポインタを返す  */ A = get(current); /*  リンク先のノード読み込み  */ / * now reached to leaves * / * leaf 内の線形探索  */ while ((t = scannode(v,A)) == link pointer of A)  current = t; A = get(current); //  値 v を持つ leaf が見つかったか ? if (v is in A) return(success); else return(failure); Simple! Only trick is to have scannode know about high-keys and right-links.   Right-link か Child-link かは 問わない
Insert Algorithm 基本的に , Search と似たような下準備をする. Step 1. 木を辿ってキー値 v を含む (should include) リーフノードを探す. その際, Rightmost-link をスタックに積む. Step2. “ remembered list ” ( 辿ってきた道 ) を辿って,実際の挿入 Bottom-up insert .
Insert(1) initialize stack; /* to remember ancestors */ current = root; A = get(current); /* scan down the tree */ while (current is not a leaf) { t = current; current = scannode(v,A); if (current not link pointer in A) push t;  /* remember node at the level */ A = get(current); } /* reached to leaf */ lock(current); A = get(current); move_right();  /* if required, move right and lock the neighbor */
// current node の update. // Split Node // for locking.. Remember the oldnode and the parent. // lock parent, oldnode, and the next-sibling.
A B C D E F G H splited A Bottom-up Stack (right-most-link) B E Leaf Found G
D E G H Leaf A Bottom-up Stack (right-most-link) B E If need to Split Flush Flush B Lock Flush Un Lock Finish! G I ’ G’ I ’ G’ E E
P A C Leaf Insert algorithm(Write lock / no read lock) B ’ A ’ P Bottom-up Stack Insert(Split) A ’ Flush Lock A B ’ Flush
Delete Too simple (leaf のエントリが K 以下なら,この論文は primary index を前提 ) Just remove keys from a leaf node. (never do deletion from internal nodes) Delete が続くとノードのエントリが k エントリ以下に なることがある. (starvation?)
problems Livelock multiprocesser system,  where one process runs indenfinitely ( 特に processing speed に差がある時 ) Following link pointer が別プロセスで作られると極端に遅くなることがある
  END;

More Related Content

PPTX
トランザクションの設計と進化
PPTX
地理分散DBについて
PPTX
PostgreSQL 14 モニタリング新機能紹介(PostgreSQL カンファレンス #24、2021/06/08)
PDF
PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...
PDF
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
PDF
YugabyteDBを使ってみよう - part2 -(NewSQL/分散SQLデータベースよろず勉強会 #2 発表資料)
PDF
YugabyteDBを使ってみよう(NewSQL/分散SQLデータベースよろず勉強会 #1 発表資料)
PPTX
祝!PostgreSQLレプリケーション10周年!徹底紹介!!
トランザクションの設計と進化
地理分散DBについて
PostgreSQL 14 モニタリング新機能紹介(PostgreSQL カンファレンス #24、2021/06/08)
PostgreSQLのバグとの付き合い方 ~バグの調査からコミュニティへの報告、修正パッチ投稿まで~(PostgreSQL Conference Japa...
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
YugabyteDBを使ってみよう - part2 -(NewSQL/分散SQLデータベースよろず勉強会 #2 発表資料)
YugabyteDBを使ってみよう(NewSQL/分散SQLデータベースよろず勉強会 #1 発表資料)
祝!PostgreSQLレプリケーション10周年!徹底紹介!!

What's hot (20)

PDF
PostgreSQLバックアップの基本
PDF
トランザクション処理可能な分散DB 「YugabyteDB」入門(Open Source Conference 2022 Online/Fukuoka 発...
PDF
AlmaLinux と Rocky Linux の誕生経緯&比較
PDF
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)
PDF
TidalScaleで複数の物理サーバを集約しインメモリーコンピューティングを実現
PDF
PacemakerのMaster/Slave構成の基本と事例紹介(DRBD、PostgreSQLレプリケーション) @Open Source Confer...
PPTX
スケールアウトするPostgreSQLを目指して!その第一歩!(NTTデータ テクノロジーカンファレンス 2020 発表資料)
PDF
PostgreSQLアーキテクチャ入門(INSIGHT OUT 2011)
PDF
待ち事象から考える、Sql server の改善ポイント
PDF
NTT DATA と PostgreSQL が挑んだ総力戦
PDF
PostgreSQL: XID周回問題に潜む別の問題
PDF
MyRocks Deep Dive
PDF
At least onceってぶっちゃけ問題の先送りだったよね #kafkajp
PPTX
iostat await svctm の 見かた、考え方
PPTX
キャッシュコヒーレントに囚われない並列カウンタ達
PDF
TLS 1.3 と 0-RTT のこわ〜い話
PDF
GraalVMでのFlight Recorderを使ったパフォーマンス解析(JJUG CCC 2023 Spring)
PPTX
押さえておきたい、PostgreSQL 13 の新機能!!(Open Source Conference 2021 Online/Hokkaido 発表資料)
PPTX
今から始めるWebClient(JSUG勉強会 2020年その6 LT大会)
PDF
pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQLバックアップの基本
トランザクション処理可能な分散DB 「YugabyteDB」入門(Open Source Conference 2022 Online/Fukuoka 発...
AlmaLinux と Rocky Linux の誕生経緯&比較
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)
TidalScaleで複数の物理サーバを集約しインメモリーコンピューティングを実現
PacemakerのMaster/Slave構成の基本と事例紹介(DRBD、PostgreSQLレプリケーション) @Open Source Confer...
スケールアウトするPostgreSQLを目指して!その第一歩!(NTTデータ テクノロジーカンファレンス 2020 発表資料)
PostgreSQLアーキテクチャ入門(INSIGHT OUT 2011)
待ち事象から考える、Sql server の改善ポイント
NTT DATA と PostgreSQL が挑んだ総力戦
PostgreSQL: XID周回問題に潜む別の問題
MyRocks Deep Dive
At least onceってぶっちゃけ問題の先送りだったよね #kafkajp
iostat await svctm の 見かた、考え方
キャッシュコヒーレントに囚われない並列カウンタ達
TLS 1.3 と 0-RTT のこわ〜い話
GraalVMでのFlight Recorderを使ったパフォーマンス解析(JJUG CCC 2023 Spring)
押さえておきたい、PostgreSQL 13 の新機能!!(Open Source Conference 2021 Online/Hokkaido 発表資料)
今から始めるWebClient(JSUG勉強会 2020年その6 LT大会)
pg_hint_planを知る(第37回PostgreSQLアンカンファレンス@オンライン 発表資料)
Ad

Viewers also liked (13)

PPTX
Oracle DBA Online Training in India
PDF
Bigtable and Boxwood
PPT
Top 10 Oracle SQL tuning tips
PPT
1.9 b tree
PPTX
Network Forensics
PPT
Tpr star tree
ZIP
Algorithm Introduction #18 B-Tree
PDF
Лекция 5: B-деревья (B-trees, k-way merge sort)
PPT
floor planning
PPTX
CAD: introduction to floorplanning
PPTX
Examining Mac File Structures
PPT
17. Trees and Graphs
Oracle DBA Online Training in India
Bigtable and Boxwood
Top 10 Oracle SQL tuning tips
1.9 b tree
Network Forensics
Tpr star tree
Algorithm Introduction #18 B-Tree
Лекция 5: B-деревья (B-trees, k-way merge sort)
floor planning
CAD: introduction to floorplanning
Examining Mac File Structures
17. Trees and Graphs
Ad

Similar to B-link-tree (20)

PDF
インターン講義8日目「データ構造」
PPTX
平衡二分探索木の並行化
PDF
プログラミングコンテストでのデータ構造 2 ~動的木編~
PPT
Lockfree Priority Queue
PDF
SIGMOD’12勉強会 -Session 7-
PPTX
冬のLock free祭り safe
PDF
20110517 okuyama ソーシャルメディアが育てた技術勉強会
PDF
Nazoki
PDF
kibayos_ov_090922
PDF
プログラミングコンテストでのデータ構造 2 ~平衡二分探索木編~
PPTX
1.2新機能と1.2から始めるcql3
PDF
マーク&スイープ勉強会
PPT
アルゴリズムとデータ構造7
PDF
Streaming data processing ライブラリの紹介 (主に Conduit)
PDF
skiplist&overlay-111030
PDF
B-Treeのアーキテクチャ解説 (第49回PostgreSQLアンカンファレンス@東京 発表資料)
PDF
Kvs okuyama-20110818
PDF
データを工夫して記録するデータ構造
PDF
Boost.B-tree introduction
インターン講義8日目「データ構造」
平衡二分探索木の並行化
プログラミングコンテストでのデータ構造 2 ~動的木編~
Lockfree Priority Queue
SIGMOD’12勉強会 -Session 7-
冬のLock free祭り safe
20110517 okuyama ソーシャルメディアが育てた技術勉強会
Nazoki
kibayos_ov_090922
プログラミングコンテストでのデータ構造 2 ~平衡二分探索木編~
1.2新機能と1.2から始めるcql3
マーク&スイープ勉強会
アルゴリズムとデータ構造7
Streaming data processing ライブラリの紹介 (主に Conduit)
skiplist&overlay-111030
B-Treeのアーキテクチャ解説 (第49回PostgreSQLアンカンファレンス@東京 発表資料)
Kvs okuyama-20110818
データを工夫して記録するデータ構造
Boost.B-tree introduction

More from Makoto Yui (20)

PDF
Apache Hivemall and my OSS experience
PDF
Introduction to Apache Hivemall v0.5.2 and v0.6
PDF
Introduction to Apache Hivemall v0.5.0
PDF
Idea behind Apache Hivemall
PDF
Introduction to Apache Hivemall v0.5.0
PDF
What's new in Hivemall v0.5.0
PDF
What's new in Apache Hivemall v0.5.0
PDF
Revisiting b+-trees
PDF
Incubating Apache Hivemall
PDF
Hivemall meets Digdag @Hackertackle 2018-02-17
PDF
Apache Hivemall @ Apache BigData '17, Miami
PDF
機械学習のデータ並列処理@第7回BDI研究会
PDF
Podling Hivemall in the Apache Incubator
PDF
Dots20161029 myui
PDF
Hadoopsummit16 myui
PDF
HadoopCon'16, Taipei @myui
PDF
3rd Hivemall meetup
PDF
Recommendation 101 using Hivemall
PDF
Hivemall dbtechshowcase 20160713 #dbts2016
PDF
Introduction to Hivemall
Apache Hivemall and my OSS experience
Introduction to Apache Hivemall v0.5.2 and v0.6
Introduction to Apache Hivemall v0.5.0
Idea behind Apache Hivemall
Introduction to Apache Hivemall v0.5.0
What's new in Hivemall v0.5.0
What's new in Apache Hivemall v0.5.0
Revisiting b+-trees
Incubating Apache Hivemall
Hivemall meets Digdag @Hackertackle 2018-02-17
Apache Hivemall @ Apache BigData '17, Miami
機械学習のデータ並列処理@第7回BDI研究会
Podling Hivemall in the Apache Incubator
Dots20161029 myui
Hadoopsummit16 myui
HadoopCon'16, Taipei @myui
3rd Hivemall meetup
Recommendation 101 using Hivemall
Hivemall dbtechshowcase 20160713 #dbts2016
Introduction to Hivemall

B-link-tree

  • 1. LENMAN-YAO concurrent B-Tree (a.k.a B-Link-Tree) 油井 誠 (Makoto YUI)
  • 3. B-Link Tree とは (history) A variant of B*-Tree (they call) actually.. a B+-tree? (data stored in leaf only) 1981 年 PHILIP.L. LEHMAN , S.BING YAO ” Efficient Locking for Concurrent Operations on B-Trees ” という論文で発表 当時,複数の プロセス で同時実効性を持つデータベースの構築が流行りだった ( らしい 論文の主眼は如何に効率のよく高い同時実効性を有する索引を構築するか.
  • 4. B*-Tree an elegant(?) variant on B+-tree keep pages at least 2/3 full, guaranteed . The benefit over B+-trees is not large, a worst case reduction in page usage of 16.67% メモリが安く早くなりつつあるので、メモリスペースを節約するアルゴリズムから脱却すべきではないだろうか. 沢山のメモリを利用することで、レイテンシーが問題がなることがある.よりエレガントなアルゴリズムが必要になってくる. これは既に、バスのキャパシティを CPU スピードが追い越すことで起こっていることである. http://www.cise.ufl.edu/~jhammer/classes/b_star.html
  • 5. B-Link-Tree (Key issue) No Read-Lock !! 複数のプロセスが同時に更新した場合に,少数のノードをロックする ロックの競合は稀である ロックの粒度が高く,開放が早い (non-2PL) ロック自体は update 時に Binary Lock (simple) デッドロックはないが,分散システムを考えるとよくないかも (? Additional Value to B*-Tree right-link , high key Breadth-first search (横型探索 ) が可能 . ノードにたどり着く Alternative way が存在する . Tree traversing operation search: top-down, left-to-right insert: bottom-up
  • 6. デッドロック ( 待ちグラフ ) T2 T1 T3 2 層ロック ( トランザクション内で処理する オブジェクトを順にロックする ) では, 巡回経路ができ,デッドロックが発生する. 巡回閉路
  • 7. B-link-Tree Structure (a) Leaf( 実際のデータへのポインタを有す ) への 距離は一定 (of course, well balanced) (b) 各ノードは基本的に 最低 K+1 の子 ( への pointer) を 持つ ただし、 Root は常に最低 2 つの子を持つ (c) 各ノードは 最高 2k+1(exclude High-Key) の子を 持つ “ High-key ” と呼ばれる追加エントリを持つこともある (+1) (d) key は leaf ノードに存在 key はデータベースのレコードへのポインタを有す . ( 各レコードがキーと関連付けられている )
  • 8. B*-Tree Node Structure (with no “ high key ” ) Internal use only.
  • 10. P i は Subtree T i を指す  T i に含まれるキー値は K i-1 < v <= K i Leaf と non-leaf ノードの構造が同一 ( シンプル ) M は Leaf であることを識別する Marker
  • 11. High-key ノードが溢れる時 (Split) ,ノードの右端に付加される Rightmost-link を辿る時に使われる.
  • 12. Set (51, 74) High-Key
  • 13. 更新時の処理 (basis) x: 物理ページ (Logical ノードと呼んでいる ) Lock(x); // ページ X を更新する際にマーキング // もし既にロックされていたら wait() A <- get(x); // Disk からメモリに読み込む Modify data in A // メモリ内の A を更新 Put(A, x) // メモリから Disk の sync Unlock(x); // ロックを解除
  • 14. Native approach ロックする必要がある. (read rock) Top-Down locking. 操作ノード下子孫をロック 15 の探索中に 9 が Insert され, Split されたケース Wait
  • 15. Rightmost-link B-link-Tree は各ノードに Single Link Pointer を持つ. 各レベルが単方向リスト . 目的 目的のノードに到達するための Alternative way を提供する どのノードもたどり着く為の 2 つの Pointer を持つ Overflow Replaced by two New node. (usually, the two nodes Are on the same physical page) Essentially same as A single node until the Parent pointer is added.
  • 16. Use high-key 74 74 63 HighKey HighKey Split 直後 ( 親へのリンクポインタが修正されていない ) 72 を探すケースを考えてみる. ここの中に High Key があるはずだが, Split されてない. この時, Link Pointer を辿る必要がある. この条件を High-Key と Search Key の比較によって行う. Search key が High key 以上ならポインタを辿る
  • 17. An structure example of B-link-Tree Additional advantage: level-major order での取得が早い (Leaf をすべて取得する場合など )
  • 18. Search Algorithm current = root; /* root の pointer を設定 */ A = get(current); /* ノードを memory に読み込む */ while (current is not a leaf) /* leaf に到達するまでループ */ current = scannode1(v, A); /* v をキーに memory bloak A を走査 */ /* リンクポインタを返す */ A = get(current); /* リンク先のノード読み込み */ / * now reached to leaves * / * leaf 内の線形探索 */ while ((t = scannode(v,A)) == link pointer of A) current = t; A = get(current); // 値 v を持つ leaf が見つかったか ? if (v is in A) return(success); else return(failure); Simple! Only trick is to have scannode know about high-keys and right-links. Right-link か Child-link かは 問わない
  • 19. Insert Algorithm 基本的に , Search と似たような下準備をする. Step 1. 木を辿ってキー値 v を含む (should include) リーフノードを探す. その際, Rightmost-link をスタックに積む. Step2. “ remembered list ” ( 辿ってきた道 ) を辿って,実際の挿入 Bottom-up insert .
  • 20. Insert(1) initialize stack; /* to remember ancestors */ current = root; A = get(current); /* scan down the tree */ while (current is not a leaf) { t = current; current = scannode(v,A); if (current not link pointer in A) push t; /* remember node at the level */ A = get(current); } /* reached to leaf */ lock(current); A = get(current); move_right(); /* if required, move right and lock the neighbor */
  • 21. // current node の update. // Split Node // for locking.. Remember the oldnode and the parent. // lock parent, oldnode, and the next-sibling.
  • 22. A B C D E F G H splited A Bottom-up Stack (right-most-link) B E Leaf Found G
  • 23. D E G H Leaf A Bottom-up Stack (right-most-link) B E If need to Split Flush Flush B Lock Flush Un Lock Finish! G I ’ G’ I ’ G’ E E
  • 24. P A C Leaf Insert algorithm(Write lock / no read lock) B ’ A ’ P Bottom-up Stack Insert(Split) A ’ Flush Lock A B ’ Flush
  • 25. Delete Too simple (leaf のエントリが K 以下なら,この論文は primary index を前提 ) Just remove keys from a leaf node. (never do deletion from internal nodes) Delete が続くとノードのエントリが k エントリ以下に なることがある. (starvation?)
  • 26. problems Livelock multiprocesser system, where one process runs indenfinitely ( 特に processing speed に差がある時 ) Following link pointer が別プロセスで作られると極端に遅くなることがある