Exemple #1
0
LIBCOUCHBASE_API
lcb_int32_t lcb_get_num_nodes(lcb_t instance)
{
    if (LCBT_VBCONFIG(instance)) {
        return LCBT_NSERVERS(instance);
    } else {
        return -1;
    }
}
LIBCOUCHBASE_API
lcb_MULTICMD_CTX *
lcb_observe3_ctxnew(lcb_t instance)
{
    OBSERVECTX *ctx;
    lcb_SIZE n_extra = LCBT_NSERVERS(instance)-1;
    ctx = calloc(1, sizeof(*ctx) + sizeof(ctx->requests) * n_extra);
    ctx->instance = instance;
    ctx->nrequests = n_extra + 1;
    ctx->mctx.addcmd = obs_ctxadd;
    ctx->mctx.done = obs_ctxdone;
    ctx->mctx.fail = obs_ctxfail;
    return &ctx->mctx;
}
LIBCOUCHBASE_API
void
lcb_sched_flush(lcb_t instance)
{
    unsigned ii;
    for (ii = 0; ii < LCBT_NSERVERS(instance); ii++) {
        mc_SERVER *server = LCBT_GET_SERVER(instance, ii);

        if (!mcserver_has_pending(server)) {
            continue;
        }
        server->pipeline.flush_start(&server->pipeline);
    }
}
Exemple #4
0
static void
maybe_reset_timeouts(lcb_t instance)
{
    size_t ii;
    lcb_U64 now;

    if (!LCBT_SETTING(instance, readj_ts_wait)) {
        return;
    }

    now = lcb_nstime();
    for (ii = 0; ii < LCBT_NSERVERS(instance); ++ii) {
        mc_SERVER *ss = LCBT_GET_SERVER(instance, ii);
        mcreq_reset_timeouts(&ss->pipeline, now);
    }
    lcb_retryq_reset_timeouts(instance->retryq, now);
}
LIBCOUCHBASE_API
lcb_MULTICMD_CTX *
lcb_observe3_ctxnew(lcb_t instance)
{
    OBSERVECTX *ctx;
    size_t ii, n_extra = LCBT_NSERVERS(instance)-1;
    ctx = calloc(1, sizeof(*ctx) + sizeof(ctx->requests) * n_extra);
    ctx->instance = instance;
    ctx->nrequests = n_extra + 1;
    ctx->mctx.addcmd = obs_ctxadd;
    ctx->mctx.done = obs_ctxdone;
    ctx->mctx.fail = obs_ctxfail;

    /* note this block doesn't do anything not done with calloc, but makes for
     * easier reading/tracking */
    for (ii = 0; ii < ctx->nrequests; ii++) {
        lcb_string_init(ctx->requests + ii);
    }

    return &ctx->mctx;
}
Exemple #6
0
static int
has_pending(lcb_t instance)
{
    unsigned ii;

    if (!lcb_retryq_empty(instance->retryq)) {
        return 1;
    }

    if (lcb_aspend_pending(&instance->pendops)) {
        return 1;
    }

    for (ii = 0; ii < LCBT_NSERVERS(instance); ii++) {
        mc_SERVER *ss = LCBT_GET_SERVER(instance, ii);
        if (mcserver_has_pending(ss)) {
            return 1;
        }
    }
    return 0;
}
Exemple #7
0
static lcb_U8
get_poll_meth(lcb_t instance, const lcb_DURABILITYOPTSv0 *options)
{
    /* Need to call this first, so we can actually allocate the appropriate
     * data for this.. */
    lcb_U8 meth = options->pollopts;
    if (meth == LCB_DURABILITY_MODE_DEFAULT) {
        meth = LCB_DURABILITY_MODE_CAS;

        if (LCBT_SETTING(instance, fetch_mutation_tokens) &&
                LCBT_SETTING(instance, dur_mutation_tokens)) {
            size_t ii;
            for (ii = 0; ii < LCBT_NSERVERS(instance); ii++) {
                mc_SERVER *s = LCBT_GET_SERVER(instance, ii);
                if (s->mutation_tokens) {
                    meth = LCB_DURABILITY_MODE_SEQNO;
                    break;
                }
            }
        }
    }
    return meth;
}
Exemple #8
0
LIBCOUCHBASE_API
const char *
lcb_get_node(lcb_t instance, lcb_GETNODETYPE type, unsigned ix)
{
    if (type & LCB_NODE_HTCONFIG) {
        if (type & LCB_NODE_CONNECTED) {
            const lcb_host_t *host = lcb_confmon_get_rest_host(instance->confmon);
            if (host) {
                return mk_scratch_host(instance, host);
            } else {
                return return_badhost(type);
            }

        } else {
            /* Retrieve one from the vbucket configuration */
            lcbvb_CONFIG *vbc = LCBT_VBCONFIG(instance);
            lcbvb_SVCMODE mode;
            const char *hp = NULL;
            if (LCBT_SETTING(instance, sslopts) & LCB_SSL_ENABLED) {
                mode = LCBVB_SVCMODE_SSL;
            } else {
                mode = LCBVB_SVCMODE_PLAIN;
            }

            if (instance->type == LCB_TYPE_BUCKET) {
                if (vbc) {
                    ix %= LCBVB_NSERVERS(vbc);
                    hp = lcbvb_get_hostport(vbc, ix, LCBVB_SVCTYPE_MGMT, mode);

                } else if ((type & LCB_NODE_NEVERNULL) == 0) {
                    return NULL;
                }
            }
            if (hp == NULL && instance->ht_nodes && instance->ht_nodes->nentries) {
                ix %= instance->ht_nodes->nentries;
                hostlist_ensure_strlist(instance->ht_nodes);
                hp = instance->ht_nodes->slentries[ix];
            }
            if (!hp) {
                if ((hp = return_badhost(type)) == NULL) {
                    return NULL;
                }
            }
            if (!ensure_scratch(instance, strlen(hp)+1)) {
                return NULL;
            }
            lcb_string_appendz(instance->scratch, hp);
            return instance->scratch->base;
        }
    } else if (type & (LCB_NODE_DATA|LCB_NODE_VIEWS)) {
        const mc_SERVER *server;
        ix %= LCBT_NSERVERS(instance);
        server = LCBT_GET_SERVER(instance, ix);

        if ((type & LCB_NODE_CONNECTED) && server->connctx == NULL) {
            return return_badhost(type);
        }
        if (server->curhost == NULL) {
            return return_badhost(type);
        }

        /* otherwise, return the actual host:port of the server */
        if (type & LCB_NODE_DATA) {
            return mk_scratch_host(instance, server->curhost);
        } else {
            return server->viewshost;
        }
    } else {
        return NULL; /* don't know the type */
    }
}