Exemplo n.º 1
0
node_pointer* complete_new_btree(couchfile_modify_result* mr, couchstore_error_t *errcode)
{
    *errcode = flush_mr(mr);
    if(*errcode != COUCHSTORE_SUCCESS) {
        return NULL;
    }

    couchfile_modify_result* targ_mr = make_modres(mr->arena, mr->rq);
    if (!targ_mr) {
        *errcode = COUCHSTORE_ERROR_ALLOC_FAIL;
        return NULL;
    }
    targ_mr->modified = 1;
    targ_mr->node_type = KP_NODE;

    *errcode = mr_move_pointers(mr, targ_mr);
    if(*errcode != COUCHSTORE_SUCCESS) {
        return NULL;
    }

    node_pointer* ret_ptr;
    if(targ_mr->count > 1 || targ_mr->pointers != targ_mr->pointers_end) {
        ret_ptr = finish_root(mr->rq, targ_mr, errcode);
    } else {
        ret_ptr = targ_mr->values_end->pointer;
    }

    return copy_node_pointer(ret_ptr);
}
Exemplo n.º 2
0
couchfile_pointer_info* modify_btree(couchfile_modify_request *rq,
        couchfile_pointer_info *root, int *errcode)
{
    couchfile_pointer_info* ret_ptr = root;
    couchfile_modify_result* root_result = make_modres(rq);
    root_result->node_type = KP_NODE;
    *errcode = modify_node(rq, root, 0, rq->num_actions, root_result);
    if(*errcode < 0)
    {
        free_modres(root_result);
        return NULL;
    }

    if(root_result->values_end->value.pointer == root)
    {
        //If we got the root pointer back, remove it from the list
        //so we don't try to free it.
        root_result->values_end->value.mem = NULL;
    }

    if(!root_result->modified)
    {
        free_modres(root_result);
    }
    else
    {
        if(root_result->count > 1 || root_result->pointers != root_result->pointers_end)
        {
            //The root was split
            //Write it to disk and return the pointer to it.
            ret_ptr = finish_root(rq, root_result, errcode);
            if(*errcode < 0)
            {
                ret_ptr = NULL;
            }
        }
        else
        {
            ret_ptr = root_result->values_end->value.pointer;
            root_result->values_end->value.mem = NULL;
            free_modres(root_result);
        }
    }
    return ret_ptr;
}
Exemplo n.º 3
0
node_pointer *modify_btree(couchfile_modify_request *rq,
                           node_pointer *root,
                           couchstore_error_t *errcode)
{
    arena* a = new_arena(0);
    node_pointer *ret_ptr = root;
    couchfile_modify_result *root_result = make_modres(a, rq);
    if (!root_result) {
        delete_arena(a);
        *errcode = COUCHSTORE_ERROR_ALLOC_FAIL;
        return root;
    }
    root_result->node_type = KP_NODE;
    *errcode = modify_node(rq, root, 0, rq->num_actions, root_result);
    if (*errcode < 0) {
        delete_arena(a);
        return NULL;
    }

    if (root_result->values_end->pointer == root) {
        //If we got the root pointer back, remove it from the list
        //so we don't try to free it.
        root_result->values_end->pointer = NULL;
    }

    if (root_result->modified) {
        if (root_result->count > 1 || root_result->pointers != root_result->pointers_end) {
            //The root was split
            //Write it to disk and return the pointer to it.
            ret_ptr = finish_root(rq, root_result, errcode);
            if (*errcode < 0) {
                ret_ptr = NULL;
            }
        } else {
            ret_ptr = root_result->values_end->pointer;
        }
    }
    if (ret_ptr != root) {
        ret_ptr = copy_node_pointer(ret_ptr);
    }
    delete_arena(a);
    return ret_ptr;
}