mehdi kargar department of computer science and engineering 1

18
Mehdi Kargar Department of Computer Science and Engineering 1

Upload: lillian-short

Post on 31-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Mehdi Kargar

Department of Computer Science and Engineering

1

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

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

1. The Monitor Solution2. The Readers-Writers Solution3. Locking Nodes (RLink-Tree)

5

public class MonitorRTree {

public synchronized void add(Rectangle rect) {

.

.

.}

public synchronized boolean search(Rectangle rect){

.

.

.}

}

6

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

Basic idea :◦ Logical Serial Number (LSN) is used to capture

unfinished splits.◦ Right Links is used to follow the split nodes.

8

RLink-Tree uses the lock coupling strategy for inserting new entries.

The normal implementation of lock coupling leads to deadlocks.

x

ZY

Process 1Finding the best node for inserting new entriesRead-Lock the nodes in a top-down approach

Process 2After 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

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

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

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

14

15

Having multiple insertion process without locking the root.

Finding better solution for phantom problem.

. . .

16

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

17

18