コード例 #1
0
static int get_common_objects(PyObject *cookie,
                              const void *key,
                              size_t nkey,
                              lcb_error_t err,
                              pycbc_ConnectionObject **conn,
                              pycbc_ResultBaseObject **res,
                              int restype,
                              pycbc_MultiResultObject **mres)

{
    PyObject *hkey;
    int rv;

    assert(Py_TYPE(cookie) == &pycbc_MultiResultType);
    *mres = (pycbc_MultiResultObject*)cookie;
    *conn = (*mres)->parent;

    CB_THR_END(*conn);

    rv = pycbc_tc_decode_key(*conn, key, nkey, &hkey);

    if (rv < 0) {
        push_fatal_error(*mres);
        return -1;
    }

    /**
     * Now, get/set the result object
     */
    if (restype == RESTYPE_BASE) {
        *res = (pycbc_ResultBaseObject*)pycbc_result_new(*conn);

    } else if (restype == RESTYPE_OPERATION) {
        *res = (pycbc_ResultBaseObject*)pycbc_opresult_new(*conn);

    } else if (restype == RESTYPE_VALUE) {
        *res = (pycbc_ResultBaseObject*)pycbc_valresult_new(*conn);

    } else {
        abort();
    }
    assert(PyDict_Contains((PyObject*)*mres, hkey) == 0);

    PyDict_SetItem((PyObject*)*mres, hkey, (PyObject*)*res);
    Py_DECREF(*res);

    (*res)->key = hkey;
    (*res)->rc = err;

    if (err != LCB_SUCCESS) {
        (*mres)->all_ok = 0;
    }

    return 0;
}
コード例 #2
0
static void
get_callback(lcb_t instance,
             const void *cookie,
             lcb_error_t err,
             const lcb_get_resp_t *resp)
{

    int rv;
    pycbc_Connection *conn = NULL;
    pycbc_ValueResult *res = NULL;
    pycbc_MultiResult *mres = NULL;
    lcb_uint32_t eflags;

    rv = get_common_objects((PyObject*)cookie,
                            resp->v.v0.key,
                            resp->v.v0.nkey,
                            err,
                            &conn,
                            (pycbc_Result**)&res,
                            RESTYPE_VALUE,
                            &mres);

    if (rv < 0) {
        CB_THR_BEGIN(conn);
        return;
    }

    res->flags = resp->v.v0.flags;
    res->cas = resp->v.v0.cas;

    maybe_push_operr(mres, (pycbc_Result*)res, err, 1);

    if (err != LCB_SUCCESS) {
        CB_THR_BEGIN(conn);
        return;
    }

    if (mres->mropts & PYCBC_MRES_F_FORCEBYTES) {
        eflags = PYCBC_FMT_BYTES;
    } else {
        eflags = resp->v.v0.flags;
    }

    rv = pycbc_tc_decode_value(mres->parent,
                               resp->v.v0.bytes,
                               resp->v.v0.nbytes,
                               eflags,
                               &res->value);
    if (rv < 0) {
        push_fatal_error(mres);
    }

    CB_THR_BEGIN(conn);
    (void)instance;
}
コード例 #3
0
static void
observe_callback(lcb_t instance,
                 const void *cookie,
                 lcb_error_t err,
                 const lcb_observe_resp_t *resp)
{
    int rv;
    pycbc_ObserveInfo *oi;
    pycbc_Connection *conn;
    pycbc_ValueResult *vres;
    pycbc_MultiResult *mres;

    if (!resp->v.v0.key) {
        mres = (pycbc_MultiResult*)cookie;;
        maybe_breakout(mres->parent);
        return;
    }

    rv = get_common_objects((PyObject*)cookie,
                            resp->v.v0.key,
                            resp->v.v0.nkey,
                            err,
                            &conn,
                            (pycbc_Result**)&vres,
                            RESTYPE_VALUE|RESTYPE_EXISTS_OK|RESTYPE_VARCOUNT,
                            &mres);
    if (rv < 0) {
        goto GT_DONE;
    }

    if (err != LCB_SUCCESS) {
        maybe_push_operr(mres, (pycbc_Result*)vres, err, 0);
        goto GT_DONE;
    }

    if (!vres->value) {
        vres->value = PyList_New(0);
    }

    oi = pycbc_observeinfo_new(conn);
    if (oi == NULL) {
        push_fatal_error(mres);
        goto GT_DONE;
    }

    oi->from_master = resp->v.v0.from_master;
    oi->flags = resp->v.v0.status;
    oi->cas = resp->v.v0.cas;
    PyList_Append(vres->value, (PyObject*)oi);
    Py_DECREF(oi);

    GT_DONE:
    CB_THR_BEGIN(conn);
    (void)instance;
}
コード例 #4
0
static int
get_common_objects(PyObject *cookie,
                   const void *key,
                   size_t nkey,
                   lcb_error_t err,
                   pycbc_Connection **conn,
                   pycbc_Result **res,
                   int restype,
                   pycbc_MultiResult **mres)

{
    PyObject *hkey;
    int rv;

    pycbc_assert(Py_TYPE(cookie) == &pycbc_MultiResultType);
    *mres = (pycbc_MultiResult*)cookie;
    *conn = (*mres)->parent;

    if (!(restype & RESTYPE_VARCOUNT)) {
        maybe_breakout(*conn);
    }

    CB_THR_END(*conn);

    rv = pycbc_tc_decode_key(*conn, key, nkey, &hkey);

    if (rv < 0) {
        push_fatal_error(*mres);
        return -1;
    }

    *res = (pycbc_Result*)PyDict_GetItem((PyObject*)*mres, hkey);

    if (*res) {
        int exists_ok = (restype & RESTYPE_EXISTS_OK) ||
                ( (*mres)->mropts & PYCBC_MRES_F_UALLOCED);

        if (!exists_ok) {
            if ((*conn)->flags & PYCBC_CONN_F_WARNEXPLICIT) {
                PyErr_WarnExplicit(PyExc_RuntimeWarning,
                                   "Found duplicate key",
                                   __FILE__, __LINE__,
                                   "couchbase._libcouchbase",
                                   NULL);

            } else {
                PyErr_WarnEx(PyExc_RuntimeWarning,
                             "Found duplicate key",
                             1);
            }
            /**
             * We need to destroy the existing object and re-create it.
             */
            PyDict_DelItem((PyObject*)*mres, hkey);
            *res = NULL;

        } else {
            Py_XDECREF(hkey);
        }

    }

    if (*res == NULL) {
        /**
         * Now, get/set the result object
         */
        if ( (*mres)->mropts & PYCBC_MRES_F_ITEMS) {
            *res = (pycbc_Result*)pycbc_item_new(*conn);

        } else if (restype & RESTYPE_BASE) {
            *res = (pycbc_Result*)pycbc_result_new(*conn);

        } else if (restype & RESTYPE_OPERATION) {
            *res = (pycbc_Result*)pycbc_opresult_new(*conn);

        } else if (restype & RESTYPE_VALUE) {
            *res = (pycbc_Result*)pycbc_valresult_new(*conn);

        } else {
            abort();
        }

        PyDict_SetItem((PyObject*)*mres, hkey, (PyObject*)*res);

        (*res)->key = hkey;
        Py_DECREF(*res);
    }

    if (err) {
        (*res)->rc = err;
    }

    if (err != LCB_SUCCESS) {
        (*mres)->all_ok = 0;
    }

    return 0;
}