1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 * Copyright 2010-2012 Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include "internal.h"
19 #include "trace.h"
20
21 LIBCOUCHBASE_API
22 lcb_error_t
lcb_remove3(lcb_t instance,const void * cookie,const lcb_CMDREMOVE * cmd)23 lcb_remove3(lcb_t instance, const void *cookie, const lcb_CMDREMOVE * cmd)
24 {
25 mc_CMDQUEUE *cq = &instance->cmdq;
26 mc_PIPELINE *pl;
27 mc_PACKET *pkt;
28 lcb_error_t err;
29 protocol_binary_request_header hdr;
30
31 if (LCB_KEYBUF_IS_EMPTY(&cmd->key)) {
32 return LCB_EMPTY_KEY;
33 }
34
35 err = mcreq_basic_packet(cq, cmd, &hdr, 0, &pkt, &pl,
36 MCREQ_BASICPACKET_F_FALLBACKOK);
37 if (err != LCB_SUCCESS) {
38 return err;
39 }
40
41
42 hdr.request.datatype = PROTOCOL_BINARY_RAW_BYTES;
43 hdr.request.magic = PROTOCOL_BINARY_REQ;
44 hdr.request.opcode = PROTOCOL_BINARY_CMD_DELETE;
45 hdr.request.cas = lcb_htonll(cmd->cas);
46 hdr.request.opaque = pkt->opaque;
47 hdr.request.bodylen = htonl((lcb_uint32_t)ntohs(hdr.request.keylen));
48
49 pkt->u_rdata.reqdata.cookie = cookie;
50 pkt->u_rdata.reqdata.start = gethrtime();
51 memcpy(SPAN_BUFFER(&pkt->kh_span), hdr.bytes, sizeof(hdr.bytes));
52 LCBTRACE_KV_START(instance->settings, cmd, LCBTRACE_OP_REMOVE, pkt->opaque, pkt->u_rdata.reqdata.span);
53 TRACE_REMOVE_BEGIN(instance, &hdr, cmd);
54 LCB_SCHED_ADD(instance, pl, pkt);
55 return LCB_SUCCESS;
56 }
57
58 LIBCOUCHBASE_API
59 lcb_error_t
lcb_remove(lcb_t instance,const void * cookie,lcb_size_t num,const lcb_remove_cmd_t * const * items)60 lcb_remove(lcb_t instance, const void *cookie, lcb_size_t num,
61 const lcb_remove_cmd_t * const * items)
62 {
63 unsigned ii;
64 lcb_sched_enter(instance);
65
66 for (ii = 0; ii < num; ii++) {
67 lcb_error_t err;
68 const lcb_remove_cmd_t *src = items[ii];
69 lcb_CMDREMOVE dst;
70 memset(&dst, 0, sizeof(dst));
71 dst.key.contig.bytes = src->v.v0.key;
72 dst.key.contig.nbytes = src->v.v0.nkey;
73 dst._hashkey.contig.bytes = src->v.v0.hashkey;
74 dst._hashkey.contig.nbytes = src->v.v0.nhashkey;
75 dst.cas = src->v.v0.cas;
76 err = lcb_remove3(instance, cookie, &dst);
77 if (err != LCB_SUCCESS) {
78 lcb_sched_fail(instance);
79 return err;
80 }
81 }
82 lcb_sched_leave(instance);
83 SYNCMODE_INTERCEPT(instance)
84 }
85