From 07ec816656156efe55b32b4928825cbc69d0a6be Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja.osipov@gmail.com>
Date: Thu, 14 Jul 2011 23:32:39 +0400
Subject: [PATCH] Implement blueprint delete-box-return-tuple

In DELETE, support flag BOX_RETURN_TUPLE.

A community request from Alexandre Kalendarev.

In the new DELETE (21) command, one can specify
delete flags. If BOX_RETURN_TUPLE is set, return
the old (deleted) tuple to the client.

Update doc/box-protocol.txt to reflect the new
(21) DELETE and its extended response format.
---
 doc/box-protocol.txt | 10 ++++++----
 mod/box/box.m        |  6 +++++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/doc/box-protocol.txt b/doc/box-protocol.txt
index 8dd7359601..a8fc296b4a 100644
--- a/doc/box-protocol.txt
+++ b/doc/box-protocol.txt
@@ -44,7 +44,7 @@
 ; - 13    -- <insert>
 ; - 17    -- <select>
 ; - 19    -- <update>
-; - 20    -- <delete>
+; - 21    -- <delete>
 ; - 65280 -- <ping>
 ; This list is sparse since a number of old commands
 ; were deprecated and removed.
@@ -270,19 +270,21 @@
 <update_response_body> ::= <insert_response_body>
 
 ;
-; <delete>, request <type> = 20
+; <delete>, request <type> = 21
 ; Similarly to updates, <delete> always uses the
 ; primary key.
 ;
 
-<delete_request_body> ::= <namespace_no><tuple>
+<delete_request_body> ::= <namespace_no><flags><tuple>
 
 ;
 ; <delete> returns the number of deleted tuples.
 ; Currently it's always either 0 or 1.
+; If BOX_RETURN_TUPLE is specified, and there is an old
+; tuple, (count > 0), DELETE returns the deleted tuple.
 ;
 
-<delete_response_body> ::= <count>
+<delete_response_body> ::= <count> | <count><fq_tuple>
 
 ;
 ; The server response, in addition to response header and body,
diff --git a/mod/box/box.m b/mod/box/box.m
index dcd1532fbe..429c218aae 100644
--- a/mod/box/box.m
+++ b/mod/box/box.m
@@ -657,8 +657,12 @@ prepare_delete(struct box_txn *txn, void *key)
 		tuples_affected = 1;
 	}
 
-	if (!(txn->flags & BOX_QUIET))
+	if (!(txn->flags & BOX_QUIET)) {
 		add_iov_dup(&tuples_affected, sizeof(tuples_affected));
+
+		if (txn->old_tuple && (txn->flags & BOX_RETURN_TUPLE))
+			tuple_add_iov(txn, txn->old_tuple);
+	}
 }
 
 static void
-- 
GitLab