Esempio n. 1
0
LIBCOUCHBASE_API
lcb_error_t
lcb_cntl_string(lcb_t instance, const char *key, const char *value)
{
    cntl_OPCODESTRS *cur;
    u_STRCONVERT u;
    lcb_error_t err;

    for (cur = stropcode_map; cur->key; cur++) {
        if (!strcmp(cur->key, key)) {
            if (cur->converter) {
                err = cur->converter(value, &u);
                if (err != LCB_SUCCESS) {
                    return err;
                }
                if (cur->converter == convert_passthru) {
                    return lcb_cntl(instance, LCB_CNTL_SET, cur->opcode, u.p);
                } else {
                    return lcb_cntl(instance, LCB_CNTL_SET, cur->opcode, &u);
                }
            }

            return lcb_cntl(instance, CNTL__MODE_SETSTRING, cur->opcode,
                (void *)value);
        }
    }
    return wrap_return(instance, LCB_NOT_SUPPORTED);
}
Esempio n. 2
0
LIBCOUCHBASE_API
lcb_syncmode_t lcb_behavior_get_syncmode(lcb_t instance)
{
    lcb_syncmode_t ret;
    lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_SYNCMODE, &ret);
    return ret;
}
Esempio n. 3
0
LIBCOUCHBASE_API
lcb_uint32_t lcb_cntl_getu32(lcb_t instance, int cmd)
{
    lcb_uint32_t ret = 0;
    lcb_cntl(instance, LCB_CNTL_GET, cmd, &ret);
    return ret;
}
Esempio n. 4
0
LIBCOUCHBASE_API
lcb_ipv6_t lcb_behavior_get_ipv6(lcb_t instance)
{
    lcb_ipv6_t ret;
    lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_IP6POLICY, &ret);
    return ret;
}
Esempio n. 5
0
LIBCOUCHBASE_API
lcb_size_t lcb_behavior_get_config_errors_threshold(lcb_t instance)
{
    lcb_size_t ret;
    lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_CONFERRTHRESH, &ret);
    return ret;
}
Esempio n. 6
0
static PyObject *
handle_float_tmo(lcb_t instance,
                 int cmd, int mode, PyObject *val, lcb_error_t *err)
{
    lcb_uint32_t cval;

    if (val != NULL) {
        if (PyFloat_Check(val)) {
            double dv = PyFloat_AsDouble(val);
            if (dv < 0) {
                PYCBC_EXC_WRAP(PYCBC_EXC_ARGUMENTS, 0,
                               "Timeout cannot be < 0");
                return NULL;
            }
            cval = dv * 1000000;

        } else {
        cval = pycbc_IntAsL(val);
            if (cval == (lcb_uint32_t)-1 && PyErr_Occurred()) {
                PYCBC_EXCTHROW_ARGS();
                return NULL;
            }
        }
    }
    if ( (*err = lcb_cntl(instance, mode, cmd, &cval)) != LCB_SUCCESS) {
        return NULL;
    }

    return pycbc_IntFromUL(cval);
}
Esempio n. 7
0
PyObject *
pycbc_Connection__vbmap(pycbc_Connection *conn, PyObject *args)
{
    pycbc_strlen_t slen = 0;
    const char *s = NULL;
    PyObject *rtuple;
    struct vbinfo_st info;
    lcb_error_t err;

    if (!PyArg_ParseTuple(args, "s#", &s, &slen)) {
        PYCBC_EXCTHROW_ARGS();
    }

    memset(&info, 0, sizeof(info));
    info.v.v0.key = s;
    info.v.v0.nkey = slen;
    err = lcb_cntl(conn->instance, CNTL_GET, CNTL_VBMAP, &info);
    if (err != LCB_SUCCESS) {
        PYCBC_EXC_WRAP(PYCBC_EXC_ARGUMENTS, 0, "lcb_cntl failed");
        return NULL;
    }

    rtuple = PyTuple_New(2);
    PyTuple_SET_ITEM(rtuple, 0, pycbc_IntFromL(info.v.v0.vbucket));
    PyTuple_SET_ITEM(rtuple, 1, pycbc_IntFromL(info.v.v0.server_index));
    return rtuple;

}
Esempio n. 8
0
LIBCOUCHBASE_API
lcb_uint32_t lcb_get_view_timeout(lcb_t instance)
{
    lcb_uint32_t ret;
    lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_VIEW_TIMEOUT, &ret);
    return ret;
}
Esempio n. 9
0
PHP_METHOD(Bucket, getOption)
{
    bucket_object *data = PCBC_PHP_THISOBJ();
    long type;
    lcb_uint32_t lcbval;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type) == FAILURE) {
        RETURN_NULL();
    }

    lcb_cntl(data->conn->lcb, LCB_CNTL_GET, type, &lcbval);

    RETURN_LONG(lcbval);
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
    lcb_STATUS err;
    lcb_INSTANCE *instance;
    char *bucket = NULL;
    size_t ii;

    if (argc < 2) {
        printf("Usage: %s couchbase://host/beer-sample [ password [ username ] ]\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    {
        struct lcb_create_st create_options = {0};
        create_options.version = 3;
        create_options.v.v3.connstr = argv[1];
        if (argc > 2) {
            create_options.v.v3.passwd = argv[2];
        }
        if (argc > 3) {
            create_options.v.v3.username = argv[3];
        }
        check(lcb_create(&instance, &create_options), "create couchbase handle");
        check(lcb_connect(instance), "schedule connection");
        lcb_wait(instance);
        check(lcb_get_bootstrap_status(instance), "bootstrap from cluster");
        check(lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_BUCKETNAME, &bucket), "get bucket name");
        if (strcmp(bucket, "beer-sample") != 0) {
            fail("expected bucket to be \"beer-sample\"");
        }
    }

    {
        const char *stmt = "SELECT * FROM breweries LIMIT 2";
        lcb_CMDANALYTICS *cmd;
        int idx = 0;
        lcb_cmdanalytics_create(&cmd);
        lcb_cmdanalytics_callback(cmd, row_callback);
        lcb_cmdanalytics_statement(cmd, stmt, strlen(stmt));
        lcb_cmdanalytics_deferred(cmd, 1);
        check(lcb_analytics(instance, &idx, cmd), "schedule analytics query");
        printf("----> \x1b[36m%s\x1b[0m\n", stmt);
        lcb_cmdanalytics_destroy(cmd);
        lcb_wait(instance);
    }

    /* Now that we're all done, close down the connection handle */
    lcb_destroy(instance);
    return 0;
}
Esempio n. 11
0
/** Initialize a Couchbase connection instance
 *
 * Initialize all information relating to a Couchbase instance and configure available method callbacks.
 * This function forces synchronous operation and will wait for a connection or timeout.
 *
 * @param instance Empty (un-allocated) Couchbase instance object.
 * @param host       The Couchbase server or list of servers.
 * @param bucket     The Couchbase bucket to associate with the instance.
 * @param pass       The Couchbase bucket password (NULL if none).
 * @param timeout    Maximum time to wait for obtaining the initial configuration.
 * @return           Couchbase error object.
 */
