Example #1
0
static void shutdown_http(clconfig_provider *provider)
{
    http_provider *http = (http_provider *)provider;

    reset_stream_state(http);

    lcb_string_release(&http->stream.chunk);
    lcb_string_release(&http->stream.input);
    lcb_string_release(&http->stream.header);

    lcb_connection_close(&http->connection);
    lcb_connection_cleanup(&http->connection);

    if (http->current_config) {
        lcb_clconfig_decref(http->current_config);
    }
    if (http->disconn_timer) {
        lcb_timer_destroy(NULL, http->disconn_timer);
    }
    if (http->io_timer) {
        lcb_timer_destroy(NULL, http->io_timer);
    }
    if (http->as_schederr) {
        lcb_timer_destroy(NULL, http->as_schederr);
    }
    if (http->nodes) {
        hostlist_destroy(http->nodes);
    }
    free(http);
}
Example #2
0
/**
 * Release all allocated resources for this server instance
 * @param server the server to destroy
 */
void lcb_server_destroy(lcb_server_t *server)
{
    lcb_server_release_connection(server, LCB_SUCCESS);

    /* Cancel all pending commands */
    if (server->cmd_log.nbytes) {
        lcb_server_purge_implicit_responses(server,
                                            server->instance->seqno,
                                            gethrtime(),
                                            1);
    }

    if (server->io_timer) {
        lcb_timer_destroy(NULL, server->io_timer);
    }


    lcb_connection_cleanup(&server->connection);

    free(server->rest_api_server);
    free(server->couch_api_base);
    free(server->authority);
    ringbuffer_destruct(&server->output_cookies);
    ringbuffer_destruct(&server->cmd_log);
    ringbuffer_destruct(&server->pending);
    ringbuffer_destruct(&server->pending_cookies);
    memset(server, 0xff, sizeof(*server));
}
Example #3
0
/*
 * Cancel the timer.
 *
 * @since 1.2.0.dp6
 *
 * This operation makes sense for periodic timers or if one need to cancel
 * regular timer before it will be triggered.
 *
 * @example Cancel periodic timer
 *   n = 1
 *   c.run do
 *     tm = c.create_periodic_timer(500000) do
 *       c.incr("foo") do
 *         if n == 5
 *           tm.cancel
 *         else
 *           n += 1
 *         end
 *       end
 *     end
 *   end
 *
 * @return [String]
 */
    VALUE
cb_timer_cancel(VALUE self)
{
    struct timer_st *tm = DATA_PTR(self);
    lcb_timer_destroy(tm->bucket->handle, tm->timer);
    return self;
}
Example #4
0
/**
 * This function is where the configuration actually takes place. We ensure
 * in other functions that this is only ever called directly from an event
 * loop stack frame (or one of the small mini functions here) so that we
 * don't accidentally end up destroying resources underneath us.
 */
static void config_callback(clconfig_listener *listener,
                            clconfig_event_t event,
                            clconfig_info *info)
{
    struct lcb_bootstrap_st *bs = (struct lcb_bootstrap_st *)listener;
    lcb_t instance = bs->parent;

    if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
        if (event == CLCONFIG_EVENT_PROVIDERS_CYCLED) {
            if (!instance->vbucket_config) {
                initial_bootstrap_error(instance,
                                        LCB_ERROR,
                                        "No more bootstrap providers remain");
            }
        }
        return;
    }

    instance->last_error = LCB_SUCCESS;
    bs->active = 0;
    /** Ensure we're not called directly twice again */
    listener->callback = async_step_callback;

    if (bs->timer) {
        lcb_timer_destroy(instance, bs->timer);
        bs->timer = NULL;
    }

    lcb_log(LOGARGS(instance, DEBUG), "Instance configured!");

    if (instance->type != LCB_TYPE_CLUSTER) {
        lcb_update_vbconfig(instance, info);
    }

    if (!bs->bootstrapped) {
        bs->bootstrapped = 1;
        if (instance->type == LCB_TYPE_BUCKET &&
                instance->dist_type == VBUCKET_DISTRIBUTION_KETAMA) {
            lcb_log(LOGARGS(instance, INFO),
                    "Reverting to HTTP Config for memcached buckets");

            /** Memcached bucket */
            lcb_clconfig_set_http_always_on(
                    lcb_confmon_get_provider(
                            instance->confmon, LCB_CLCONFIG_HTTP));
            lcb_confmon_set_provider_active(instance->confmon,
                                            LCB_CLCONFIG_HTTP, 1);

            lcb_confmon_set_provider_active(instance->confmon,
                                            LCB_CLCONFIG_CCCP, 0);

            lcb_confmon_set_provider_active(instance->confmon,
                                            LCB_CLCONFIG_CCCP, 0);
        }
    }

    lcb_maybe_breakout(instance);
}
Example #5
0
    static void
