balanced binary search tree
play

Balanced Binary Search Tree Dana Drachsler, Technion, Israel Joint - PowerPoint PPT Presentation

Verification-Friendly Concurrent Balanced Binary Search Tree Dana Drachsler, Technion, Israel Joint work with: Martin Vechev, ETH, Switzerland Eran Yahav, Technion, Israel 2 Motivation Balanced Binary Search Tree (BST) is an efficient


  1. Verification-Friendly Concurrent Balanced Binary Search Tree Dana Drachsler, Technion, Israel Joint work with: Martin Vechev, ETH, Switzerland Eran Yahav, Technion, Israel

  2. 2 Motivation • Balanced Binary Search Tree (BST) is an efficient data-structure for storing unique elements ▫ No repetitions are allowed • Formal verification: ▫ Given a program, prove some property ▫ In the tree:  prove that repetitions of elements cannot occur

  3. 3 Motivation • Formal verification was applied to the sequential algorithm (e.g. using Isabelle [6]) • However, in a concurrent setting, formal verification is more complicated

  4. 4 Motivation • There seems to be a trade-off between algorithms that are easy to verify and algorithms that are practical • A concurrent BST that is protected by a global lock is easy to verify • Practical concurrent trees use sophisticated mechanisms ▫ Many different cases to reason about ▫ Harder to verify

  5. 5 Goal • We gap this trade-off by presenting a concurrent BST that is both practical and simple to reason about • Our key idea: ▫ Integrate the property into the algorithm • We achieve a fine-grained locking balanced BST • Our tree is very similar to the sequential tree • Our mechanism allows breaking the proof into several separated proofs

  6. 6 Outline Binary Search Balanced Binary Tree Search Tree Concurrent Concurrent Binary Balanced Binary Search Tree Search Tree

  7. 7 Binary Search Tree • A data-structure that stores elements • Consists of nodes 6 • Each node represents an element ▫ Internal tree 3 12 • Each element has a unique key ▫ Repetitions are not allowed 24 • Each node in the tree holds: ▫ The left sub-tree has elements with smaller keys ▫ The right sub-tree has elements with bigger keys

  8. 8 Binary Search Tree • In other words, BST maintains two types of invariants: ▫ Set invariant  Each key appears at most once ▫ BST invariants  For each node:  The keys in the left sub-tree are smaller  The keys in the right sub-tree are bigger

  9. 9 Binary Search Tree 24? • Supports the following operations: ▫ Contains 6 3 12 24

  10. 9 Binary Search Tree • Supports the following operations: ▫ Contains 6 3 12 24? 24

  11. 10 Binary Search Tree • Supports the following operations: ▫ Insert 6  The new node is always a leaf 3 12 24 9 24

  12. 10 Binary Search Tree • Supports the following operations: ▫ Insert 6  The new node is always a leaf 3 12 24 9

  13. 11 Binary Search Tree • Supports the following operations: ▫ Remove 6  The removed node, 𝑜 , may be:  A leaf  3 12 24 9

  14. 11 Binary Search Tree • Supports the following operations: ▫ Remove 6  The removed node, 𝑜 , may be:  A leaf 3 12 24

  15. 11 Binary Search Tree • Supports the following operations: ▫ Remove 6  The removed node, 𝑜 , may be:  A leaf  A parent of a single child 3 12 ▫ 𝑜 ’s parent is connected to 𝑜 ’s child 24 9 10

  16. 11 Binary Search Tree • Supports the following operations: ▫ Remove 6  The removed node, 𝑜 , may be:  A leaf  A parent of a single child 3 12 ▫ 𝑜 ’s parent is connected to 𝑜 ’s child 24 10

  17. 11 Binary Search Tree • Supports the following operations: ▫ Remove 6  The removed node, 𝑜 , may be:  A leaf  A parent of a single child 3 12 ▫ 𝑜 ’s parent is connected to 𝑜 ’s child  A parent of two children 24 10 ▫ 𝑜 ’s successor is relocated to 𝑜 ’s location

  18. 11 Binary Search Tree • Supports the following operations: ▫ Remove 10  The removed node, 𝑜 , may be:  A leaf  A parent of a single child 3 12 ▫ 𝑜 ’s parent is connected to 𝑜 ’s child  A parent of two children 24 ▫ 𝑜 ’s successor is relocated to 𝑜 ’s location

  19. 12 Outline Balanced Binary Search Tree Concurrent Concurrent Binary Balanced Binary Search Tree Search Tree

  20. 13 Challenges in Concurrent BST 9? • Consider the following tree: ▫ Thread A searches for 9 6 3 12 9

  21. 13 Challenges in Concurrent BST • Consider the following tree: ▫ Thread A searches for 9 6 and pauses 9? 3 12 9

  22. 13 Challenges in Concurrent BST • Consider the following tree: ▫ Thread A searches for 9 6 and pauses 9? ▫ Thread B removes 6 3 12 9

  23. 13 Challenges in Concurrent BST • Consider the following tree: ▫ Thread A searches for 9 9 and pauses 9? ▫ Thread B removes 6 3 12

  24. 13 Challenges in Concurrent BST • Consider the following tree: ▫ Thread A searches for 9 9 and pauses 9? ▫ Thread B removes 6 3 12 ▫ Thread A resumes the search

  25. 13 Challenges in Concurrent BST • Consider the following tree: ▫ Thread A searches for 9 9 and pauses ▫ Thread B removes 6 3 12 ▫ Thread A resumes the search and observes that 9 is not present 9?

  26. 14 How do others cope with this challenge? • By not supporting the remove operation ▫ Bender et al. [1]

  27. 15 How do others cope with this challenge? • By using external trees ▫ Only leaves can be removed 3 ▫ Use more space than internal trees ▫ Ellen et al. [4] 3 9 24 9

  28. 16 How do others cope with this challenge? • Many concurrent algorithms for data-structures remove elements in two steps: ▫ Marking the node as logically removed 6 3 12

  29. 16 How do others cope with this challenge? • Many concurrent algorithms for data-structures remove elements in two steps: ▫ Marking the node as logically removed 6 ▫ Update pointers to physically remove the node 3 12

  30. 17 How do others cope with this challenge? • By marking the node as removed without A: physically removing it contains(9) 9? ▫ Also known as partially-external trees ▫ Bronson et al. [2] 6 ▫ Crain et al. [3] 3 12 9

  31. 17 How do others cope with this challenge? • By marking the node as removed without A: physically removing it contains(9) ▫ Also known as partially-external trees ▫ Bronson et al. [2] 6 ▫ Crain et al. [3] 9? 3 12 9

  32. 17 How do others cope with this challenge? • By marking the node as removed without A: physically removing it contains(9) ▫ Also known as partially-external trees B: ▫ Bronson et al. [2] remove(6) ▫ Crain et al. [3] 9? 3 12 9

  33. 17 How do others cope with this challenge? • By marking the node as removed without A: physically removing it contains(9) ▫ Also known as partially-external trees B: ▫ Bronson et al. [2] remove(6) ▫ Crain et al. [3] 3 12 9? 9

  34. 18 How do others cope with this challenge? • By marking the node as removed without A: physically removing it contains(9) 9? ▫ Howley et al. [5] 6 3 12 9

  35. 18 How do others cope with this challenge? • By marking the node as removed without A: physically removing it contains(9) ▫ Howley et al. [5] 6 9? 3 12 9

  36. 18 How do others cope with this challenge? • By marking the node as removed without A: physically removing it contains(9) ▫ Howley et al. [5] B: remove(6) 6 9 9? 3 12

  37. 18 How do others cope with this challenge? • By marking the node as removed without A: physically removing it contains(9) ▫ Howley et al. [5] B: remove(6) 6 9 3 12 9?

  38. 19 How do others cope with this challenge? • These solutions leave removed nodes in the tree • Is it possible to physically remove nodes? • Trivial solution: use global lock 6 3 12 9

  39. 19 How do others cope with this challenge? • These solutions leave removed nodes in the tree • Is it possible to physically remove nodes? • Trivial solution: use global lock • Observation: To determine 6 7? whether 𝑙 is in the tree it is enough to have 𝑞, 𝑡 such that: 3 12 ▫ 𝑞, 𝑡 belong to the tree ▫ Any 𝑥 ∈ 𝑞, 𝑡 is not in the tree 9

  40. 20 Our Approach • Maintain the predecessor-successor relation ▫ The set layout • Consult this relation before making final decisions 6 3 12 9

  41. 20 Our Approach • Maintain the predecessor-successor relation A: ▫ The set layout contains(9) 9? • Consult this relation before making final decisions 6 3 12 9

  42. 20 Our Approach • Maintain the predecessor-successor relation A: ▫ The set layout contains(9) • Consult this relation before making final decisions 6 9? 3 12 9

  43. 20 Our Approach • Maintain the predecessor-successor relation A: ▫ The set layout contains(9) • Consult this relation before B: making final decisions remove(6) 9 9? 3 12

  44. 20 Our Approach • Maintain the predecessor-successor relation A: ▫ The set layout contains(9) • Consult this relation before B: making final decisions remove(6) 9 3 12 9?

  45. 20 Our Approach • Maintain the predecessor-successor relation A: ▫ The set layout contains(9) • Consult this relation before B: making final decisions remove(6) 9 9? 3 12

  46. 20 Our Approach • Maintain the predecessor-successor relation A: ▫ The set layout contains(9) • Consult this relation before B: making final decisions remove(6) 9 9? • This relation allows us to lock the required nodes even if they 3 12 are not adjacent ▫ Enjoy the benefits of the global lock ▫ While enabling more parallelism

Recommend


More recommend