lcb_error_t couchbase_init_connection(lcb_t *instance, const char *host, const char *bucket, const char *pass,
				      struct timeval const *timeout)
{
	lcb_error_t error;                      /* couchbase command return */
	struct lcb_create_st options;           /* init create struct */

	lcb_uint32_t timeout_ms = FR_TIMEVAL_TO_MS(timeout);

	/* init options */
	memset(&options, 0, sizeof(options));

	/* assign couchbase create options */
	options.v.v0.host = host;
	options.v.v0.bucket = bucket;

	/* assign user and password if they were both passed */
	if (bucket != NULL && pass != NULL) {
		options.v.v0.user = bucket;
		options.v.v0.passwd = pass;
	}

	/* create couchbase connection instance */
	error = lcb_create(instance, &options);
	if (error != LCB_SUCCESS) return error;

	error = lcb_cntl(*instance, LCB_CNTL_SET, LCB_CNTL_CONFIGURATION_TIMEOUT, &timeout_ms);
	if (error != LCB_SUCCESS) return error;

	/* initiate connection */
	error = lcb_connect(*instance);
	if (error != LCB_SUCCESS) return error;

	/* set general method callbacks */
	lcb_set_stat_callback(*instance, couchbase_stat_callback);
	lcb_set_store_callback(*instance, couchbase_store_callback);
	lcb_set_get_callback(*instance, couchbase_get_callback);
	lcb_set_http_data_callback(*instance, couchbase_http_data_callback);
	/* wait on connection */
	lcb_wait(*instance);