timer_callback(lcb_timer_t timer, lcb_t instance,
        const void *cookie)
{
    struct timer_st *tm = (struct timer_st *)cookie;
    int error = 0;

    rb_protect(trigger_timer, tm->self, &error);
    if (error) {
        lcb_timer_destroy(instance, timer);
    }
    (void)cookie;
}
Example #6
0
void lcb_bootstrap_destroy(lcb_t instance)
{
    struct lcb_bootstrap_st *bs = instance->bootstrap;
    if (!bs) {
        return;
    }

    if (bs->timer) {
        lcb_timer_destroy(instance, bs->timer);
    }

    lcb_confmon_remove_listener(instance->confmon, &bs->listener);
    free(bs);
    instance->bootstrap = NULL;
}
Example #7
0
static void cccp_cleanup(clconfig_provider *pb)
{
    cccp_provider *cccp = (cccp_provider *)pb;

    release_socket(cccp, 0);
    lcb_connection_cleanup(&cccp->connection);

    if (cccp->config) {
        lcb_clconfig_decref(cccp->config);
    }
    if (cccp->nodes) {
        hostlist_destroy(cccp->nodes);
    }
    if (cccp->timer) {
        lcb_timer_destroy(NULL, cccp->timer);
    }
    if (cccp->cmdcookie) {
        cccp->cmdcookie->ignore_errors = 1;
    }
    free(cccp);
}
Example #8
0
static void initial_bootstrap_error(lcb_t instance,
                                    lcb_error_t err,
                                    const char *errinfo)
{
    instance->last_error = lcb_confmon_last_error(instance->confmon);
    if (instance->last_error == LCB_SUCCESS) {
        instance->last_error = err;
    }

    instance->bootstrap->active = 0 ;
    lcb_error_handler(instance, instance->last_error, errinfo);
    lcb_log(LOGARGS(instance, ERR),
            "Failed to bootstrap client=%p. Code=0x%x, Message=%s",
            (void *)instance, err, errinfo);
    if (instance->bootstrap->timer) {
        lcb_timer_destroy(instance, instance->bootstrap->timer);
        instance->bootstrap->timer = NULL;
    }

    lcb_maybe_breakout(instance);
}
Example #9
0
LIBCOUCHBASE_API
void lcb_destroy(lcb_t instance)
{
    lcb_size_t ii;
    lcb_settings *settings = &instance->settings;

    if (instance->cur_configinfo) {
        lcb_clconfig_decref(instance->cur_configinfo);
        instance->cur_configinfo = NULL;
    }
    instance->vbucket_config = NULL;

    lcb_bootstrap_destroy(instance);
    lcb_confmon_destroy(instance->confmon);
    hostlist_destroy(instance->usernodes);

    if (instance->timers != NULL) {
        for (ii = 0; ii < instance->timers->capacity; ++ii) {
            if (instance->timers->items[ii] > 1) {
                lcb_timer_destroy(instance,
                                  (lcb_timer_t)instance->timers->items[ii]);
            }
        }
        hashset_destroy(instance->timers);
    }

    if (instance->durability_polls) {
        struct lcb_durability_set_st **dset_list;
        lcb_size_t nitems = hashset_num_items(instance->durability_polls);
        dset_list = (struct lcb_durability_set_st **)
                    hashset_get_items(instance->durability_polls, NULL);
        if (dset_list) {
            for (ii = 0; ii < nitems; ii++) {
                lcb_durability_dset_destroy(dset_list[ii]);
            }
            free(dset_list);
        }
        hashset_destroy(instance->durability_polls);
    }

    for (ii = 0; ii < instance->nservers; ++ii) {
        lcb_server_destroy(instance->servers + ii);
    }

    if (instance->http_requests) {
        for (ii = 0; ii < instance->http_requests->capacity; ++ii) {
            if (instance->http_requests->items[ii] > 1) {
                lcb_http_request_t htreq =
                    (lcb_http_request_t)instance->http_requests->items[ii];

                /**
                 * We don't want to invoke callbacks *or* remove it from our
                 * hash table
                 */
                htreq->status |= LCB_HTREQ_S_CBINVOKED | LCB_HTREQ_S_HTREMOVED;

                /* we should figure out a better error code for this.. */
                lcb_http_request_finish(instance, htreq, LCB_ERROR);
            }
        }
    }

    hashset_destroy(instance->http_requests);

    free(instance->servers);

    connmgr_destroy(instance->memd_sockpool);

    if (settings->io && settings->io->v.v0.need_cleanup) {
        lcb_destroy_io_ops(settings->io);
    }

    ringbuffer_destruct(&instance->purged_buf);
    ringbuffer_destruct(&instance->purged_cookies);

    free(instance->histogram);
    free(instance->scratch);
    free(settings->username);
    free(settings->password);
    free(settings->bucket);
    free(settings->sasl_mech_force);
    if (instance->cmdht) {
        genhash_free(instance->cmdht);
        instance->cmdht = NULL;
    }

    memset(instance, 0xff, sizeof(*instance));
    free(instance);
}