Philip L. Lehman and S. Bing Yao
CMU and Purdue University
lock(x) A = get(x) // read x in A from disk modify A put(A, x) // "atomic" rewrite of A to disk unlock(x)
| search(15) | insert(9) |
|---|---|
| C ← read(x) | |
| A ← read(x) | |
| examine C; get ptr to y | |
| examine A; get ptr to y | |
| A ← read(y) | |
| insert 9 into A; must split into A, B | |
| put(B, y') | |
| put(A, y) | |
| Add to node x a pointer to node y'. | |
| C ← read(y) | |
| error: 15 not found! |
current = root;
A = get(current);
while (current is not a leaf) {
current = scanNode(v, A);
A = get(current);
}
while ((t = scanNode(v, A)) == link pointer) {
current = t;
A = get(current);
}
if (v is in A)
success
else
failure
initialize stack;
current = root;
A = get(current);
while (current is not a leaf) {
t = current;
current = scanNode(v, A);
if (current not link pointer in A)
push(t);
A = get(current);
}
lock(current);
A = get(current);
move.right();
if (v in A)
stop "exist";
w ← pointer to pages allocated for record associated with v;
DoInsertion:
if A is safe {
insert new key/ptr pair on A;
put(A, current);
unlock(current);
} else { // split
u = allocate new page for B;
redistribute A over A & B;
y = max value on A now;
make high key of B equal old high key of A;
make right link of B equal old right link of A;
make high key of A equal y;
make right link of A point to B;
put(B, u);
put(A, current);
oldNode = current;
new key/pointer pair = (y, u);
current = pop(stack);
lock(current);
A = get(current);
move.right(); // might hold three locks here
unlock(oldNode);
goto DoInsertion;
}
while ((t = scanNode(v, A)) is a link pointer of A) {
lock(t);
unlock(current);
current = t;
A = get(current);
}