long value,
boolean isOverride,
Block block)
throws IOException, SQLException
{
Lock blockLock = block.getLock();
blockLock.lockReadAndWrite(_timeout);
try {
block.read();
validate(block);
long blockId = block.getBlockId();
byte []buffer = block.getBuffer();
int length = getLength(buffer);
if (length == _n) {
// return false if the block needs to be split
return false;
}
if (isLeaf(buffer, block)) {
insertValue(keyBuffer, keyOffset, keyLength,
value, isOverride, block);
validate(block);
return true;
}
long childBlockId = lookupTuple(blockId, buffer,
keyBuffer, keyOffset, keyLength,
false);
while (! insert(keyBuffer, keyOffset, keyLength,
value, isOverride, true,
childBlockId)) {
split(block, childBlockId);
childBlockId = lookupTuple(blockId, buffer,
keyBuffer, keyOffset, keyLength,
false);
}
validate(block);
return true;
} finally {
blockLock.unlockReadAndWrite();
}
}