Extended the node checker a bit.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13944 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
* Roughly based on 'btlib' written by Marcus J. Ranum - it shares
|
* Roughly based on 'btlib' written by Marcus J. Ranum - it shares
|
||||||
* no code but achieves binary compatibility with the on disk format.
|
* no code but achieves binary compatibility with the on disk format.
|
||||||
*
|
*
|
||||||
* Copyright 2001-2004, Axel Dörfler, [email protected].
|
* Copyright 2001-2005, Axel Dörfler, [email protected].
|
||||||
* This file may be used under the terms of the MIT License.
|
* This file may be used under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -25,21 +25,31 @@
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
class NodeChecker {
|
class NodeChecker {
|
||||||
public:
|
public:
|
||||||
NodeChecker(bplustree_node *node, int32 nodeSize)
|
NodeChecker(bplustree_node *node, int32 nodeSize, const char *text)
|
||||||
:
|
:
|
||||||
fNode(node),
|
fNode(node),
|
||||||
fSize(nodeSize)
|
fSize(nodeSize),
|
||||||
|
fText(text)
|
||||||
{
|
{
|
||||||
|
Check("integrity check failed on construction.");
|
||||||
}
|
}
|
||||||
|
|
||||||
~NodeChecker()
|
~NodeChecker()
|
||||||
{
|
{
|
||||||
fNode->CheckIntegrity(fSize);
|
Check("integrity check failed on destruction.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Check(const char *message)
|
||||||
|
{
|
||||||
|
if (fNode->CheckIntegrity(fSize) < B_OK)
|
||||||
|
dprintf("%s: %s\n", fText, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bplustree_node *fNode;
|
bplustree_node *fNode;
|
||||||
int32 fSize;
|
int32 fSize;
|
||||||
|
const char *fText;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -592,6 +602,10 @@ status_t
|
|||||||
BPlusTree::FindKey(bplustree_node *node, const uint8 *key, uint16 keyLength,
|
BPlusTree::FindKey(bplustree_node *node, const uint8 *key, uint16 keyLength,
|
||||||
uint16 *_index, off_t *_next)
|
uint16 *_index, off_t *_next)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
NodeChecker checker(node, fNodeSize, "find");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (node->all_key_count == 0) {
|
if (node->all_key_count == 0) {
|
||||||
if (_index)
|
if (_index)
|
||||||
*_index = 0;
|
*_index = 0;
|
||||||
@@ -1166,7 +1180,7 @@ BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength,
|
|||||||
CachedNode cached(this);
|
CachedNode cached(this);
|
||||||
while (stack.Pop(&nodeAndKey) && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) {
|
while (stack.Pop(&nodeAndKey) && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
NodeChecker checker(node, fNodeSize);
|
NodeChecker checker(node, fNodeSize, "insert");
|
||||||
#endif
|
#endif
|
||||||
if (node->IsLeaf()) {
|
if (node->IsLeaf()) {
|
||||||
// first round, check for duplicate entries
|
// first round, check for duplicate entries
|
||||||
@@ -1230,6 +1244,10 @@ BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength,
|
|||||||
|
|
||||||
RETURN_ERROR(B_ERROR);
|
RETURN_ERROR(B_ERROR);
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
checker.Check("insert split");
|
||||||
|
NodeChecker otherChecker(other, fNodeSize, "insert split other");
|
||||||
|
#endif
|
||||||
|
|
||||||
UpdateIterators(nodeAndKey.nodeOffset, otherOffset, nodeAndKey.keyIndex,
|
UpdateIterators(nodeAndKey.nodeOffset, otherOffset, nodeAndKey.keyIndex,
|
||||||
node->NumKeys(), 1);
|
node->NumKeys(), 1);
|
||||||
@@ -1518,7 +1536,7 @@ BPlusTree::Remove(Transaction &transaction, const uint8 *key, uint16 keyLength,
|
|||||||
CachedNode cached(this);
|
CachedNode cached(this);
|
||||||
while (stack.Pop(&nodeAndKey) && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) {
|
while (stack.Pop(&nodeAndKey) && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
NodeChecker checker(node, fNodeSize);
|
NodeChecker checker(node, fNodeSize, "remove");
|
||||||
#endif
|
#endif
|
||||||
if (node->IsLeaf()) {
|
if (node->IsLeaf()) {
|
||||||
// first round, check for duplicate entries
|
// first round, check for duplicate entries
|
||||||
@@ -2088,7 +2106,7 @@ bplustree_node::FragmentsUsed(uint32 nodeSize)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
void
|
status_t
|
||||||
bplustree_node::CheckIntegrity(uint32 nodeSize)
|
bplustree_node::CheckIntegrity(uint32 nodeSize)
|
||||||
{
|
{
|
||||||
if (NumKeys() > nodeSize || AllKeyLength() > nodeSize)
|
if (NumKeys() > nodeSize || AllKeyLength() > nodeSize)
|
||||||
@@ -2098,9 +2116,18 @@ bplustree_node::CheckIntegrity(uint32 nodeSize)
|
|||||||
uint16 length;
|
uint16 length;
|
||||||
uint8 *key = KeyAt(i, &length);
|
uint8 *key = KeyAt(i, &length);
|
||||||
if (key + length + sizeof(off_t) + sizeof(uint16) > (uint8 *)this + nodeSize
|
if (key + length + sizeof(off_t) + sizeof(uint16) > (uint8 *)this + nodeSize
|
||||||
|| length > BPLUSTREE_MAX_KEY_LENGTH)
|
|| length > BPLUSTREE_MAX_KEY_LENGTH) {
|
||||||
|
dprintf("node %p, key %ld\n", this, i);
|
||||||
DEBUGGER(("invalid node: keys corrupted"));
|
DEBUGGER(("invalid node: keys corrupted"));
|
||||||
|
return B_BAD_DATA;
|
||||||
}
|
}
|
||||||
|
if (Values()[i] == -1) {
|
||||||
|
dprintf("node %p, value %ld: %Ld\n", this, i, Values()[i]);
|
||||||
|
DEBUGGER(("invalid node: values corrupted"));
|
||||||
|
return B_BAD_DATA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Roughly based on 'btlib' written by Marcus J. Ranum - it shares
|
* Roughly based on 'btlib' written by Marcus J. Ranum - it shares
|
||||||
* no code but achieves binary compatibility with the on disk format.
|
* no code but achieves binary compatibility with the on disk format.
|
||||||
*
|
*
|
||||||
* Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de.
|
* Copyright 2001-2005, Axel Dörfler, axeld@pinc-software.de.
|
||||||
* This file may be used under the terms of the MIT License.
|
* This file may be used under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef B_PLUS_TREE_H
|
#ifndef B_PLUS_TREE_H
|
||||||
@@ -98,7 +98,7 @@ struct bplustree_node {
|
|||||||
static inline uint32 FragmentIndex(off_t link);
|
static inline uint32 FragmentIndex(off_t link);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
void CheckIntegrity(uint32 nodeSize);
|
status_t CheckIntegrity(uint32 nodeSize);
|
||||||
#endif
|
#endif
|
||||||
} _PACKED;
|
} _PACKED;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user