	return LCB_SUCCESS;
}
Esempio n. 12
0
static PyObject *
handle_intval(lcb_t instance,
              int cmd, int mode, PyObject *val, lcb_error_t *err)
{
    int cval;

    if (val != NULL) {
        cval = pycbc_IntAsL(val);
        if (cval == -1 && PyErr_Occurred()) {
            PYCBC_EXCTHROW_ARGS();
        }
    }

    if ((*err = lcb_cntl(instance, mode, cmd, &cval)) != LCB_SUCCESS) {
        return NULL;
    }

    return pycbc_IntFromL(cval);

}
Esempio n. 13
0
static PyObject *
Bucket_connected(pycbc_Bucket *self, void *unused)
{
    PyObject* ret = self->flags & PYCBC_CONN_F_CONNECTED ? Py_True : Py_False;

    if (ret == Py_False) {
        void *handle = NULL;
        lcb_error_t err;
        err = lcb_cntl(self->instance, LCB_CNTL_GET, LCB_CNTL_VBCONFIG, &handle);
        if (err == LCB_SUCCESS && handle != NULL) {
            self->flags |= PYCBC_CONN_F_CONNECTED;
            ret = Py_True;
        }
    }

    Py_INCREF(ret);

    (void)unused;

    return ret;
}
Esempio n. 14
0
static PyObject *
handle_boolean(lcb_t instance,
               int cmd, int mode, PyObject *val, lcb_error_t *err)
{
    int cval;
    PyObject *ret;

    if (val != NULL) {
        cval = PyObject_IsTrue(val);
    }

    if ( (*err = lcb_cntl(instance, mode, cmd, &cval)) != LCB_SUCCESS) {
        return NULL;
    }

    if (cval) {
        ret = Py_True;
    } else {
        ret = Py_False;
    }
    Py_INCREF(ret);
    return ret;
}
Esempio n. 15
0
static PyObject *
Bucket__mutinfo(pycbc_Bucket *self)
{
    PyObject *ll = PyList_New(0);
    size_t ii, vbmax;
    lcbvb_CONFIG *cfg = NULL;
    lcb_error_t rc;

    rc = lcb_cntl(self->instance, LCB_CNTL_GET, LCB_CNTL_VBCONFIG, &cfg);
    if (rc != LCB_SUCCESS) {
        PYCBC_EXC_WRAP(PYCBC_EXC_LCBERR, rc, "Couldn't get vBucket config");
        return NULL;
    }

    vbmax = vbucket_config_get_num_vbuckets(cfg);
    for (ii = 0; ii < vbmax; ++ii) {
        lcb_KEYBUF kb = { 0 };
        const lcb_MUTATION_TOKEN *mt;
        lcb_error_t rc = LCB_SUCCESS;
        PyObject *cur;

        kb.type = LCB_KV_VBID;
        kb.contig.nbytes = (size_t)ii;

        mt = lcb_get_mutation_token(self->instance, &kb, &rc);
        if (mt == NULL) {
            continue;
        }
        cur = Py_BuildValue("HKK", LCB_MUTATION_TOKEN_VB(mt),
            LCB_MUTATION_TOKEN_ID(mt), LCB_MUTATION_TOKEN_SEQ(mt));
        PyList_Append(ll, cur);
        Py_DECREF(cur);
    }

    return ll;
}
Esempio n. 16
0
LIBCOUCHBASE_API
void lcb_set_view_timeout(lcb_t instance, lcb_uint32_t usec)
{
    lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_VIEW_TIMEOUT, &usec);
}
Esempio n. 17
0
LIBCOUCHBASE_API
void lcb_behavior_set_config_errors_threshold(lcb_t instance, lcb_size_t num_events)
{
    lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_CONFERRTHRESH, &num_events);
}
Esempio n. 18
0
LIBCOUCHBASE_API
lcb_error_t lcb_cntl_setu32(lcb_t instance, int cmd, lcb_uint32_t arg)
{
    return lcb_cntl(instance, LCB_CNTL_SET, cmd, &arg);
}
Esempio n. 19
0
LIBCOUCHBASE_API
void lcb_behavior_set_ipv6(lcb_t instance, lcb_ipv6_t mode)
{
    lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_IP6POLICY, &mode);
}
Esempio n. 20
0
/**
 * These APIs are moved from behavior.c and implemented atop of lcb_cntl
 */
