Skip to content

Commit

Permalink
memtx: replace is_pure_insert flag with is_own_change flag
Browse files Browse the repository at this point in the history
The latter flag is a bit wider: it reveals not only inserting
statements after deleting by the same transaction, but also
replacing and deleting statements after all kinds of previois
changes but the same transaction. This extended behavior will
be used in further commits.

Part of #8648
Part of #8654

NO_DOC=refactoring
NO_TEST=refactoring
NO_CHANGELOG=refactoring
  • Loading branch information
alyapunov committed Jun 21, 2023
1 parent 7414973 commit 3cfa675
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
13 changes: 9 additions & 4 deletions src/box/memtx_tx.c
Expand Up @@ -1980,6 +1980,7 @@ memtx_tx_history_add_insert_stmt(struct txn_stmt *stmt,
&old_tuple, mode, &is_own_change);
if (rc != 0)
goto fail;
stmt->is_own_change = is_own_change;

/* Create add_story and replaced_story if necessary. */
add_story = memtx_tx_story_new(space, new_tuple);
Expand Down Expand Up @@ -2022,8 +2023,7 @@ memtx_tx_history_add_insert_stmt(struct txn_stmt *stmt,
else
del_story = memtx_tx_story_get(old_tuple);
memtx_tx_story_link_deleted_by(del_story, stmt);
} else if (is_own_change)
stmt->is_pure_insert = true;
}

/*
* In case of DUP_INSERT there must be no visible replaced tuple. It is
Expand Down Expand Up @@ -2090,6 +2090,9 @@ memtx_tx_history_add_delete_stmt(struct txn_stmt *stmt,

if (tuple_has_flag(old_tuple, TUPLE_IS_DIRTY)) {
del_story = memtx_tx_story_get(old_tuple);
if (del_story->add_stmt != NULL)
stmt->is_own_change =
del_story->add_stmt->txn == stmt->txn;
} else {
assert(stmt->txn != NULL);
del_story = memtx_tx_story_new(space, old_tuple);
Expand Down Expand Up @@ -2313,7 +2316,8 @@ memtx_tx_history_prepare_insert_stmt(struct txn_stmt *stmt)
struct txn_stmt *test_stmt = test->add_stmt;
if (test_stmt->txn == stmt->txn)
continue;
if (test_stmt->is_pure_insert)
if (test_stmt->is_own_change &&
test_stmt->del_story == NULL)
continue;
if (test_stmt->del_story != NULL) {
assert(test_stmt->del_story->add_stmt->txn
Expand Down Expand Up @@ -2388,7 +2392,8 @@ memtx_tx_history_prepare_insert_stmt(struct txn_stmt *stmt)
struct txn_stmt *test_stmt = test->add_stmt;
if (test_stmt->txn == stmt->txn)
continue;
if (test_stmt->is_pure_insert)
if (test_stmt->is_own_change &&
test_stmt->del_story == NULL)
continue;
if (test_stmt->del_story == story)
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/box/txn.c
Expand Up @@ -306,7 +306,7 @@ txn_stmt_new(struct txn *txn)
stmt->engine_savepoint = NULL;
stmt->row = NULL;
stmt->has_triggers = false;
stmt->is_pure_insert = false;
stmt->is_own_change = false;
return stmt;
}

Expand Down
12 changes: 6 additions & 6 deletions src/box/txn.h
Expand Up @@ -302,13 +302,13 @@ struct txn_stmt {
/** on_commit and/or on_rollback list is not empty. */
bool has_triggers;
/*
* `insert` statement is guaranteed not to delete anything
* from the transaction's point of view (i.e., there was a preceding
* `delete` in the scope of the same transaction): no linking to the
* list of `delete` statements is required during preparation of insert
* statements that add preceding stories.
* Flag that shows whether this statement overwrites own transaction
* statement. For example if a transaction makes two replaces of the
* same key, the second statement will be with is_own_change = true.
* Or if a transaction deletes some key and then inserts that key,
* the insertion statement will be with is_own_change = true.
*/
bool is_pure_insert;
bool is_own_change;
/**
* Request type - IPROTO type code
*/
Expand Down

0 comments on commit 3cfa675

Please sign in to comment.