Beispiel #1
0
static int join_leaf (
	tree_s 		*tree,
	branch_s	*parent,
	leaf_s		*child,
	int		k)
{
	leaf_s	*sibling;

	sibling = bget(tree->t_dev, parent->br_key[k+1].k_block);
	if (!sibling) return qERR_NOT_FOUND;

	if (child->l_total + sibling->l_total > MAX_FREE) {
FN;
		compact(child);
		compact(sibling);
		copy_recs(child, sibling, 0);
		memmove( &parent->br_key[k+1], &parent->br_key[k+2],
			sizeof(parent->br_key[0]) * (parent->br_num - (k+2)));
		--parent->br_num;
		bdirty(parent);
	}
	//verify_leaf(child, WHERE);
	bput(sibling);	// Should free sibling
	return 0;
}
Beispiel #2
0
bool split_leaf (void *self, branch_s *parent, int k, unint len)
{
	leaf_s	*child = self;
	leaf_s	*sibling;
	int	upper;
	u64	upper_key;
FN;
	if (!leaf_is_full(child, len)) {
		return FALSE;
	}
	sibling = new_leaf(bdev(parent));

	upper = (child->l_num + 1) / 2;
	upper_key = child->l_rec[upper].r_key;

	copy_recs(sibling, child, upper);

	child->l_num = upper;
	child->l_total += (BLK_SIZE - sizeof(leaf_s)) - sibling->l_total;
	bdirty(child);
	bput(child);

	insert_sibling(parent, sibling, k, upper_key);
	bput(sibling);
	return TRUE;
}
Beispiel #3
0
static bool split_leaf (tree_s *tree, leaf_s *child, branch_s *parent, s64 k, unint size)
{
	leaf_s	*sibling;
	snint	upper;
	u64	upper_key;

	if (!leaf_is_full(child, size)) {
		return FALSE;
	}
FN;
	sibling = new_leaf(tree);

	upper = (child->l_num + 1) / 2;
	upper_key = child->l_rec[upper].r_key;

	copy_recs(sibling, child, upper);

	child->l_num = upper;
	child->l_total += (BLK_SIZE - sizeof(leaf_s)) - sibling->l_total;
	tau_blog(child);
	tau_bput(child);

	insert_sibling(parent, sibling, k, upper_key);
	tau_bput(sibling);
	return TRUE;
}
Beispiel #4
0
static int join_leaf (tree_s *tree, branch_s *parent, leaf_s *child, snint k)
{
    leaf_s		*sibling;

    sibling = parent->br_key[k+1].k_node;
    if (!sibling) return qERR_NOT_FOUND;

    if (child->l_total + sibling->l_total > MAX_FREE) {
        compact(child);
        copy_recs(child, sibling, 0);
        memmove( &parent->br_key[k+1], &parent->br_key[k+2],
                 sizeof(parent->br_key[0]) * (parent->br_num - (k+2)));
        --parent->br_num;
    }
    return 0;
}
Beispiel #5
0
void compact (leaf_s *leaf)
{
	static char	block[BLK_SIZE];
	leaf_s		*p;
FN;
	// Need a spin lock here
	p = (leaf_s *)block;
	bzero(p, BLK_SIZE);
	p->l_type = leaf->l_type;
	p->l_end  = BLK_SIZE;
	p->l_total = MAX_FREE;

	copy_recs(p, leaf, 0);
	memmove(leaf, p, BLK_SIZE);
	aver(leaf->l_total == free_space(leaf));
	bdirty(leaf);
}
Beispiel #6
0
static void compact (leaf_s *leaf)
{
    static char	block[PAGE_SIZE];
    leaf_s		*p;
    FN;
    // Need a spin lock here
    p = (leaf_s *)block;
    memset(p, 0, PAGE_SIZE);

    p->h_node = leaf->h_node;
    p->h_magic  = leaf->h_magic;
    p->l_end    = PAGE_SIZE;
    p->l_total  = MAX_FREE;

    copy_recs(p, leaf, 0);
    memmove(leaf, p, PAGE_SIZE);
    aver(leaf->l_total == free_space(leaf));
}
Beispiel #7
0
static void compact (leaf_s *leaf)
{
	static char	block[BLK_SIZE];
	leaf_s		*p;
FN;
	// Need a spin lock here
	p = (leaf_s *)block;
	memset(p, 0, BLK_SIZE);

	p->h_blknum = leaf->h_blknum;
	p->h_magic  = leaf->h_magic;
	p->l_end    = BLK_SIZE;
	p->l_total  = MAX_FREE;

	copy_recs(p, leaf, 0);
	memmove(leaf, p, BLK_SIZE);
	assert(leaf->l_total == free_space(leaf));
	tau_blog(leaf);
}
Beispiel #8
0
static int join_leaf (tree_s *tree, branch_s *parent, leaf_s *child, snint k)
{
	leaf_s		*sibling;

	sibling = tau_bget(tree_inode(tree), parent->br_key[k+1].k_block);
	if (!sibling) return qERR_NOT_FOUND;

	if (child->l_total + sibling->l_total > MAX_FREE) {
HERE;
		compact(child);
		copy_recs(child, sibling, 0);
		tau_blog(child);
		memmove( &parent->br_key[k+1], &parent->br_key[k+2],
			sizeof(parent->br_key[0]) * (parent->br_num - (k+2)));
		--parent->br_num;
		tau_blog(parent);
		tau_blog(sibling);
	}
	tau_bput(sibling);	//XXX: Should free sibling
	return 0;
}