Skip to content

Commit f7a520e

Browse files
committed
box: don't apply space upgrade func to DML result except for DELETE
There's no need to apply a space upgrade function to the tuple returned by INSERT, REPLACE, UPDATE, or UPSERT, because it must match the new format anyway. We only need to process tuples returned by DELETE requests. That being said, let's move the result processing from box_process_rw() to memtx_space_execute_delete(). Note, we don't need to patch vinyl_space_execute_delete(), because in Vinyl DELETE doesn't return the deleted tuple. Follow-up commit 21e2def ("box: introduce result processor"). NO_DOC=refactoring NO_TEST=refactoring NO_CHANGELOG=refactoring
1 parent 3698d27 commit f7a520e

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/box/box.cc

+2-9
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ box_process_rw(struct request *request, struct space *space,
307307
bool return_tuple = false;
308308
struct txn *txn = in_txn();
309309
bool is_autocommit = txn == NULL;
310-
struct result_processor res_proc;
311-
int rc;
312310
if (is_autocommit && (txn = txn_begin()) == NULL)
313311
return -1;
314312
assert(iproto_type_is_dml(request->type));
@@ -317,19 +315,14 @@ box_process_rw(struct request *request, struct space *space,
317315
goto rollback;
318316
if (txn_begin_stmt(txn, space, request->type) != 0)
319317
goto rollback;
320-
result_process_prepare(&res_proc, space);
321-
rc = space_execute_dml(space, txn, request, &tuple);
322-
if (result == NULL)
323-
tuple = NULL;
324-
result_process_perform(&res_proc, &rc, &tuple);
325-
if (rc != 0) {
318+
if (space_execute_dml(space, txn, request, &tuple) != 0) {
326319
txn_rollback_stmt(txn);
327320
goto rollback;
328321
}
329322
if (result != NULL)
330323
*result = tuple;
331324

332-
return_tuple = tuple != NULL;
325+
return_tuple = result != NULL && tuple != NULL;
333326
if (return_tuple) {
334327
/*
335328
* Pin the tuple locally before the commit,

src/box/memtx_space.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "sequence.h"
4646
#include "memtx_tuple_compression.h"
4747
#include "schema.h"
48+
#include "result.h"
4849

4950
/*
5051
* Yield every 1K tuples while building a new index or checking
@@ -437,8 +438,8 @@ memtx_space_execute_delete(struct space *space, struct txn *txn,
437438
if (memtx_space_replace_tuple(space, stmt, old_tuple, NULL,
438439
DUP_REPLACE_OR_INSERT) != 0)
439440
return -1;
440-
*result = stmt->old_tuple;
441-
return 0;
441+
*result = result_process(space, stmt->old_tuple);
442+
return *result == NULL ? -1 : 0;
442443
}
443444

444445
static int

src/box/result.h

+17
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ result_process_perform(struct result_processor *p, int *rc,
6060
space_upgrade_unref(p->upgrade);
6161
}
6262

63+
/**
64+
* A shortcut for
65+
*
66+
* int rc = 0;
67+
* struct result_processor res_proc;
68+
* result_process_prepare(&res_proc, space);
69+
* result_process_perform(&res_proc, &rc, &tuple);
70+
*/
71+
static inline struct tuple *
72+
result_process(struct space *space, struct tuple *tuple)
73+
{
74+
if (unlikely(space->upgrade != NULL))
75+
return space_upgrade_apply(space->upgrade, tuple);
76+
else
77+
return tuple;
78+
}
79+
6380
#if defined(__cplusplus)
6481
} /* extern "C" */
6582
#endif /* defined(__cplusplus) */

0 commit comments

Comments
 (0)