Lines Matching refs:c
24 #define META_CHAR(p, c) { \ argument
26 *(p+1) = c; \
52 static void _finalize_mset(conn *c, int nbytes, enum store_item_type ret, uint64_t cas) { in _finalize_mset() argument
53 mc_resp *resp = c->resp; in _finalize_mset()
54 item *it = c->item; in _finalize_mset()
55 conn_set_state(c, conn_new_cmd); in _finalize_mset()
65 if (c->noreply) { in _finalize_mset()
79 c->noreply = false; in _finalize_mset()
80 out_string(c, "SERVER_ERROR Unhandled storage type."); in _finalize_mset()
132 void complete_nread_ascii(conn *c) { in complete_nread_ascii() argument
133 assert(c != NULL); in complete_nread_ascii()
135 item *it = c->item; in complete_nread_ascii()
136 int comm = c->cmd; in complete_nread_ascii()
141 pthread_mutex_lock(&c->thread->stats.mutex); in complete_nread_ascii()
142 c->thread->stats.slab_stats[ITEM_clsid(it)].set_cmds++; in complete_nread_ascii()
143 pthread_mutex_unlock(&c->thread->stats.mutex); in complete_nread_ascii()
152 item_chunk *ch = (item_chunk *) c->ritem; in complete_nread_ascii()
175 if (c->mset_res) { in complete_nread_ascii()
176 c->noreply = false; in complete_nread_ascii()
178 out_string(c, "CLIENT_ERROR bad data chunk"); in complete_nread_ascii()
181 c->thread->cur_sfd = c->sfd; // cuddle sfd for logging. in complete_nread_ascii()
182 …ret = store_item(it, comm, c->thread, &nbytes, &cas, c->cas ? c->cas : get_cas_id(), c->set_stale); in complete_nread_ascii()
183 c->cas = 0; in complete_nread_ascii()
186 switch (c->cmd) { in complete_nread_ascii()
188 MEMCACHED_COMMAND_ADD(c->sfd, ITEM_key(it), it->nkey, in complete_nread_ascii()
192 MEMCACHED_COMMAND_REPLACE(c->sfd, ITEM_key(it), it->nkey, in complete_nread_ascii()
196 MEMCACHED_COMMAND_APPEND(c->sfd, ITEM_key(it), it->nkey, in complete_nread_ascii()
200 MEMCACHED_COMMAND_PREPEND(c->sfd, ITEM_key(it), it->nkey, in complete_nread_ascii()
204 MEMCACHED_COMMAND_SET(c->sfd, ITEM_key(it), it->nkey, in complete_nread_ascii()
208 MEMCACHED_COMMAND_CAS(c->sfd, ITEM_key(it), it->nkey, it->nbytes, in complete_nread_ascii()
214 if (c->mset_res) { in complete_nread_ascii()
215 _finalize_mset(c, nbytes, ret, cas); in complete_nread_ascii()
219 out_string(c, "STORED"); in complete_nread_ascii()
222 out_string(c, "EXISTS"); in complete_nread_ascii()
225 out_string(c, "NOT_FOUND"); in complete_nread_ascii()
228 out_string(c, "NOT_STORED"); in complete_nread_ascii()
231 out_string(c, "SERVER_ERROR Unhandled storage type."); in complete_nread_ascii()
237 c->set_stale = false; /* force flag to be off just in case */ in complete_nread_ascii()
238 c->mset_res = false; in complete_nread_ascii()
239 item_remove(c->item); /* release the c->item reference */ in complete_nread_ascii()
240 c->item = 0; in complete_nread_ascii()
252 out_string(c, "ERROR"); \
260 out_string(c, "ERROR"); \
268 out_string(c, "ERROR"); \
333 int try_read_command_asciiauth(conn *c) { in try_read_command_asciiauth() argument
339 if (!c->sasl_started) { in try_read_command_asciiauth()
344 if (c->rbytes < 2) in try_read_command_asciiauth()
347 el = memchr(c->rcurr, '\n', c->rbytes); in try_read_command_asciiauth()
351 if (c->rbytes > 2048) { in try_read_command_asciiauth()
352 conn_set_state(c, conn_closing); in try_read_command_asciiauth()
365 ntokens = tokenize_command(c->rcurr, tokens, MAX_TOKENS); in try_read_command_asciiauth()
367 c->rbytes -= (el - c->rcurr) + 1; in try_read_command_asciiauth()
368 c->rcurr += (el - c->rcurr) + 1; in try_read_command_asciiauth()
374 if (!c->resp) { in try_read_command_asciiauth()
375 if (!resp_start(c)) { in try_read_command_asciiauth()
376 conn_set_state(c, conn_closing); in try_read_command_asciiauth()
380 out_string(c, "CLIENT_ERROR unauthenticated"); in try_read_command_asciiauth()
386 c->rlbytes = size + 2; in try_read_command_asciiauth()
388 c->sasl_started = true; // reuse from binprot sasl, but not sasl :) in try_read_command_asciiauth()
391 if (c->rbytes < c->rlbytes) { in try_read_command_asciiauth()
397 if (!c->resp) { in try_read_command_asciiauth()
398 if (!resp_start(c)) { in try_read_command_asciiauth()
399 conn_set_state(c, conn_closing); in try_read_command_asciiauth()
404 cont = c->rcurr; in try_read_command_asciiauth()
406 c->rbytes -= c->rlbytes; in try_read_command_asciiauth()
407 c->rcurr += c->rlbytes; in try_read_command_asciiauth()
408 c->sasl_started = false; in try_read_command_asciiauth()
413 if (strncmp(cont + c->rlbytes - 2, "\r\n", 2) != 0) { in try_read_command_asciiauth()
414 out_string(c, "CLIENT_ERROR bad command line termination"); in try_read_command_asciiauth()
419 cont[c->rlbytes - 2] = '\0'; in try_read_command_asciiauth()
423 out_string(c, "CLIENT_ERROR bad authentication token format"); in try_read_command_asciiauth()
428 out_string(c, "STORED"); in try_read_command_asciiauth()
429 c->authenticated = true; in try_read_command_asciiauth()
430 c->try_read_command = try_read_command_ascii; in try_read_command_asciiauth()
431 pthread_mutex_lock(&c->thread->stats.mutex); in try_read_command_asciiauth()
432 c->thread->stats.auth_cmds++; in try_read_command_asciiauth()
433 pthread_mutex_unlock(&c->thread->stats.mutex); in try_read_command_asciiauth()
435 out_string(c, "CLIENT_ERROR authentication failure"); in try_read_command_asciiauth()
436 pthread_mutex_lock(&c->thread->stats.mutex); in try_read_command_asciiauth()
437 c->thread->stats.auth_cmds++; in try_read_command_asciiauth()
438 c->thread->stats.auth_errors++; in try_read_command_asciiauth()
439 pthread_mutex_unlock(&c->thread->stats.mutex); in try_read_command_asciiauth()
445 int try_read_command_ascii(conn *c) { in try_read_command_ascii() argument
448 if (c->rbytes == 0) in try_read_command_ascii()
451 el = memchr(c->rcurr, '\n', c->rbytes); in try_read_command_ascii()
453 if (c->rbytes > 2048) { in try_read_command_ascii()
458 char *ptr = c->rcurr; in try_read_command_ascii()
463 if (ptr - c->rcurr > 100 || in try_read_command_ascii()
466 conn_set_state(c, conn_closing); in try_read_command_ascii()
473 if (!c->rbuf_malloced) { in try_read_command_ascii()
474 if (!rbuf_switch_to_malloc(c)) { in try_read_command_ascii()
475 conn_set_state(c, conn_closing); in try_read_command_ascii()
484 if ((el - c->rcurr) > 1 && *(el - 1) == '\r') { in try_read_command_ascii()
489 assert(cont <= (c->rcurr + c->rbytes)); in try_read_command_ascii()
491 c->last_cmd_time = current_time; in try_read_command_ascii()
492 process_command_ascii(c, c->rcurr); in try_read_command_ascii()
494 c->rbytes -= (cont - c->rcurr); in try_read_command_ascii()
495 c->rcurr = cont; in try_read_command_ascii()
497 assert(c->rcurr <= (c->rbuf + c->rsize)); in try_read_command_ascii()
503 static inline bool set_noreply_maybe(conn *c, token_t *tokens, size_t ntokens) in set_noreply_maybe() argument
516 c->noreply = true; in set_noreply_maybe()
518 return c->noreply; in set_noreply_maybe()
547 static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, bool return_cas, b… in process_get_command() argument
555 assert(c != NULL); in process_get_command()
556 mc_resp *resp = c->resp; in process_get_command()
561 out_string(c, "CLIENT_ERROR invalid exptime argument"); in process_get_command()
579 it = limited_get(key, nkey, c->thread, exptime, should_touch, DO_UPDATE, &overflow); in process_get_command()
593 MEMCACHED_COMMAND_GET(c->sfd, ITEM_key(it), it->nkey, in process_get_command()
606 if (storage_get_item(c, it, resp) != 0) { in process_get_command()
607 pthread_mutex_lock(&c->thread->stats.mutex); in process_get_command()
608 c->thread->stats.get_oom_extstore++; in process_get_command()
609 pthread_mutex_unlock(&c->thread->stats.mutex); in process_get_command()
630 fprintf(stderr, ">%d sending key ", c->sfd); in process_get_command()
638 pthread_mutex_lock(&c->thread->stats.mutex); in process_get_command()
640 c->thread->stats.touch_cmds++; in process_get_command()
641 c->thread->stats.slab_stats[ITEM_clsid(it)].touch_hits++; in process_get_command()
643 c->thread->stats.lru_hits[it->slabs_clsid]++; in process_get_command()
644 c->thread->stats.get_cmds++; in process_get_command()
646 pthread_mutex_unlock(&c->thread->stats.mutex); in process_get_command()
656 pthread_mutex_lock(&c->thread->stats.mutex); in process_get_command()
658 c->thread->stats.touch_cmds++; in process_get_command()
659 c->thread->stats.touch_misses++; in process_get_command()
661 c->thread->stats.get_misses++; in process_get_command()
662 c->thread->stats.get_cmds++; in process_get_command()
664 MEMCACHED_COMMAND_GET(c->sfd, key, nkey, -1, 0); in process_get_command()
665 pthread_mutex_unlock(&c->thread->stats.mutex); in process_get_command()
670 if (!resp_start(c)) { in process_get_command()
673 resp = c->resp; in process_get_command()
684 if (!resp_start(c)) { in process_get_command()
687 resp = c->resp; in process_get_command()
693 fprintf(stderr, ">%d END\n", c->sfd); in process_get_command()
702 conn_release_items(c); in process_get_command()
704 if (!resp_start(c)) { in process_get_command()
706 conn_set_state(c, conn_closing); in process_get_command()
710 out_string(c, "CLIENT_ERROR bad command line format"); in process_get_command()
712 out_of_memory(c, "SERVER_ERROR out of memory writing get response"); in process_get_command()
717 conn_set_state(c, conn_mwrite); in process_get_command()
721 inline static void process_stats_detail(conn *c, const char *command) { in process_stats_detail() argument
722 assert(c != NULL); in process_stats_detail()
726 out_string(c, "OK"); in process_stats_detail()
730 out_string(c, "OK"); in process_stats_detail()
735 write_and_free(c, stats, len); in process_stats_detail()
738 out_string(c, "CLIENT_ERROR usage: stats detail on|off|dump"); in process_stats_detail()
742 static void process_stat(conn *c, token_t *tokens, const size_t ntokens) { in process_stat() argument
744 assert(c != NULL); in process_stat()
747 out_string(c, "CLIENT_ERROR bad command line"); in process_stat()
752 server_stats(&append_stats, c); in process_stat()
753 (void)get_stats(NULL, 0, &append_stats, c); in process_stat()
756 out_string(c, "RESET"); in process_stat()
761 process_stats_detail(c, ""); /* outputs the error message */ in process_stat()
763 process_stats_detail(c, tokens[2].value); in process_stat()
767 process_stat_settings(&append_stats, c); in process_stat()
773 out_string(c, "CLIENT_ERROR stats cachedump not allowed"); in process_stat()
778 out_string(c, "CLIENT_ERROR bad command line"); in process_stat()
784 out_string(c, "CLIENT_ERROR bad command line format"); in process_stat()
789 out_string(c, "CLIENT_ERROR Illegal slab id"); in process_stat()
794 write_and_free(c, buf, bytes); in process_stat()
797 process_stats_conns(&append_stats, c); in process_stat()
800 process_extstore_stats(&append_stats, c); in process_stat()
804 process_proxy_stats(settings.proxy_ctx, &append_stats, c); in process_stat()
806 process_proxy_funcstats(settings.proxy_ctx, &append_stats, c); in process_stat()
808 process_proxy_bestats(settings.proxy_ctx, &append_stats, c); in process_stat()
813 if (get_stats(subcommand, strlen(subcommand), &append_stats, c)) { in process_stat()
814 if (c->stats.buffer == NULL) { in process_stat()
815 out_of_memory(c, "SERVER_ERROR out of memory writing stats"); in process_stat()
817 write_and_free(c, c->stats.buffer, c->stats.offset); in process_stat()
818 c->stats.buffer = NULL; in process_stat()
821 out_string(c, "ERROR"); in process_stat()
827 append_stats(NULL, 0, NULL, 0, c); in process_stat()
829 if (c->stats.buffer == NULL) { in process_stat()
830 out_of_memory(c, "SERVER_ERROR out of memory writing stats"); in process_stat()
832 write_and_free(c, c->stats.buffer, c->stats.offset); in process_stat()
833 c->stats.buffer = NULL; in process_stat()
838 static void process_meta_command(conn *c, token_t *tokens, const size_t ntokens) { in process_meta_command() argument
839 assert(c != NULL); in process_meta_command()
842 out_string(c, "CLIENT_ERROR bad command line format"); in process_meta_command()
854 out_string(c, "CLIENT_ERROR bad command line format"); in process_meta_command()
861 item *it = limited_get(key, nkey, c->thread, 0, false, DONT_UPDATE, &overflow); in process_meta_command()
863 mc_resp *resp = c->resp; in process_meta_command()
893 conn_set_state(c, conn_new_cmd); in process_meta_command()
895 out_string(c, "EN"); in process_meta_command()
897 pthread_mutex_lock(&c->thread->stats.mutex); in process_meta_command()
898 c->thread->stats.meta_cmds++; in process_meta_command()
899 pthread_mutex_unlock(&c->thread->stats.mutex); in process_meta_command()
1075 static void process_mget_command(conn *c, token_t *tokens, const size_t ntokens) { in process_mget_command() argument
1087 assert(c != NULL); in process_mget_command()
1088 mc_resp *resp = c->resp; in process_mget_command()
1095 out_errstring(c, "CLIENT_ERROR bad command line format"); in process_mget_command()
1104 out_errstring(c, "CLIENT_ERROR options flags are too long"); in process_mget_command()
1111 out_errstring(c, errstr); in process_mget_command()
1114 c->noreply = of.no_reply; in process_mget_command()
1124 it = limited_get(key, nkey, c->thread, 0, false, !of.no_update, &overflow); in process_mget_command()
1127 it = limited_get_locked(key, nkey, c->thread, DONT_UPDATE, &hv, &overflow); in process_mget_command()
1135 out_errstring(c, "SERVER_ERROR refcount overflow during fetch"); in process_mget_command()
1277 if (storage_get_item(c, it, resp) != 0) { in process_mget_command()
1278 pthread_mutex_lock(&c->thread->stats.mutex); in process_mget_command()
1279 c->thread->stats.get_oom_extstore++; in process_mget_command()
1280 pthread_mutex_unlock(&c->thread->stats.mutex); in process_mget_command()
1325 do_item_bump(c->thread, it, hv); in process_mget_command()
1333 pthread_mutex_lock(&c->thread->stats.mutex); in process_mget_command()
1335 c->thread->stats.touch_cmds++; in process_mget_command()
1336 c->thread->stats.slab_stats[ITEM_clsid(it)].touch_hits++; in process_mget_command()
1338 c->thread->stats.lru_hits[it->slabs_clsid]++; in process_mget_command()
1339 c->thread->stats.get_cmds++; in process_mget_command()
1341 pthread_mutex_unlock(&c->thread->stats.mutex); in process_mget_command()
1343 conn_set_state(c, conn_new_cmd); in process_mget_command()
1345 pthread_mutex_lock(&c->thread->stats.mutex); in process_mget_command()
1347 c->thread->stats.touch_cmds++; in process_mget_command()
1348 c->thread->stats.touch_misses++; in process_mget_command()
1350 c->thread->stats.get_misses++; in process_mget_command()
1351 c->thread->stats.get_cmds++; in process_mget_command()
1353 MEMCACHED_COMMAND_GET(c->sfd, key, nkey, -1, 0); in process_mget_command()
1354 pthread_mutex_unlock(&c->thread->stats.mutex); in process_mget_command()
1357 if (c->noreply) in process_mget_command()
1382 conn_set_state(c, conn_new_cmd); in process_mget_command()
1392 out_errstring(c, errstr); in process_mget_command()
1395 static void process_mset_command(conn *c, token_t *tokens, const size_t ntokens) { in process_mset_command() argument
1405 assert(c != NULL); in process_mset_command()
1406 mc_resp *resp = c->resp; in process_mset_command()
1414 out_errstring(c, "CLIENT_ERROR bad command line format"); in process_mset_command()
1419 out_errstring(c, "CLIENT_ERROR bad command line format"); in process_mset_command()
1424 out_errstring(c, "CLIENT_ERROR options flags too long"); in process_mset_command()
1433 out_errstring(c, "CLIENT_ERROR bad command line format"); in process_mset_command()
1438 out_errstring(c, "CLIENT_ERROR bad command line format"); in process_mset_command()
1454 c->noreply = of.no_reply; in process_mset_command()
1456 c->cas = of.has_cas_in ? of.cas_id_in : get_cas_id(); in process_mset_command()
1544 pthread_mutex_lock(&c->thread->stats.mutex); in process_mset_command()
1545 c->thread->stats.store_too_large++; in process_mset_command()
1546 pthread_mutex_unlock(&c->thread->stats.mutex); in process_mset_command()
1550 pthread_mutex_lock(&c->thread->stats.mutex); in process_mset_command()
1551 c->thread->stats.store_no_memory++; in process_mset_command()
1552 pthread_mutex_unlock(&c->thread->stats.mutex); in process_mset_command()
1555 LOGGER_LOG(c->thread->l, LOG_MUTATIONS, LOGGER_ITEM_STORE, in process_mset_command()
1560 it = item_get_locked(key, nkey, c->thread, DONT_UPDATE, &hv); in process_mset_command()
1563 STORAGE_delete(c->thread->storage, it); in process_mset_command()
1572 c->item = it; in process_mset_command()
1575 c->ritem = ITEM_schunk(it); in process_mset_command()
1577 c->ritem = ITEM_data(it); in process_mset_command()
1580 c->ritem = ITEM_data(it); in process_mset_command()
1582 c->rlbytes = it->nbytes; in process_mset_command()
1583 c->cmd = comm; in process_mset_command()
1591 c->set_stale = true; in process_mset_command()
1596 c->mset_res = true; in process_mset_command()
1597 conn_set_state(c, conn_nread); in process_mset_command()
1601 c->sbytes = vlen; in process_mset_command()
1605 out_errstring(c, errstr); in process_mset_command()
1607 conn_set_state(c, conn_swallow); in process_mset_command()
1610 static void process_mdelete_command(conn *c, token_t *tokens, const size_t ntokens) { in process_mdelete_command() argument
1618 assert(c != NULL); in process_mdelete_command()
1619 mc_resp *resp = c->resp; in process_mdelete_command()
1627 out_string(c, "CLIENT_ERROR bad command line format"); in process_mdelete_command()
1632 out_string(c, "CLIENT_ERROR options flags too long"); in process_mdelete_command()
1640 out_errstring(c, "CLIENT_ERROR invalid or duplicate flag"); in process_mdelete_command()
1643 assert(c != NULL); in process_mdelete_command()
1644 c->noreply = of.no_reply; in process_mdelete_command()
1667 it = item_get_locked(key, nkey, c->thread, DONT_UPDATE, &hv); in process_mdelete_command()
1669 MEMCACHED_COMMAND_DELETE(c->sfd, ITEM_key(it), it->nkey); in process_mdelete_command()
1673 pthread_mutex_lock(&c->thread->stats.mutex); in process_mdelete_command()
1674 c->thread->stats.delete_misses++; in process_mdelete_command()
1675 pthread_mutex_unlock(&c->thread->stats.mutex); in process_mdelete_command()
1686 if (do_store_item(new_it, NREAD_SET, c->thread, hv, NULL, NULL, in process_mdelete_command()
1714 if (c->noreply) in process_mdelete_command()
1719 pthread_mutex_lock(&c->thread->stats.mutex); in process_mdelete_command()
1720 c->thread->stats.slab_stats[ITEM_clsid(it)].delete_hits++; in process_mdelete_command()
1721 pthread_mutex_unlock(&c->thread->stats.mutex); in process_mdelete_command()
1726 STORAGE_delete(c->thread->storage, it); in process_mdelete_command()
1728 if (c->noreply) in process_mdelete_command()
1734 pthread_mutex_lock(&c->thread->stats.mutex); in process_mdelete_command()
1735 c->thread->stats.delete_misses++; in process_mdelete_command()
1736 pthread_mutex_unlock(&c->thread->stats.mutex); in process_mdelete_command()
1751 conn_set_state(c, conn_new_cmd); in process_mdelete_command()
1759 out_errstring(c, errstr); in process_mdelete_command()
1762 static void process_marithmetic_command(conn *c, token_t *tokens, const size_t ntokens) { in process_marithmetic_command() argument
1768 assert(c != NULL); in process_marithmetic_command()
1769 mc_resp *resp = c->resp; in process_marithmetic_command()
1785 out_string(c, "CLIENT_ERROR bad command line format"); in process_marithmetic_command()
1790 out_string(c, "CLIENT_ERROR options flags too long"); in process_marithmetic_command()
1797 out_errstring(c, "CLIENT_ERROR invalid or duplicate flag"); in process_marithmetic_command()
1800 assert(c != NULL); in process_marithmetic_command()
1801 c->noreply = of.no_reply; in process_marithmetic_command()
1834 switch(do_add_delta(c->thread, key, nkey, incr, of.delta, tmpbuf, &of.req_cas_id, hv, &it)) { in process_marithmetic_command()
1836 if (c->noreply) in process_marithmetic_command()
1862 if (do_store_item(it, NREAD_ADD, c->thread, hv, NULL, NULL, in process_marithmetic_command()
1874 pthread_mutex_lock(&c->thread->stats.mutex); in process_marithmetic_command()
1876 c->thread->stats.incr_misses++; in process_marithmetic_command()
1878 c->thread->stats.decr_misses++; in process_marithmetic_command()
1880 pthread_mutex_unlock(&c->thread->stats.mutex); in process_marithmetic_command()
1982 conn_set_state(c, conn_new_cmd); in process_marithmetic_command()
1989 out_errstring(c, errstr); in process_marithmetic_command()
1993 static void process_update_command(conn *c, token_t *tokens, const size_t ntokens, int comm, bool h… in process_update_command() argument
2003 assert(c != NULL); in process_update_command()
2005 set_noreply_maybe(c, tokens, ntokens); in process_update_command()
2008 out_string(c, "CLIENT_ERROR bad command line format"); in process_update_command()
2018 out_string(c, "CLIENT_ERROR bad command line format"); in process_update_command()
2027 out_string(c, "CLIENT_ERROR bad command line format"); in process_update_command()
2033 out_string(c, "CLIENT_ERROR bad command line format"); in process_update_command()
2047 out_string(c, "SERVER_ERROR object too large for cache"); in process_update_command()
2049 pthread_mutex_lock(&c->thread->stats.mutex); in process_update_command()
2050 c->thread->stats.store_too_large++; in process_update_command()
2051 pthread_mutex_unlock(&c->thread->stats.mutex); in process_update_command()
2053 out_of_memory(c, "SERVER_ERROR out of memory storing object"); in process_update_command()
2055 pthread_mutex_lock(&c->thread->stats.mutex); in process_update_command()
2056 c->thread->stats.store_no_memory++; in process_update_command()
2057 pthread_mutex_unlock(&c->thread->stats.mutex); in process_update_command()
2059 LOGGER_LOG(c->thread->l, LOG_MUTATIONS, LOGGER_ITEM_STORE, in process_update_command()
2060 NULL, status, comm, key, nkey, 0, 0, c->sfd); in process_update_command()
2062 conn_set_state(c, conn_swallow); in process_update_command()
2063 c->sbytes = vlen; in process_update_command()
2068 it = item_get(key, nkey, c->thread, DONT_UPDATE); in process_update_command()
2071 STORAGE_delete(c->thread->storage, it); in process_update_command()
2080 c->item = it; in process_update_command()
2083 c->ritem = ITEM_schunk(it); in process_update_command()
2085 c->ritem = ITEM_data(it); in process_update_command()
2088 c->ritem = ITEM_data(it); in process_update_command()
2090 c->rlbytes = it->nbytes; in process_update_command()
2091 c->cmd = comm; in process_update_command()
2092 conn_set_state(c, conn_nread); in process_update_command()
2095 static void process_touch_command(conn *c, token_t *tokens, const size_t ntokens) { in process_touch_command() argument
2102 assert(c != NULL); in process_touch_command()
2104 set_noreply_maybe(c, tokens, ntokens); in process_touch_command()
2107 out_string(c, "CLIENT_ERROR bad command line format"); in process_touch_command()
2115 out_string(c, "CLIENT_ERROR invalid exptime argument"); in process_touch_command()
2120 it = item_touch(key, nkey, exptime, c->thread); in process_touch_command()
2122 pthread_mutex_lock(&c->thread->stats.mutex); in process_touch_command()
2123 c->thread->stats.touch_cmds++; in process_touch_command()
2124 c->thread->stats.slab_stats[ITEM_clsid(it)].touch_hits++; in process_touch_command()
2125 pthread_mutex_unlock(&c->thread->stats.mutex); in process_touch_command()
2127 out_string(c, "TOUCHED"); in process_touch_command()
2130 pthread_mutex_lock(&c->thread->stats.mutex); in process_touch_command()
2131 c->thread->stats.touch_cmds++; in process_touch_command()
2132 c->thread->stats.touch_misses++; in process_touch_command()
2133 pthread_mutex_unlock(&c->thread->stats.mutex); in process_touch_command()
2135 out_string(c, "NOT_FOUND"); in process_touch_command()
2139 static void process_arithmetic_command(conn *c, token_t *tokens, const size_t ntokens, const bool i… in process_arithmetic_command() argument
2145 assert(c != NULL); in process_arithmetic_command()
2147 set_noreply_maybe(c, tokens, ntokens); in process_arithmetic_command()
2150 out_string(c, "CLIENT_ERROR bad command line format"); in process_arithmetic_command()
2158 out_string(c, "CLIENT_ERROR invalid numeric delta argument"); in process_arithmetic_command()
2162 switch(add_delta(c->thread, key, nkey, incr, delta, temp, NULL)) { in process_arithmetic_command()
2164 out_string(c, temp); in process_arithmetic_command()
2167 out_string(c, "CLIENT_ERROR cannot increment or decrement non-numeric value"); in process_arithmetic_command()
2170 out_of_memory(c, "SERVER_ERROR out of memory"); in process_arithmetic_command()
2173 pthread_mutex_lock(&c->thread->stats.mutex); in process_arithmetic_command()
2175 c->thread->stats.incr_misses++; in process_arithmetic_command()
2177 c->thread->stats.decr_misses++; in process_arithmetic_command()
2179 pthread_mutex_unlock(&c->thread->stats.mutex); in process_arithmetic_command()
2181 out_string(c, "NOT_FOUND"); in process_arithmetic_command()
2189 static void process_delete_command(conn *c, token_t *tokens, const size_t ntokens) { in process_delete_command() argument
2195 assert(c != NULL); in process_delete_command()
2199 bool sets_noreply = set_noreply_maybe(c, tokens, ntokens); in process_delete_command()
2203 out_string(c, "CLIENT_ERROR bad command line format. " in process_delete_command()
2214 out_string(c, "CLIENT_ERROR bad command line format"); in process_delete_command()
2222 it = item_get_locked(key, nkey, c->thread, DONT_UPDATE, &hv); in process_delete_command()
2224 MEMCACHED_COMMAND_DELETE(c->sfd, ITEM_key(it), it->nkey); in process_delete_command()
2226 pthread_mutex_lock(&c->thread->stats.mutex); in process_delete_command()
2227 c->thread->stats.slab_stats[ITEM_clsid(it)].delete_hits++; in process_delete_command()
2228 pthread_mutex_unlock(&c->thread->stats.mutex); in process_delete_command()
2231 STORAGE_delete(c->thread->storage, it); in process_delete_command()
2233 out_string(c, "DELETED"); in process_delete_command()
2235 pthread_mutex_lock(&c->thread->stats.mutex); in process_delete_command()
2236 c->thread->stats.delete_misses++; in process_delete_command()
2237 pthread_mutex_unlock(&c->thread->stats.mutex); in process_delete_command()
2239 out_string(c, "NOT_FOUND"); in process_delete_command()
2244 static void process_verbosity_command(conn *c, token_t *tokens, const size_t ntokens) { in process_verbosity_command() argument
2247 assert(c != NULL); in process_verbosity_command()
2249 set_noreply_maybe(c, tokens, ntokens); in process_verbosity_command()
2252 out_string(c, "CLIENT_ERROR bad command line format"); in process_verbosity_command()
2256 out_string(c, "OK"); in process_verbosity_command()
2261 static void process_misbehave_command(conn *c) { in process_misbehave_command() argument
2278 out_string(c, "ERROR"); in process_misbehave_command()
2280 out_string(c, "OK"); in process_misbehave_command()
2284 static void process_debugtime_command(conn *c, token_t *tokens, const size_t ntokens) { in process_debugtime_command() argument
2296 out_string(c, "ERROR"); in process_debugtime_command()
2302 out_string(c, "OK"); in process_debugtime_command()
2306 static void process_slabs_automove_command(conn *c, token_t *tokens, const size_t ntokens) { in process_slabs_automove_command() argument
2310 assert(c != NULL); in process_slabs_automove_command()
2312 set_noreply_maybe(c, tokens, ntokens); in process_slabs_automove_command()
2316 out_string(c, "ERROR"); in process_slabs_automove_command()
2322 out_string(c, "CLIENT_ERROR bad command line format"); in process_slabs_automove_command()
2330 out_string(c, "ERROR"); in process_slabs_automove_command()
2334 out_string(c, "OK"); in process_slabs_automove_command()
2339 static void process_watch_command(conn *c, token_t *tokens, const size_t ntokens) { in process_watch_command() argument
2342 assert(c != NULL); in process_watch_command()
2344 set_noreply_maybe(c, tokens, ntokens); in process_watch_command()
2346 out_string(c, "CLIENT_ERROR watch commands not allowed"); in process_watch_command()
2350 if (resp_has_stack(c)) { in process_watch_command()
2351 out_string(c, "ERROR cannot pipeline other commands before watch"); in process_watch_command()
2378 out_string(c, "ERROR"); in process_watch_command()
2386 switch(logger_add_watcher(c, c->sfd, f)) { in process_watch_command()
2388 out_string(c, "WATCHER_TOO_MANY log watcher limit reached"); in process_watch_command()
2391 out_string(c, "WATCHER_FAILED failed to add log watcher"); in process_watch_command()
2394 conn_set_state(c, conn_watch); in process_watch_command()
2395 event_del(&c->event); in process_watch_command()
2400 static void process_memlimit_command(conn *c, token_t *tokens, const size_t ntokens) { in process_memlimit_command() argument
2402 assert(c != NULL); in process_memlimit_command()
2404 set_noreply_maybe(c, tokens, ntokens); in process_memlimit_command()
2407 out_string(c, "ERROR"); in process_memlimit_command()
2410 out_string(c, "MEMLIMIT_TOO_SMALL cannot set maxbytes to less than 8m"); in process_memlimit_command()
2413 out_string(c, "MEMLIMIT_ADJUST_FAILED input value is megabytes not bytes"); in process_memlimit_command()
2419 out_string(c, "OK"); in process_memlimit_command()
2421 out_string(c, "MEMLIMIT_ADJUST_FAILED out of bounds or unable to adjust"); in process_memlimit_command()
2427 static void process_lru_command(conn *c, token_t *tokens, const size_t ntokens) { in process_lru_command() argument
2434 set_noreply_maybe(c, tokens, ntokens); in process_lru_command()
2441 out_string(c, "ERROR"); in process_lru_command()
2444 out_string(c, "ERROR hot and warm pcts must not exceed 80"); in process_lru_command()
2446 out_string(c, "ERROR hot/warm age factors must be greater than 0"); in process_lru_command()
2452 out_string(c, "OK"); in process_lru_command()
2459 out_string(c, "OK"); in process_lru_command()
2462 out_string(c, "OK"); in process_lru_command()
2464 out_string(c, "ERROR"); in process_lru_command()
2469 out_string(c, "ERROR"); in process_lru_command()
2477 out_string(c, "OK"); in process_lru_command()
2480 out_string(c, "ERROR"); in process_lru_command()
2484 static void process_extstore_command(conn *c, token_t *tokens, const size_t ntokens) { in process_extstore_command() argument
2485 set_noreply_maybe(c, tokens, ntokens); in process_extstore_command()
2538 out_string(c, "ERROR"); in process_extstore_command()
2540 out_string(c, "OK"); in process_extstore_command()
2544 static void process_flush_all_command(conn *c, token_t *tokens, const size_t ntokens) { in process_flush_all_command() argument
2548 set_noreply_maybe(c, tokens, ntokens); in process_flush_all_command()
2550 pthread_mutex_lock(&c->thread->stats.mutex); in process_flush_all_command()
2551 c->thread->stats.flush_cmds++; in process_flush_all_command()
2552 pthread_mutex_unlock(&c->thread->stats.mutex); in process_flush_all_command()
2556 out_string(c, "CLIENT_ERROR flush_all not allowed"); in process_flush_all_command()
2560 if (ntokens != (c->noreply ? 3 : 2)) { in process_flush_all_command()
2562 out_string(c, "CLIENT_ERROR invalid exptime argument"); in process_flush_all_command()
2581 out_string(c, "OK"); in process_flush_all_command()
2584 static void process_version_command(conn *c) { in process_version_command() argument
2585 out_string(c, "VERSION " VERSION); in process_version_command()
2588 static void process_quit_command(conn *c) { in process_quit_command() argument
2589 conn_set_state(c, conn_mwrite); in process_quit_command()
2590 c->close_after_write = true; in process_quit_command()
2591 c->close_reason = NORMAL_CLOSE; in process_quit_command()
2594 static void process_shutdown_command(conn *c, token_t *tokens, const size_t ntokens) { in process_shutdown_command() argument
2596 out_string(c, "ERROR: shutdown not enabled"); in process_shutdown_command()
2601 c->close_reason = SHUTDOWN_CLOSE; in process_shutdown_command()
2602 conn_set_state(c, conn_closing); in process_shutdown_command()
2605 c->close_reason = SHUTDOWN_CLOSE; in process_shutdown_command()
2606 conn_set_state(c, conn_closing); in process_shutdown_command()
2609 out_string(c, "CLIENT_ERROR invalid shutdown mode"); in process_shutdown_command()
2613 static void process_slabs_command(conn *c, token_t *tokens, const size_t ntokens) { in process_slabs_command() argument
2618 out_string(c, "CLIENT_ERROR slab reassignment disabled"); in process_slabs_command()
2624 out_string(c, "CLIENT_ERROR bad command line format"); in process_slabs_command()
2631 out_string(c, "OK"); in process_slabs_command()
2634 out_string(c, "BUSY currently processing reassign request"); in process_slabs_command()
2637 out_string(c, "BADCLASS invalid src or dst class id"); in process_slabs_command()
2640 out_string(c, "NOSPARE source class has no spare pages"); in process_slabs_command()
2643 out_string(c, "SAME src and dst class are identical"); in process_slabs_command()
2649 process_slabs_automove_command(c, tokens, ntokens); in process_slabs_command()
2651 out_string(c, "ERROR"); in process_slabs_command()
2655 static void process_lru_crawler_command(conn *c, token_t *tokens, const size_t ntokens) { in process_lru_crawler_command() argument
2659 out_string(c, "CLIENT_ERROR lru crawler disabled"); in process_lru_crawler_command()
2667 out_string(c, "OK"); in process_lru_crawler_command()
2670 out_string(c, "BUSY currently processing crawler request"); in process_lru_crawler_command()
2673 out_string(c, "BADCLASS invalid class id"); in process_lru_crawler_command()
2676 out_string(c, "NOTSTARTED no items to crawl"); in process_lru_crawler_command()
2679 out_string(c, "ERROR an unknown error happened"); in process_lru_crawler_command()
2685 out_string(c, "CLIENT_ERROR lru crawler disabled"); in process_lru_crawler_command()
2689 out_string(c, "ERROR metadump not allowed"); in process_lru_crawler_command()
2692 if (resp_has_stack(c)) { in process_lru_crawler_command()
2693 out_string(c, "ERROR cannot pipeline other commands before metadump"); in process_lru_crawler_command()
2698 c, c->sfd, LRU_CRAWLER_CAP_REMAINING); in process_lru_crawler_command()
2707 conn_set_state(c, conn_watch); in process_lru_crawler_command()
2708 event_del(&c->event); in process_lru_crawler_command()
2711 out_string(c, "BUSY currently processing crawler request"); in process_lru_crawler_command()
2714 out_string(c, "BADCLASS invalid class id"); in process_lru_crawler_command()
2717 out_string(c, "NOTSTARTED no items to crawl"); in process_lru_crawler_command()
2720 out_string(c, "ERROR an unknown error happened"); in process_lru_crawler_command()
2726 out_string(c, "CLIENT_ERROR lru crawler disabled"); in process_lru_crawler_command()
2730 out_string(c, "ERROR key dump not allowed"); in process_lru_crawler_command()
2733 if (resp_has_stack(c)) { in process_lru_crawler_command()
2734 out_string(c, "ERROR cannot pipeline other commands before mgdump"); in process_lru_crawler_command()
2739 c, c->sfd, LRU_CRAWLER_CAP_REMAINING); in process_lru_crawler_command()
2742 conn_set_state(c, conn_watch); in process_lru_crawler_command()
2743 event_del(&c->event); in process_lru_crawler_command()
2746 out_string(c, "BUSY currently processing crawler request"); in process_lru_crawler_command()
2749 out_string(c, "BADCLASS invalid class id"); in process_lru_crawler_command()
2752 out_string(c, "NOTSTARTED no items to crawl"); in process_lru_crawler_command()
2755 out_string(c, "ERROR an unknown error happened"); in process_lru_crawler_command()
2762 out_string(c, "CLIENT_ERROR bad command line format"); in process_lru_crawler_command()
2766 out_string(c, "OK"); in process_lru_crawler_command()
2771 out_string(c, "CLIENT_ERROR bad command line format"); in process_lru_crawler_command()
2775 out_string(c, "CLIENT_ERROR sleep must be one second or less"); in process_lru_crawler_command()
2779 out_string(c, "OK"); in process_lru_crawler_command()
2784 out_string(c, "OK"); in process_lru_crawler_command()
2786 out_string(c, "ERROR failed to start lru crawler thread"); in process_lru_crawler_command()
2790 out_string(c, "OK"); in process_lru_crawler_command()
2792 out_string(c, "ERROR failed to stop lru crawler thread"); in process_lru_crawler_command()
2795 out_string(c, "ERROR"); in process_lru_crawler_command()
2799 out_string(c, "ERROR"); in process_lru_crawler_command()
2803 static void process_refresh_certs_command(conn *c, token_t *tokens, const size_t ntokens) { in process_refresh_certs_command() argument
2804 set_noreply_maybe(c, tokens, ntokens); in process_refresh_certs_command()
2807 out_string(c, "OK"); in process_refresh_certs_command()
2809 write_and_free(c, errmsg, strlen(errmsg)); in process_refresh_certs_command()
2823 void process_command_ascii(conn *c, char *command) { in process_command_ascii() argument
2829 assert(c != NULL); in process_command_ascii()
2831 MEMCACHED_PROCESS_COMMAND_START(c->sfd, c->rcurr, c->rbytes); in process_command_ascii()
2834 fprintf(stderr, "<%d %s\n", c->sfd, command); in process_command_ascii()
2842 if (!resp_start(c)) { in process_command_ascii()
2843 conn_set_state(c, conn_closing); in process_command_ascii()
2847 c->thread->cur_sfd = c->sfd; // cuddle sfd for logging. in process_command_ascii()
2852 out_string(c, "ERROR"); in process_command_ascii()
2861 process_mget_command(c, tokens, ntokens); in process_command_ascii()
2864 process_mset_command(c, tokens, ntokens); in process_command_ascii()
2867 process_mdelete_command(c, tokens, ntokens); in process_command_ascii()
2870 out_string(c, "MN"); in process_command_ascii()
2872 conn_set_state(c, conn_mwrite); in process_command_ascii()
2875 process_marithmetic_command(c, tokens, ntokens); in process_command_ascii()
2878 process_meta_command(c, tokens, ntokens); in process_command_ascii()
2881 out_string(c, "ERROR"); in process_command_ascii()
2889 process_get_command(c, tokens, ntokens, false, false); in process_command_ascii()
2892 process_get_command(c, tokens, ntokens, true, false); in process_command_ascii()
2895 process_get_command(c, tokens, ntokens, false, true); in process_command_ascii()
2898 process_get_command(c, tokens, ntokens, true, true); in process_command_ascii()
2900 out_string(c, "ERROR"); in process_command_ascii()
2906 process_update_command(c, tokens, ntokens, comm, false); in process_command_ascii()
2909 process_stat(c, tokens, ntokens); in process_command_ascii()
2912 process_shutdown_command(c, tokens, ntokens); in process_command_ascii()
2915 process_slabs_command(c, tokens, ntokens); in process_command_ascii()
2917 out_string(c, "ERROR"); in process_command_ascii()
2924 process_update_command(c, tokens, ntokens, comm, false); in process_command_ascii()
2926 out_string(c, "ERROR"); in process_command_ascii()
2932 process_update_command(c, tokens, ntokens, comm, true); in process_command_ascii()
2936 process_memlimit_command(c, tokens, ntokens); in process_command_ascii()
2938 out_string(c, "ERROR"); in process_command_ascii()
2944 process_arithmetic_command(c, tokens, ntokens, 1); in process_command_ascii()
2946 out_string(c, "ERROR"); in process_command_ascii()
2952 process_delete_command(c, tokens, ntokens); in process_command_ascii()
2956 process_arithmetic_command(c, tokens, ntokens, 0); in process_command_ascii()
2960 process_debugtime_command(c, tokens, ntokens); in process_command_ascii()
2963 out_string(c, "ERROR"); in process_command_ascii()
2969 process_touch_command(c, tokens, ntokens); in process_command_ascii()
2971 out_string(c, "ERROR"); in process_command_ascii()
2978 process_update_command(c, tokens, ntokens, comm, false); in process_command_ascii()
2985 process_get_command(c, tokens, ntokens, false, false); in process_command_ascii()
2990 process_flush_all_command(c, tokens, ntokens); in process_command_ascii()
2994 process_version_command(c); in process_command_ascii()
2998 process_quit_command(c); in process_command_ascii()
3002 process_lru_crawler_command(c, tokens, ntokens); in process_command_ascii()
3006 process_watch_command(c, tokens, ntokens); in process_command_ascii()
3010 process_verbosity_command(c, tokens, ntokens); in process_command_ascii()
3013 process_lru_command(c, tokens, ntokens); in process_command_ascii()
3017 process_misbehave_command(c); in process_command_ascii()
3022 process_extstore_command(c, tokens, ntokens); in process_command_ascii()
3026 process_refresh_certs_command(c, tokens, ntokens); in process_command_ascii()
3030 conn_set_state(c, conn_closing); in process_command_ascii()
3032 out_string(c, "ERROR"); in process_command_ascii()