Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Petrenko <sergepetrenko@tarantool.org>,
	tarantool-patches@dev.tarantool.org, gorcunov@gmail.com,
	Sergey Ostanevich <sergos@tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH 1/1] replication: set replica ID before _cluster commit
Date: Tue, 27 Jul 2021 00:06:33 +0200	[thread overview]
Message-ID: <8274284e-52a2-6110-2344-b170ecfc3de6@tarantool.org> (raw)
In-Reply-To: <ae2191cb-7cd3-81bd-a610-7f024f586c3a@tarantool.org>

Thanks for the review!

I add Sergey Os. to the review as Sergey P. is on vacation.

>> diff --git a/src/box/alter.cc b/src/box/alter.cc
>> index 89bb5946c..64ba09021 100644
>> --- a/src/box/alter.cc
>> +++ b/src/box/alter.cc
>>   @@ -4280,14 +4244,34 @@ on_replace_dd_cluster(struct trigger *trigger, void *event)
>>                         "updates of instance uuid");
>>                   return -1;
>>               }
>> -        } else {
>> -            struct trigger *on_commit;
>> -            on_commit = txn_alter_trigger_new(register_replica,
>> -                              new_tuple);
>> -            if (on_commit == NULL)
>> -                return -1;
>> -            txn_stmt_on_commit(stmt, on_commit);
>> +            return 0;
>> +        }
>> +        /*
>> +         * With read-views enabled there might be already a replica
>> +         * whose registration is in progress in another transaction.
>> +         * With the same replica ID.
>> +         */
>> +        if (replica_by_id(replica_id) != NULL) {
>> +            diag_set(ClientError, ER_UNSUPPORTED, "Tarantool",
>> +                 "more than 1 replica with the same ID");
>> +            return -1;
>>           }
>> ====================
>>
>> I couldn't test this check because of the bug in mvcc:
>> https://github.com/tarantool/tarantool/issues/6246
>>
>> ====================
> 
> I don't understand how this could happen
> (I mean the if branch being taken).
> 
> Would you mind explaining?

When MVCC will be fixed, it can happen that there are 2 transactions
trying to change _cluster.

If they add the same replica ID and the second transaction starts
before the first one is finished, it is going to see
replicaset.replica_by_id[new_id] != NULL from the first transaction.
Even before any of them is committed.

Hence it can't add its own new struct replica into the same place nor
can it touch the struct replica from the foreign transaction.

Therefore the only choice is to fail with an error.

The same would happen if MVCC is turned off - then space:insert()
would fail with duplicate tuple error right away due to dirty reads.

>> diff --git a/src/box/replication.h b/src/box/replication.h
>> index 57e0f10ae..5d1fa1255 100644
>> --- a/src/box/replication.h
>> +++ b/src/box/replication.h
>> @@ -360,6 +360,10 @@ replica_by_uuid(const struct tt_uuid *uuid);
>>   struct replica *
>>   replica_by_id(uint32_t replica_id);
>>   +/** Find the smallest free replica ID in the available range. */
> 
> 
> nit: free -> empty / unoccupied

Oxford dictionary says 'free' meanings are, among others,
"not busy", "not being used", "not blocked", "ready to give".
https://www.oxfordlearnersdictionaries.com/definition/english/free_1?q=free

Which means the current word is fine. But I don't mind to
change it:

====================
@@ -360,7 +360,7 @@ replica_by_uuid(const struct tt_uuid *uuid);
 struct replica *
 replica_by_id(uint32_t replica_id);
 
-/** Find the smallest free replica ID in the available range. */
+/** Find the smallest empty replica ID in the available range. */
 int
 replica_find_new_id(uint32_t *replica_id);

  reply	other threads:[~2021-07-26 22:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-25 16:53 Vladislav Shpilevoy via Tarantool-patches
2021-07-25 18:31 ` Sergey Petrenko via Tarantool-patches
2021-07-26 22:06   ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-07-27 12:13 ` Cyrill Gorcunov via Tarantool-patches
2021-07-27 15:10 ` Sergey Ostanevich via Tarantool-patches
2021-07-27 21:53   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-28 22:20     ` Sergey Ostanevich via Tarantool-patches
2021-07-29 21:42 ` Vladislav Shpilevoy via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8274284e-52a2-6110-2344-b170ecfc3de6@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=sergepetrenko@tarantool.org \
    --cc=sergos@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/1] replication: set replica ID before _cluster commit' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox