summaryrefslogtreecommitdiff
path: root/proxy_internal.c
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2023-03-08 17:30:53 -0800
committerdormando <dormando@rydia.net>2023-03-11 18:19:23 -0800
commitc04701654413719d4abd7645c6d7b3fba4255e85 (patch)
treed415716c5ce3f9290c473bd5e82df4884bd5ab1d /proxy_internal.c
parentaef5b580a5b1528cd418433857adfd7a87f1b4e4 (diff)
downloadmemcached-c04701654413719d4abd7645c6d7b3fba4255e85.tar.gz
meta: N flag changes append/prepend. ms s flag.
Sending 's' flag to metaset now returns the size of the item stored. Useful if you want to know how large an append/prepended item now is. If the 'N' flag is supplied while in append/prepend mode, allows autovivifying (with exptime supplied from N) for append/prepend style keys that don't need headers created first.
Diffstat (limited to 'proxy_internal.c')
-rw-r--r--proxy_internal.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/proxy_internal.c b/proxy_internal.c
index b826181..5484dc7 100644
--- a/proxy_internal.c
+++ b/proxy_internal.c
@@ -389,7 +389,7 @@ static void process_update_cmd(LIBEVENT_THREAD *t, mcp_parser_t *pr, mc_resp *re
return;
}
- int ret = store_item(it, comm, t, NULL, CAS_NO_STALE);
+ int ret = store_item(it, comm, t, NULL, NULL, CAS_NO_STALE);
switch (ret) {
case STORED:
pout_string(resp, "STORED");
@@ -1046,6 +1046,7 @@ static void process_mset_cmd(LIBEVENT_THREAD *t, mcp_parser_t *pr, mc_resp *resp
assert(t != NULL);
char *p = resp->wbuf;
int tlen = 0;
+ rel_time_t exptime = 0;
//WANT_TOKENS_MIN(ntokens, 3);
@@ -1080,10 +1081,20 @@ static void process_mset_cmd(LIBEVENT_THREAD *t, mcp_parser_t *pr, mc_resp *resp
comm = NREAD_ADD;
break;
case 'A': // Append.
- comm = NREAD_APPEND;
+ if (of.vivify) {
+ comm = NREAD_APPENDVIV;
+ exptime = of.autoviv_exptime;
+ } else {
+ comm = NREAD_APPEND;
+ }
break;
case 'P': // Prepend.
- comm = NREAD_PREPEND;
+ if (of.vivify) {
+ comm = NREAD_PREPENDVIV;
+ exptime = of.autoviv_exptime;
+ } else {
+ comm = NREAD_PREPEND;
+ }
break;
case 'R': // Replace.
comm = NREAD_REPLACE;
@@ -1105,7 +1116,7 @@ static void process_mset_cmd(LIBEVENT_THREAD *t, mcp_parser_t *pr, mc_resp *resp
comm = NREAD_CAS;
}
- it = item_alloc(key, nkey, of.client_flags, of.exptime, vlen);
+ it = item_alloc(key, nkey, of.client_flags, exptime, vlen);
if (it == 0) {
if (! item_size_ok(nkey, of.client_flags, vlen)) {
@@ -1160,7 +1171,8 @@ static void process_mset_cmd(LIBEVENT_THREAD *t, mcp_parser_t *pr, mc_resp *resp
}
uint64_t cas = 0;
- int ret = store_item(it, comm, t, &cas, set_stale);
+ int nbytes = 0;
+ int ret = store_item(it, comm, t, &nbytes, &cas, set_stale);
switch (ret) {
case STORED:
memcpy(p, "HD", 2);
@@ -1204,6 +1216,16 @@ static void process_mset_cmd(LIBEVENT_THREAD *t, mcp_parser_t *pr, mc_resp *resp
META_CHAR(p, 'c');
p = itoa_u64(cas, p);
break;
+ case 's':
+ // Get final item size, ie from append/prepend
+ META_CHAR(p, 's');
+ // If the size changed during append/prepend
+ if (nbytes != 0) {
+ p = itoa_u32(nbytes-2, p);
+ } else {
+ p = itoa_u32(it->nbytes-2, p);
+ }
+ break;
}
}
@@ -1436,7 +1458,7 @@ static void process_marithmetic_cmd(LIBEVENT_THREAD *t, mcp_parser_t *pr, mc_res
if (it != NULL) {
memcpy(ITEM_data(it), tmpbuf, vlen);
memcpy(ITEM_data(it) + vlen, "\r\n", 2);
- if (do_store_item(it, NREAD_ADD, t, hv, &cas, CAS_NO_STALE)) {
+ if (do_store_item(it, NREAD_ADD, t, hv, NULL, &cas, CAS_NO_STALE)) {
item_created = true;
} else {
// Not sure how we can get here if we're holding the lock.