Skip to content
Snippets Groups Projects
Commit 1f5cc898 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Speed up txn_is_distributed() check

Speed up txn_is_distributed() check by keeping track of the number of
local rows of the transaction.
parent 204b2384
No related branches found
No related tags found
No related merge requests found
...@@ -121,6 +121,8 @@ txn_rollback_to_svp(struct txn *txn, struct stailq_entry *svp) ...@@ -121,6 +121,8 @@ txn_rollback_to_svp(struct txn *txn, struct stailq_entry *svp)
if (stmt->row != NULL && stmt->row->replica_id == 0) { if (stmt->row != NULL && stmt->row->replica_id == 0) {
assert(txn->n_new_rows > 0); assert(txn->n_new_rows > 0);
txn->n_new_rows--; txn->n_new_rows--;
if (stmt->row->group_id == GROUP_LOCAL)
txn->n_local_rows--;
} }
if (stmt->row != NULL && stmt->row->replica_id != 0) { if (stmt->row != NULL && stmt->row->replica_id != 0) {
assert(txn->n_applier_rows > 0); assert(txn->n_applier_rows > 0);
...@@ -145,6 +147,7 @@ txn_begin(bool is_autocommit) ...@@ -145,6 +147,7 @@ txn_begin(bool is_autocommit)
/* Initialize members explicitly to save time on memset() */ /* Initialize members explicitly to save time on memset() */
stailq_create(&txn->stmts); stailq_create(&txn->stmts);
txn->n_new_rows = 0; txn->n_new_rows = 0;
txn->n_local_rows = 0;
txn->n_applier_rows = 0; txn->n_applier_rows = 0;
txn->is_autocommit = is_autocommit; txn->is_autocommit = is_autocommit;
txn->has_triggers = false; txn->has_triggers = false;
...@@ -221,15 +224,13 @@ bool ...@@ -221,15 +224,13 @@ bool
txn_is_distributed(struct txn *txn) txn_is_distributed(struct txn *txn)
{ {
assert(txn == in_txn()); assert(txn == in_txn());
if (txn->n_new_rows == 0 || txn->n_applier_rows == 0) /**
return false; * Transaction has both new and applier rows, and some of
struct txn_stmt *stmt; * the new rows need to be replicated back to the
/* Search for new non local group rows. */ * server of transaction origin.
stailq_foreach_entry(stmt, &txn->stmts, next) */
if (stmt->row->replica_id == 0 && return (txn->n_new_rows > 0 && txn->n_applier_rows > 0 &&
stmt->space->def->opts.group_id != GROUP_LOCAL) txn->n_new_rows != txn->n_local_rows);
return true;
return false;
} }
/** /**
...@@ -253,10 +254,14 @@ txn_commit_stmt(struct txn *txn, struct request *request) ...@@ -253,10 +254,14 @@ txn_commit_stmt(struct txn *txn, struct request *request)
if (txn_add_redo(stmt, request) != 0) if (txn_add_redo(stmt, request) != 0)
goto fail; goto fail;
assert(stmt->row != NULL); assert(stmt->row != NULL);
if (stmt->row->replica_id == 0) if (stmt->row->replica_id == 0) {
++txn->n_new_rows; ++txn->n_new_rows;
else if (stmt->row->group_id == GROUP_LOCAL)
++txn->n_local_rows;
} else {
++txn->n_applier_rows; ++txn->n_applier_rows;
}
} }
/* /*
* If there are triggers, and they are not disabled, and * If there are triggers, and they are not disabled, and
......
...@@ -142,6 +142,11 @@ struct txn { ...@@ -142,6 +142,11 @@ struct txn {
struct stailq stmts; struct stailq stmts;
/** Number of new rows without an assigned LSN. */ /** Number of new rows without an assigned LSN. */
int n_new_rows; int n_new_rows;
/**
* Number of local new rows, no assigned LSN and
* replication group_id=local (not replicated anywhere).
*/
int n_local_rows;
/** /**
* Number of rows coming from the applier, with an * Number of rows coming from the applier, with an
* already assigned LSN. * already assigned LSN.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment