static void do_memcached_flush(INTERNAL_FUNCTION_PARAMETERS, int oo, php_couchbase_res *res) { lcb_error_t retval; lcb_error_t cberr = LCB_SUCCESS; php_couchbase_ctx *ctx; lcb_flush_cmd_t cmd; const lcb_flush_cmd_t *const commands[] = { &cmd }; lcb_t instance; instance = res->handle; memset(&cmd, 0, sizeof(cmd)); lcb_set_flush_callback(instance, memcached_flush_callback); retval = lcb_flush(instance, (const void *)&cberr, 1, commands); if (retval == LCB_SUCCESS) { retval = cberr; } res->rc = retval; if (retval == LCB_SUCCESS) { RETURN_TRUE; } else { char errmsg[256]; sprintf(errmsg, "Failed to flush bucket: %s", lcb_strerror(instance, retval)); couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, cb_lcb_exception, errmsg); } }
/* * Name: couchdb_flush * Input Args: * handle - handle to the lcb instance * * Description: Flushes the entire cluster */ int couchdb_flush(void) { lcb_error_t ret; int lock_result; lcb_flush_cmd_t *cmd = malloc(sizeof(*cmd)); const lcb_flush_cmd_t *const flush_cmd[] = { cmd }; cmd->version = 0; lock_result = pthread_rwlock_wrlock(&db_rwlock); if (lock_result != 0) { syslog(LOG_ERR, "%s: Failed to obtain writelock. Error = %d\n", __FUNCTION__, errno); return -errno; } ret = lcb_flush(couchdb_handle, NULL, 1, flush_cmd); if (ret != LCB_SUCCESS) { syslog(LOG_ERR, "%s: lcb_flush failed with error %s\n", __FUNCTION__, lcb_strerror(couchdb_handle, ret)); return -ret; } /* Block the thread till this operation completes */ lcb_wait(couchdb_handle); pthread_rwlock_unlock(&db_rwlock); USYSLOG(LOG_INFO, "\n%s: lflushed siuccess\n", __FUNCTION__); return (1); }