* CachedNode::SetToWritable() already needs the updated header, so we need to

Unset() the header in Allocate() before calling it. This fixes bug #5410.
* CachedNode::Allocate() does not need to revert its changes; the transaction
  will take care of that. However, BPlusTree::fHeader is currently not correctly
  maintained if a transaction fails (working on that now).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35490 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-02-16 08:34:55 +00:00
parent 751e92fde1
commit 2a8ae7fb92
@@ -227,7 +227,7 @@ CachedNode::InternalSetTo(Transaction* transaction, off_t offset)
fWritable = false; fWritable = false;
} }
if (block) { if (block != NULL) {
// The node is somewhere in that block... // The node is somewhere in that block...
// (confusing offset calculation) // (confusing offset calculation)
fNode = (bplustree_node*)(block + offset fNode = (bplustree_node*)(block + offset
@@ -324,18 +324,17 @@ CachedNode::Allocate(Transaction& transaction, bplustree_node** _node,
header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(header->MaximumSize() header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(header->MaximumSize()
+ fTree->fNodeSize); + fTree->fNodeSize);
if (SetToWritable(transaction, offset, false) != NULL) { cached.Unset();
fNode->Initialize(); // SetToWritable() below needs the new values in the tree's header
*_offset = offset; if (SetToWritable(transaction, offset, false) == NULL)
*_node = fNode; RETURN_ERROR(B_ERROR);
return B_OK;
}
// revert header size to old value fNode->Initialize();
header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(header->MaximumSize()
- fTree->fNodeSize); *_offset = offset;
RETURN_ERROR(B_ERROR); *_node = fNode;
return B_OK;
} }
@@ -423,7 +422,7 @@ BPlusTree::SetTo(Transaction& transaction, Inode* stream, int32 nodeSize)
= HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL); = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL);
header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(nodeSize * 2); header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(nodeSize * 2);
memcpy(&fHeader, header, sizeof(bplustree_header)); cached.Unset();
// initialize b+tree root node // initialize b+tree root node
cached.SetToWritable(transaction, fHeader.RootNode(), false); cached.SetToWritable(transaction, fHeader.RootNode(), false);