Skip to content

Commit

Permalink
MB-6661: The delete packet returns a cas value
Browse files Browse the repository at this point in the history
This is neccessary for clients to detect an update after a delete
when using the observe command.

Change-Id: Id965bc5ca51a3d4d80f7071939b208111a48a38a
Reviewed-on: http://review.couchbase.org/20856
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
  • Loading branch information
Mike Wiederhold authored and Peter Wansch committed Sep 20, 2012
1 parent 524945f commit 8587311
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
14 changes: 6 additions & 8 deletions daemon/memcached.c
Expand Up @@ -3514,8 +3514,7 @@ static void process_bin_update(conn *c) {
if (c->cmd == PROTOCOL_BINARY_CMD_SET) {
/* @todo fix this for the ASYNC interface! */
settings.engine.v1->remove(settings.engine.v0, c, key, nkey,
memcached_ntohll(req->message.header.request.cas),
c->binary_header.request.vbucket);
&c->cas, c->binary_header.request.vbucket);
}

/* swallow the data line */
Expand Down Expand Up @@ -3628,8 +3627,6 @@ static void process_bin_flush(conn *c) {
}

static void process_bin_delete(conn *c) {
protocol_binary_request_delete* req = binary_get_request(c);

char* key = binary_get_key(c);
size_t nkey = c->binary_header.request.keylen;

Expand All @@ -3653,8 +3650,7 @@ static void process_bin_delete(conn *c) {
stats_prefix_record_delete(key, nkey);
}
ret = settings.engine.v1->remove(settings.engine.v0, c, key, nkey,
memcached_ntohll(req->message.header.request.cas),
c->binary_header.request.vbucket);
&c->cas, c->binary_header.request.vbucket);
}

/* For some reason the SLAB_INCR tries to access this... */
Expand Down Expand Up @@ -4635,7 +4631,8 @@ static void process_update_command(conn *c, mc_extension_token_t *tokens, const
/* Avoid stale data persisting in cache because we failed alloc.
* Unacceptable for SET. Anywhere else too? */
if (store_op == OPERATION_SET) {
settings.engine.v1->remove(settings.engine.v0, c, key, nkey, 0, 0);
uint64_t cas = 0;
settings.engine.v1->remove(settings.engine.v0, c, key, nkey, &cas, 0);
}
}
}
Expand Down Expand Up @@ -4751,8 +4748,9 @@ static char *process_delete_command(conn *c, mc_extension_token_t *tokens,
c->aiostat = ENGINE_SUCCESS;
c->ewouldblock = false;
if (ret == ENGINE_SUCCESS) {
uint64_t cas = 0;
ret = settings.engine.v1->remove(settings.engine.v0, c,
key, nkey, 0, 0);
key, nkey, &cas, 0);
}

/* For some reason the SLAB_INCR tries to access this... */
Expand Down
8 changes: 4 additions & 4 deletions engines/default_engine/default_engine.c
Expand Up @@ -32,7 +32,7 @@ static ENGINE_ERROR_CODE default_item_delete(ENGINE_HANDLE* handle,
const void* cookie,
const void* key,
const size_t nkey,
uint64_t cas,
uint64_t* cas,
uint16_t vbucket);

static void default_item_release(ENGINE_HANDLE* handle, const void *cookie,
Expand Down Expand Up @@ -334,7 +334,7 @@ static ENGINE_ERROR_CODE default_item_delete(ENGINE_HANDLE* handle,
const void* cookie,
const void* key,
const size_t nkey,
uint64_t cas,
uint64_t* cas,
uint16_t vbucket)
{
struct default_engine* engine = get_handle(handle);
Expand All @@ -345,7 +345,7 @@ static ENGINE_ERROR_CODE default_item_delete(ENGINE_HANDLE* handle,
return ENGINE_KEY_ENOENT;
}

if (cas == 0 || cas == item_get_cas(it)) {
if (*cas == 0 || *cas == item_get_cas(it)) {
item_unlink(engine, it);
item_release(engine, it);
} else {
Expand Down Expand Up @@ -792,7 +792,7 @@ static ENGINE_ERROR_CODE default_tap_notify(ENGINE_HANDLE* handle,
return default_flush(handle, cookie, 0);

case TAP_DELETION:
return default_item_delete(handle, cookie, key, nkey, cas, vbucket);
return default_item_delete(handle, cookie, key, nkey, &cas, vbucket);

case TAP_MUTATION:
it = engine->server.cookie->get_engine_specific(cookie);
Expand Down
6 changes: 3 additions & 3 deletions engines/tap_mock_engine/tap_mock_engine.cc
Expand Up @@ -32,7 +32,7 @@ extern "C" {
const void* cookie,
const void* key,
const size_t nkey,
uint64_t cas,
uint64_t* cas,
uint16_t vbucket);

static void item_release(ENGINE_HANDLE* handle, const void *cookie,
Expand Down Expand Up @@ -903,10 +903,10 @@ static ENGINE_ERROR_CODE item_delete(ENGINE_HANDLE* handle,
const void* cookie,
const void* key,
const size_t nkey,
uint64_t cas,
uint64_t* cas,
uint16_t vbucket)
{
return getHandle(handle).itemDelete(cookie, key, nkey, cas, vbucket);
return getHandle(handle).itemDelete(cookie, key, nkey, *cas, vbucket);
}

static void item_release(ENGINE_HANDLE* handle, const void *cookie, item* it)
Expand Down
2 changes: 1 addition & 1 deletion include/memcached/engine.h
Expand Up @@ -256,7 +256,7 @@ extern "C" {
const void* cookie,
const void* key,
const size_t nkey,
uint64_t cas,
uint64_t* cas,
uint16_t vbucket);

/**
Expand Down
2 changes: 1 addition & 1 deletion programs/engine_testapp.c
Expand Up @@ -102,7 +102,7 @@ static ENGINE_ERROR_CODE mock_remove(ENGINE_HANDLE* handle,
const void* cookie,
const void* key,
const size_t nkey,
uint64_t cas,
uint64_t* cas,
uint16_t vbucket)
{
struct mock_engine *me = get_handle(handle);
Expand Down
2 changes: 1 addition & 1 deletion testsuite/basic_engine_testsuite.c
Expand Up @@ -270,7 +270,7 @@ static enum test_result remove_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
uint64_t cas = 0;
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,0, 0) == ENGINE_SUCCESS);
assert(h1->store(h, NULL, test_item, &cas, OPERATION_SET,0) == ENGINE_SUCCESS);
assert(h1->remove(h, NULL, key, strlen(key), cas, 0) == ENGINE_SUCCESS);
assert(h1->remove(h, NULL, key, strlen(key), &cas, 0) == ENGINE_SUCCESS);
item *check_item = test_item;
assert(h1->get(h, NULL, &check_item, key, strlen(key), 0) == ENGINE_KEY_ENOENT);
assert(check_item == NULL);
Expand Down

0 comments on commit 8587311

Please sign in to comment.