Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>, gorcunov@gmail.com
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v3 07/12] box: introduce `box.ctl.demote`
Date: Wed, 4 Aug 2021 16:08:16 +0300	[thread overview]
Message-ID: <b7c5b181-9a16-99d8-fda8-dc1b9684d087@tarantool.org> (raw)
In-Reply-To: <5ca8fae1-c231-8903-a5d6-cc1aa03a9ea5@tarantool.org>



04.08.2021 02:25, Vladislav Shpilevoy пишет:
> Thanks for the fixes!
>
> See 3 comments below.
>
>> diff --git a/src/box/iproto.cc b/src/box/iproto.cc
>> index 3ed641eea..5cc69b77f 100644
>> --- a/src/box/iproto.cc
>> +++ b/src/box/iproto.cc
>> @@ -557,6 +558,20 @@ struct iproto_connection
>>       struct iproto_thread *iproto_thread;
>>   };
>>
>> +#ifdef NDEBUG
>> +#define iproto_write_error(fd, e, schema_version, sync)                         \
>> +    iproto_do_write_error(fd, e, schema_version, sync);
>> +#else
>> +#define iproto_write_error(fd, e, schema_version, sync) do {                    \
>> +    int flags = fcntl(fd, F_GETFL, 0);                                      \
>> +    if (flags >= 0)                                                         \
>> +        fcntl(fd, F_SETFL, flags & (~O_NONBLOCK));                      \
>> +    iproto_do_write_error(fd, e, schema_version, sync);                     \
>> +    if (flags >= 0)                                                         \
>> +        fcntl(fd, F_SETFL, flags);                                      \
>> +} while (0);
>> +#endif
> 1. Why didn't you do this right in iproto_write_error? Why do
> you need to change iproto.cc code at all?

I've found a commit way back from 2017 where you removed the
fcntl dependency from xrow. I didn't want to introduce it again.