LIBCOUCHBASE_API
void lcb_behavior_set_syncmode(lcb_t instance, lcb_syncmode_t val)
{
    lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_SYNCMODE, &val);
}
Esempio n. 21
0
PHP_METHOD(Bucket, __construct)
{
    bucket_object *data = PCBC_PHP_THISOBJ();
    zval *zdsn = NULL;
    zval *zname = NULL;
    zval *zpassword = NULL;
    char *dsn = NULL;
    char *name = NULL;
    char *password = NULL;
    lcb_error_t err;
    lcb_t instance;
    struct lcb_create_st create_options;
    char *connkey = NULL;
    pcbc_lcb *conn_iter, *conn;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zzz",
                              &zdsn, &zname, &zpassword) == FAILURE) {
        RETURN_NULL();
    }

    if (zap_zval_is_undef(zdsn)) {
        zdsn = NULL;
    }
    if (zap_zval_is_undef(zname)) {
        zname = NULL;
    }
    if (zap_zval_is_undef(zpassword)) {
        zpassword = NULL;
    }

    if (zdsn) {
        if (Z_TYPE_P(zdsn) == IS_STRING) {
            dsn = estrndup(Z_STRVAL_P(zdsn), Z_STRLEN_P(zdsn));
        } else {
            throw_pcbc_exception("Expected dsn as string", LCB_EINVAL);
            RETURN_NULL();
        }
    }

    if (zname) {
        if (Z_TYPE_P(zname) == IS_STRING) {
            name = estrndup(Z_STRVAL_P(zname), Z_STRLEN_P(zname));
        } else {
            throw_pcbc_exception("Expected bucket name as string", LCB_EINVAL);
            if (dsn) efree(dsn);
            RETURN_NULL();
        }
    }

    if (zpassword) {
        if (Z_TYPE_P(zpassword) == IS_STRING) {
            password = estrndup(Z_STRVAL_P(zpassword), Z_STRLEN_P(zpassword));
        } else {
            throw_pcbc_exception("Expected bucket password as string", LCB_EINVAL);
            if (dsn) efree(dsn);
            if (name) efree(name);
            RETURN_NULL();
        }
    }

    spprintf(&connkey, 512, "%s|%s|%s",
             dsn ? dsn : "",
             name ? name : "",
             password ? password : "");

    conn_iter = PCBCG(first_bconn);
    while (conn_iter) {
        if (strcmp(conn_iter->key, connkey) == 0) {
            break;
        }
        conn_iter = conn_iter->next;
    }

    if (!conn_iter)
    {
        memset(&create_options, 0, sizeof(create_options));
        create_options.version = 3;
        create_options.v.v3.connstr = dsn;
        create_options.v.v3.username = name;
        create_options.v.v3.passwd = password;
        create_options.v.v3.type = LCB_TYPE_BUCKET;
        err = lcb_create(&instance, &create_options);

        if (dsn) efree(dsn);
        if (password) efree(password);

        if (err != LCB_SUCCESS) {
            efree(connkey);
            efree(name);
            throw_lcb_exception(err);
            RETURN_NULL();
        }
        lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_CLIENT_STRING, pcbc_client_string);

        lcb_install_callback3(instance, LCB_CALLBACK_GET, get_callback);
        lcb_install_callback3(instance, LCB_CALLBACK_UNLOCK, unlock_callback);
        lcb_install_callback3(instance, LCB_CALLBACK_STORE, store_callback);
        lcb_install_callback3(instance, LCB_CALLBACK_STOREDUR, store_callback);
        lcb_install_callback3(instance, LCB_CALLBACK_REMOVE, remove_callback);
        lcb_install_callback3(instance, LCB_CALLBACK_TOUCH, touch_callback);
        lcb_install_callback3(instance, LCB_CALLBACK_COUNTER, counter_callback);
        lcb_install_callback3(instance, LCB_CALLBACK_SDLOOKUP, subdoc_callback);
        lcb_install_callback3(instance, LCB_CALLBACK_SDMUTATE, subdoc_callback);
        lcb_install_callback3(instance, LCB_CALLBACK_HTTP, http_callback);

        lcb_set_durability_callback(instance, durability_callback);


        err = lcb_connect(instance);
        if (err != LCB_SUCCESS) {
            efree(connkey);
            efree(name);
            lcb_destroy(instance);
            throw_lcb_exception(err);
            RETURN_NULL();
        }

        // We use lcb_wait here as no callbacks are invoked by connect.
        lcb_wait(instance);

        err = lcb_get_bootstrap_status(instance);
        if (err != LCB_SUCCESS) {
            efree(connkey);
            efree(name);
            lcb_destroy(instance);
            throw_lcb_exception(err);
            RETURN_NULL();
        }

        conn = pemalloc(sizeof(pcbc_lcb), 1);
        conn->bucket = pestrdup(name, 1);
        efree(name);
        conn->key = pestrdup(connkey, 1);
        conn->lcb = instance;
        conn->next = NULL;
        data->conn = conn;

        if (PCBCG(last_bconn)) {
            PCBCG(last_bconn)->next = conn;
            PCBCG(last_bconn) = conn;
        } else {
            PCBCG(first_bconn) = conn;
            PCBCG(last_bconn) = conn;
        }
    } else {
        if (dsn) efree(dsn);
        if (name) efree(name);
        if (password) efree(password);

        data->conn = conn_iter;
    }

    efree(connkey);
}
Esempio n. 22
0
File: cb.c Progetto: muut/cberl
ERL_NIF_TERM cb_connect(ErlNifEnv* env, handle_t* handle, void* obj)
{
    connect_args_t* args = (connect_args_t*)obj;

    lcb_error_t err;
    struct lcb_create_st create_options;
    struct lcb_create_io_ops_st io_opts;

    io_opts.version = 0;
    io_opts.v.v0.type = LCB_IO_OPS_DEFAULT;
    io_opts.v.v0.cookie = NULL;

    memset(&create_options, 0, sizeof(create_options));
    err = lcb_create_io_ops(&create_options.v.v0.io, &io_opts);
    if (err != LCB_SUCCESS) {
      printf("failed create io ops\n");
      fprintf(stderr, "Failed to create IO instance: %s\n",
          lcb_strerror(NULL, err));
      return return_lcb_error(env, err);
    }

    create_options.v.v0.host = args->host;
    create_options.v.v0.user = args->user;
    create_options.v.v0.bucket = args->bucket;
    create_options.v.v0.passwd = args->pass;

    err = lcb_create(&(handle->instance), &create_options);

    free(args->host);
    free(args->user);
    free(args->pass);
    free(args->bucket);

    if (err != LCB_SUCCESS) {
        return enif_make_tuple2(env, enif_make_atom(env, "error"),
                enif_make_string(env, lcb_strerror(NULL, err), ERL_NIF_LATIN1));
    }

    (void)lcb_set_get_callback(handle->instance, get_callback);
    (void)lcb_set_store_callback(handle->instance, store_callback);
    (void)lcb_set_unlock_callback(handle->instance, unlock_callback);
    (void)lcb_set_touch_callback(handle->instance, touch_callback);
    (void)lcb_set_arithmetic_callback(handle->instance, arithmetic_callback);
    (void)lcb_set_remove_callback(handle->instance, remove_callback);
    (void)lcb_set_http_complete_callback(handle->instance, http_callback);

    err = lcb_connect(handle->instance);

    if (err != LCB_SUCCESS) {
        return return_lcb_error(env, err);
    }

    err = lcb_wait(handle->instance);

    if(err != LCB_SUCCESS) {
        return return_lcb_error(env, err);
    }

    #ifdef LCB_CNTL_DETAILED_ERRCODES
    int val = 1;
    err = lcb_cntl(handle->instance, LCB_CNTL_SET, LCB_CNTL_DETAILED_ERRCODES, &val);
    if(err != LCB_SUCCESS) {
        return return_lcb_error(env, err);
    }
    #endif

    return enif_make_atom(env, "ok");
}
Esempio n. 23
0
static int
Bucket__init__(pycbc_Bucket *self,
                       PyObject *args, PyObject *kwargs)
{
    int rv;
    int conntype = LCB_TYPE_BUCKET;

    lcb_error_t err;
    PyObject *unlock_gil_O = NULL;
    PyObject *iops_O = NULL;
    PyObject *dfl_fmt = NULL;
    PyObject *tc = NULL;

    struct lcb_create_st create_opts = { 0 };


    /**
     * This xmacro enumerates the constructor keywords, targets, and types.
     * This was converted into an xmacro to ease the process of adding or
     * removing various parameters.
     */
#define XCTOR_ARGS(X) \
    X("connection_string", &create_opts.v.v3.connstr, "z") \
    X("connstr", &create_opts.v.v3.connstr, "z") \
    X("username", &create_opts.v.v3.username, "z") \
    X("password", &create_opts.v.v3.passwd, "z") \
    X("quiet", &self->quiet, "I") \
    X("unlock_gil", &unlock_gil_O, "O") \
    X("transcoder", &tc, "O") \
    X("default_format", &dfl_fmt, "O") \
    X("lockmode", &self->lockmode, "i") \
    X("_flags", &self->flags, "I") \
    X("_conntype", &conntype, "i") \
    X("_iops", &iops_O, "O")

    static char *kwlist[] = {
        #define X(s, target, type) s,
            XCTOR_ARGS(X)
        #undef X
            NULL
    };

    #define X(s, target, type) type
    static char *argspec = "|" XCTOR_ARGS(X);
    #undef X

    if (self->init_called) {
        PyErr_SetString(PyExc_RuntimeError, "__init__ was already called");
        return -1;
    }

    self->init_called = 1;
    self->flags = 0;
    self->unlock_gil = 1;
    self->lockmode = PYCBC_LOCKMODE_EXC;

    #define X(s, target, type) target,
    rv = PyArg_ParseTupleAndKeywords(args, kwargs, argspec, kwlist,
        XCTOR_ARGS(X) NULL);
    #undef X

    if (!rv) {
        PYCBC_EXCTHROW_ARGS();
        return -1;
    }

    if (unlock_gil_O && PyObject_IsTrue(unlock_gil_O) == 0) {
        self->unlock_gil = 0;
    }

    create_opts.version = 3;
    create_opts.v.v3.type = conntype;

    if (iops_O && iops_O != Py_None) {
        self->iopswrap = pycbc_iowrap_new(self, iops_O);
        create_opts.v.v3.io = pycbc_iowrap_getiops(self->iopswrap);
        self->unlock_gil = 0;
    }

    if (dfl_fmt == Py_None || dfl_fmt == NULL) {
        /** Set to 0 if None or NULL */
        dfl_fmt = pycbc_IntFromL(PYCBC_FMT_JSON);

    } else {
        Py_INCREF(dfl_fmt); /* later decref */
    }

    rv = Bucket_set_format(self, dfl_fmt, NULL);
    Py_XDECREF(dfl_fmt);
    if (rv == -1) {
        return rv;
    }

    /** Set the transcoder */
    if (tc && Bucket_set_transcoder(self, tc, NULL) == -1) {
        return -1;
    }

#if defined(WITH_THREAD)
    if (!self->unlock_gil) {
        self->lockmode = PYCBC_LOCKMODE_NONE;
    }

    if (self->lockmode != PYCBC_LOCKMODE_NONE) {
        self->lock = PyThread_allocate_lock();
    }
#else
    self->unlock_gil = 0;
    self->lockmode = PYCBC_LOCKMODE_NONE;
#endif

    err = lcb_create(&self->instance, &create_opts);
    if (err != LCB_SUCCESS) {
        self->instance = NULL;
        PYCBC_EXC_WRAP(PYCBC_EXC_LCBERR, err,
                       "Couldn't create instance. Either bad "
                       "credentials/hosts/bucket names were "
                       "passed, or there was an internal error in creating the "
                       "object");
        return -1;
    }

    if (pycbc_log_handler) {
        err = lcb_cntl(self->instance, LCB_CNTL_SET, LCB_CNTL_LOGGER,
                       &pycbc_lcb_logprocs);
        if (err != LCB_SUCCESS) {
            self->instance = NULL;
            PYCBC_EXC_WRAP(PYCBC_EXC_LCBERR, err, "Couldn't create log handler");
            return -1;
        }
    }

    pycbc_callbacks_init(self->instance);
    lcb_set_cookie(self->instance, self);
    {
        const char *bucketstr;
        err = lcb_cntl(self->instance, LCB_CNTL_GET, LCB_CNTL_BUCKETNAME, &bucketstr);
        if (err == LCB_SUCCESS && bucketstr != NULL) {
            self->bucket = pycbc_SimpleStringZ(bucketstr);
        }
    }
    return 0;
}