Пример #1
0
/**
********************************************************************************
** \brief
**   save a key/value into the ark db
*******************************************************************************/
void kv_async_DEL_KEY(async_CB_t *pCB)
{
    uint32_t rc=0;
    pCB->tag = pCB->itag + pCB->len_i;

    while (EAGAIN == (rc=ark_del_async_cb(pCB->ark,
                                          pCB->db->klen,
                                          pCB->db->kv[pCB->len_i].key,
                                          kv_async_cb,
                                          pCB->tag))) usleep(10000);
    if (rc) KV_ERR_STOP(pCB,"DEL_KEY",rc);
}
Пример #2
0
void kv_async_EXISTS_KEY(async_CB_t *pCB)
{
    uint32_t rc=0;
    pCB->tag = pCB->itag + pCB->len_i;

    while (EAGAIN == (rc=ark_exists_async_cb(pCB->ark,
                                             KV_ASYNC_KLEN,
                                             pCB->db[pCB->len_i].key,
                                             kv_async_cb,
                                             pCB->tag))) usleep(10000);
    if (rc) KV_ERR_STOP(pCB,"EXIST_KEY",rc);
}
Пример #3
0
void kv_async_SET_KEY(async_CB_t *pCB)
{
    uint32_t rc=0;
    pCB->tag = pCB->itag + pCB->len_i;

    while (EAGAIN == (rc=ark_set_async_cb(pCB->ark,
                                          KV_ASYNC_KLEN,
                                          pCB->db[pCB->len_i].key,
                                          KV_ASYNC_VLEN,
                                          pCB->db[pCB->len_i].value,
                                          kv_async_cb,
                                          pCB->tag))) usleep(10000);
    if (rc) KV_ERR_STOP(pCB,"SET_KEY",rc);
}
Пример #4
0
/**
********************************************************************************
** \brief
**   callback for ark functions: set,get,exists,del
*******************************************************************************/
void kv_async_cb(int errcode, uint64_t dt, int64_t res)
{
    async_context_t *pCT  = pCTs+GET_CTXT(dt);
    async_CB_t      *pCB  = NULL;
    kv_t            *p_kv = NULL;

    if (NULL == pCT) KV_ERR_STOP(pCB, "bad dt: ctxt", 0);
    pCB = pCT->pCBs+GET_CB(dt);

    if (NULL == pCB)          KV_ERR_STOP(pCB, "bad dt: cb", 0);
    if (0   != errcode)       KV_ERR_STOP(pCB, "bad errcode", errcode);
    if (dt  != pCB->tag)      KV_ERR_STOP(pCB, "bad tag", 0);
    if (res != pCB->db->vlen) KV_ERR_STOP(pCB, "bad res", 0);

    p_kv = pCB->db->kv + pCB->len_i;
    ++pCB->len_i;

    if (pCB->flags & KV_ASYNC_SET)
    {
        /* end of db len sequence, move to next step */
        if (pCB->len_i == pCB->len)
        {
            pCB->len_i  = 0;
            pCB->flags &= ~KV_ASYNC_SET;
            pCB->flags |= KV_ASYNC_GET;
            kv_async_GET_KEY(pCB);
            goto done;
        }
        kv_async_SET_KEY(pCB);
        goto done;
    }
    else if (pCB->flags & KV_ASYNC_GET)
    {
        if (0 != memcmp(p_kv->value, pCB->gvalue, pCB->db->vlen))
        {
            KV_ERR_STOP(pCB,"get miscompare",0);
        }

        /* end of db len sequence, move to next step */
        if (pCB->len_i == pCB->len)
        {
            pCB->len_i = 0;
            if (read100 && !(pCB->flags & KV_ASYNC_SHUTDOWN))
            {
                kv_async_GET_KEY(pCB);
            }
            else
            {
                pCB->flags &= ~KV_ASYNC_GET;
                pCB->flags |= KV_ASYNC_EXISTS;
                kv_async_EXISTS_KEY(pCB);
            }
            goto done;
        }
        kv_async_GET_KEY(pCB);
        goto done;
    }
    else if (pCB->flags & KV_ASYNC_EXISTS)
    {
        /* if end of db len sequence, move to next step */
        if (pCB->len_i == pCB->len)
        {
            pCB->len_i  = 0;
            pCB->flags &= ~KV_ASYNC_EXISTS;
            pCB->flags |= KV_ASYNC_DEL;
            kv_async_DEL_KEY(pCB);
            goto done;
        }
        kv_async_EXISTS_KEY(pCB);
        goto done;
    }
    else if (pCB->flags & KV_ASYNC_DEL)
    {
        /* end of db len sequence, move to next step */
        if (pCB->len_i == pCB->len)
        {
            if (pCB->flags & KV_ASYNC_SHUTDOWN)
            {
                pCB->flags &= ~KV_ASYNC_RUNNING;
                goto done;
            }
            pCB->flags &= ~KV_ASYNC_DEL;
            pCB->flags |= KV_ASYNC_SET;
            pCB->len_i  = 0;
            kv_async_SET_KEY(pCB);
            goto done;
        }
        kv_async_DEL_KEY(pCB);
        goto done;
    }
    else
    {
        /* should not be here */
        assert(0);
    }

done:
    return;
}