>> diff --git a/src/box/relay.cc b/src/box/relay.cc
>> index 805b5e7ff..2947468ba 100644
>> --- a/src/box/relay.cc
>> +++ b/src/box/relay.cc
>> @@ -444,20 +444,20 @@ relay_initial_join(int fd, uint64_t sync, struct vclock *vclock,
>>        */
>>       if (replica_version_id > 0) {
>>           /* Mark the beginning of the metadata stream. */
>> -        row.type = IPROTO_JOIN_META;
>> -        coio_write_xrow(&relay->io, &row);
>> +        xrow_encode_type(&row, IPROTO_JOIN_META);
>> +        xstream_write(&relay->stream, &row);
> 2. Why do you use xtream_write? And why coio_write_xrow just a few lines
> above works just fine then?

xstream write is basically a shortcut for "row.sync = sync ; 
coio_write_xrow"

Writing row.sync = sync before every coio_write_xrow looked rather ugly 
IMO, that's
why I changed it.

I need to reassign row.sync before each despatch because xrow_encode_* 
functions usually
reset all the xrow fields to 0.

>
>>           xrow_encode_raft(&row, &fiber()->gc, &raft_req);
>> -        coio_write_xrow(&relay->io, &row);
>> +        xstream_write(&relay->stream, &row);
>>
>>           char body[XROW_SYNCHRO_BODY_LEN_MAX];
>>           xrow_encode_synchro(&row, body, &req);
>>           row.replica_id = req.replica_id;
>> -        coio_write_xrow(&relay->io, &row);
>> +        xstream_write(&relay->stream, &row);
>>
>>           /* Mark the end of the metadata stream. */
>> -        row.type = IPROTO_JOIN_SNAPSHOT;
>> -        coio_write_xrow(&relay->io, &row);
>> +        xrow_encode_type(&row, IPROTO_JOIN_SNAPSHOT);
>> +        xstream_write(&relay->stream, &row);
>>       }
>> diff --git a/src/box/raft.c b/src/box/raft.c
>> index f8d13aa32..bc69f7f1b 100644
>> --- a/src/box/raft.c
>> +++ b/src/box/raft.c
>> @@ -83,6 +83,24 @@ box_raft_request_to_msg(const struct raft_request *req, struct raft_msg *msg)
>>       };
>>   }
>>
>> +static void
>> +box_raft_update_synchro_queue(struct raft *raft)
>> +{
>> +    assert(raft == box_raft());
>> +    if (raft->state != RAFT_STATE_LEADER)
>> +        return;
>> +    int rc = 0;
>> +    uint32_t errcode = 0;
>> +    do {
>> +        rc = box_promote_qsync();
>> +        if (rc != 0) {
>> +            struct error *err = diag_last_error(diag_get());
>> +            errcode = box_error_code(err);
>> +            diag_log();
>> +        }
> 3. Could it stop being a leader during the retries? Would it
> make sense to continue them then?

Thanks for noticing!

Check out the diff:

===============================
diff --git a/src/box/box.cc b/src/box/box.cc
index 4882b76a4..c7a972992 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1698,6 +1698,10 @@ box_promote_qsync(void)
         int64_t wait_lsn = box_wait_limbo_acked(TIMEOUT_INFINITY);
         if (wait_lsn < 0)
                 return -1;
+       if (raft->state != RAFT_STATE_LEADER) {
+               diag_set(ClientError, ER_NOT_LEADER, raft->leader);
+               return -1;
+       }
         box_issue_promote(txn_limbo.owner_id, wait_lsn);
         return 0;
  }
diff --git a/src/box/errcode.h b/src/box/errcode.h
index d2854677f..906cd28b2 100644
--- a/src/box/errcode.h
+++ b/src/box/errcode.h
@@ -278,6 +278,7 @@ struct errcode_record {
         /*223 */_(ER_INTERFERING_PROMOTE,       "Instance with replica 
id %u was promoted first") \
         /*224 */_(ER_ELECTION_DISABLED,         "Elections were turned 
off")\
         /*225 */_(ER_TXN_ROLLBACK,              "Transaction was rolled 
back") \
+       /*226 */_(ER_NOT_LEADER,                "The instance is not a 
leader. New leader is %u")\

  /*
   * !IMPORTANT! Please follow instructions at start of the file

===============================
>
>> +    } while (rc != 0 && errcode == ER_QUORUM_WAIT && !fiber_is_cancelled());
>> +}

-- 
Serge Petrenko


  reply	other threads:[~2021-08-04 13:08 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 22:12 [Tarantool-patches] [PATCH v3 00/12] forbid implicit limbo ownership transition Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 01/12] replication: always send raft state to subscribers Serge Petrenko via Tarantool-patches
2021-07-04 12:12   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-09  9:43     ` Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 02/12] txn_limbo: fix promote term filtering Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 03/12] raft: refactor raft_new_term() Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 04/12] box: make promote always bump the term Serge Petrenko via Tarantool-patches
2021-07-04 12:14   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-14 18:26     ` Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 05/12] replication: forbid implicit limbo owner transition Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 06/12] box: allow calling promote on a candidate Serge Petrenko via Tarantool-patches
2021-07-04 12:14   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-14 18:26     ` Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 07/12] box: introduce `box.ctl.demote` Serge Petrenko via Tarantool-patches
2021-07-04 12:27   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-14 18:28     ` Serge Petrenko via Tarantool-patches
2021-07-21 23:28       ` Vladislav Shpilevoy via Tarantool-patches
2021-07-23  7:44         ` Sergey Petrenko via Tarantool-patches
2021-07-26 23:50           ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29 20:56             ` Sergey Petrenko via Tarantool-patches
2021-08-01 16:19               ` Vladislav Shpilevoy via Tarantool-patches
2021-08-03  7:56                 ` Serge Petrenko via Tarantool-patches
2021-08-03 23:25                   ` Vladislav Shpilevoy via Tarantool-patches
2021-08-04 13:08                     ` Serge Petrenko via Tarantool-patches [this message]
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 08/12] txn_limbo: persist the latest effective promote in snapshot Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 09/12] replication: encode version in JOIN request Serge Petrenko via Tarantool-patches
2021-07-04 12:27   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-14 18:28     ` Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 10/12] replication: add META stage to JOIN Serge Petrenko via Tarantool-patches
2021-07-04 12:28   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-14 18:28     ` Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 11/12] replication: send latest effective promote in initial join Serge Petrenko via Tarantool-patches
2021-07-04 12:28   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-14 18:28     ` Serge Petrenko via Tarantool-patches
2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 12/12] replication: send current Raft term in join response Serge Petrenko via Tarantool-patches
2021-07-04 12:29   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-14 18:28     ` Serge Petrenko via Tarantool-patches
2021-08-04 22:41 ` [Tarantool-patches] [PATCH v3 00/12] forbid implicit limbo ownership transition Vladislav Shpilevoy via Tarantool-patches
2021-08-06  7:54   ` Vitaliia Ioffe via Tarantool-patches
2021-08-06  8:31 ` Kirill Yukhin via Tarantool-patches
2021-08-08 10:46   ` Vladislav Shpilevoy via Tarantool-patches
2021-08-09  7:14     ` Kirill Yukhin 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=b7c5b181-9a16-99d8-fda8-dc1b9684d087@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=sergepetrenko@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v3 07/12] box: introduce `box.ctl.demote`' \
    /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