Skip to content

Commit

Permalink
organize trunk free blocks using AVL tree ok
Browse files Browse the repository at this point in the history
git-svn-id: http://fastdfs.googlecode.com/svn@971 0d4c4929-bc51-0410-a161-b7c81ae5c018
  • Loading branch information
happyfish100 committed Dec 25, 2011
1 parent c4760b5 commit cff6bf2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 5 additions & 6 deletions trunk/common/avl_tree.c
Expand Up @@ -48,7 +48,7 @@ static AVLTreeNode *createTreeNode(AVLTreeNode *pParentNode, void *target_data)
pNewNode = (AVLTreeNode *)malloc(sizeof(AVLTreeNode));
if (pNewNode == NULL)
{
printf("malloc fail!\n");
printf("malloc %d bytes fail!\n", (int)sizeof(AVLTreeNode));
return NULL;
}

Expand Down Expand Up @@ -87,7 +87,6 @@ static void avlLeftBalanceWhenInsert(AVLTreeNode **pTreeNode, int *taller)
*taller = 0;
break;
case 0 :
printf("树已经平衡化!!!!!!!\n");
break;
case 1 :
rightsub = leftsub->right;
Expand Down Expand Up @@ -127,7 +126,6 @@ static void avlRightBalanceWhenInsert(AVLTreeNode **pTreeNode, int *taller)
*taller = 0;
break;
case 0:
printf("树已经平衡化!!!!!!!\n");
break;
case -1:
leftsub = rightsub->left;
Expand Down Expand Up @@ -230,7 +228,7 @@ int avl_tree_insert(AVLTreeInfo *tree, void *data)

taller = 0;
return avl_tree_insert_loop(tree->compare_func, &(tree->root), \
data, &taller);
data, &taller);
}

static int avl_tree_replace_loop(CompareFunc compare_func, \
Expand Down Expand Up @@ -534,7 +532,7 @@ static void *avl_tree_delete_loop(CompareFunc compare_func, \
return pResultData;
}

nCompRes = -1; //在右分支中寻找直接前驱结点
nCompRes = -1;
}
else
{
Expand Down Expand Up @@ -604,7 +602,6 @@ static void *avl_tree_delete_loop(CompareFunc compare_func, \
}
else
{
//printf("find the prior.\n");
avl_tree_delete_loop(compare_func, \
&((*pCurrentNode)->left), target_data, \
shorter, *pCurrentNode);
Expand Down Expand Up @@ -661,6 +658,7 @@ static int avl_tree_walk_loop(DataOpFunc data_op_func, \
return result;
}

/*
if (pCurrentNode->balance >= -1 && pCurrentNode->balance <= 1)
{
//printf("==%d\n", pCurrentNode->balance);
Expand All @@ -669,6 +667,7 @@ static int avl_tree_walk_loop(DataOpFunc data_op_func, \
{
printf("==bad %d!!!!!!!!!!!!\n", pCurrentNode->balance);
}
*/

if (pCurrentNode->right != NULL)
{
Expand Down
13 changes: 11 additions & 2 deletions trunk/storage/trunk_mgr/trunk_mem.c
Expand Up @@ -146,7 +146,7 @@ int storage_trunk_init()
return result;
}

logInfo("tree node count: %d", avl_tree_count(&tree_info));
//logInfo("tree node count: %d", avl_tree_count(&tree_info));

return 0;
}
Expand Down Expand Up @@ -650,7 +650,16 @@ static int trunk_add_node(FDFSTrunkNode *pNode, const bool bWriteBinLog)
chain->size = pNode->trunk.file.size;
chain->head = pNode;

avl_tree_insert(&tree_info, chain);
if (avl_tree_insert(&tree_info, chain) != 1)
{
result = errno != 0 ? errno : ENOMEM;
logError("file: "__FILE__", line: %d, " \
"avl_tree_insert fail, " \
"errno: %d, error info: %s", \
__LINE__, result, STRERROR(result));
pthread_mutex_unlock(&trunk_mem_lock);
return result;
}
}
else
{
Expand Down

0 comments on commit cff6bf2

Please sign in to comment.