Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mehdi Kargar Department of Computer Science and Engineering 1.

Similar presentations


Presentation on theme: "Mehdi Kargar Department of Computer Science and Engineering 1."— Presentation transcript:

1 Mehdi Kargar Department of Computer Science and Engineering 1

2  R-tree is useful for indexing and representing multidimensional objects.  An R-tree is a depth balanced tree with a dynamic index structure ◦ Leaf nodes point to actual keys ◦ The number of entries in a node is between m and N (1 < m ≤ N) ◦ Root might have between 1 and N entries. ◦ All leaf nodes are at the same level ◦ The key for each internal node is the minimum bounding rectangle of its child nodes ◦ keys at all levels might have overlap with each other 2

3 3

4  During the search for a key, it might be necessary to descend multiple sub-trees  Insertion is more complex than search ◦ After inserting a new key, the new bounding rectangle should be propagated up to the tree. ◦ If a node overflows, it should be split. The split should also be propagated up to the tree.  During the Insertion, only one sub-tree is traversed at each level. We should not descend multiple sub-trees. 4

5 1. The Monitor Solution 2. The Readers-Writers Solution 3. Locking Nodes (RLink-Tree) 5

6 public class MonitorRTree { public synchronized void add(Rectangle rect) {. } public synchronized boolean search(Rectangle rect) {. } 6

7 import java.util.concurrent.locks.ReentrantReadWriteLock; public class ReadWriteLockRTree { private ReentrantReadWriteLock lock;.... public void add(Rectangle rect) { this.lock.writeLock().lock();. this.lock.writeLock().unlock(); } public boolean search(Rectangle rect) { this.lock.readLock().lock();. this.lock.readLock().unlock(); } 7

8  Basic idea : ◦ Logical Serial Number (LSN) is used to capture unfinished splits. ◦ Right Links is used to follow the split nodes. 8

9  RLink-Tree uses the lock coupling strategy for inserting new entries.  The normal implementation of lock coupling leads to deadlocks. x ZY Process 1 Finding the best node for inserting new entries Read-Lock the nodes in a top-down approach Process 2 After Inserting new entry, the split and new bounding rectangle should be propagated Write-Lock the nodes in a bottom-up approach Write-Lock 2 1 Read-Lock 1 2 9

10  The previous situation is called phantom problem.  It can be solved by predicate locks.  What are predicate locks ??  You can find more about it here : ◦ K. Eswaren, J. Gray, R. Lorie and I. Traiger, On the Notions of Consistency and Predicate Locks in a Database System, Comm. ACM, November 1976, Vol. 19, No. 11, pp. 624– 633. 10

11  Here, the root node is kept write-lock for the insertion of new nodes. Thus, only one process can insert at any time and we do not have multiple insertions.  The LSN and right links are the same as the original RLink-Tree.  Search algorithm and the read-lock mechanism is also the same as RLink-Tree. 11

12 12 public synchronized void readLock() { while (this.state == WRITE) { try { this.wait(); } catch (InterruptedException e) {} } this.increment(); } public synchronized void readUnlock() { this.decrement(); this.notifyAll(); } public synchronized void writeLock() { while (this.readers != 0 || state == WRITE) { try { this.wait(); } catch (InterruptedException e) {} } this.state = WRITE; } public synchronized void writeUnlock() { this.state = READ; this.notifyAll(); }

13 13

14 14

15 15

16  Having multiple insertion process without locking the root.  Finding better solution for phantom problem. ... 16

17  Verifying the implementations using different applications and tools such as Java PathFinder 17

18 18


Download ppt "Mehdi Kargar Department of Computer Science and Engineering 1."

Similar presentations


Ads by Google