Hi! Here are a few cleanups for wal and txn_limbo. The txn_limbo cleanups shrinks code while wal modes rework allows to save a pointer. I made the series during work on issue 5447 branch gorcunov/gh-5447-cleanup Cyrill Gorcunov (3): wal: sanitize wal_mode txn_limbo: simplify owner migration condition txn_limbo: simplify txn_limbo_ack src/box/txn_limbo.c | 6 ++---- src/box/wal.c | 6 +++++- src/box/wal.h | 27 +++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 9 deletions(-) base-commit: d2bd451095890c1caaedb2d1c2fc3a49c554915e -- 2.30.2
- there is no need to set WAN_NONE to 0 explicitly - add comments about modes - there is no need to carry NULL in wal_mode_STRS - use designated assignment in wal_mode_STRS Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- src/box/wal.c | 6 +++++- src/box/wal.h | 27 +++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/box/wal.c b/src/box/wal.c index 34af0bda6..05f30769a 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -55,7 +55,11 @@ enum { WAL_FALLOCATE_LEN = 1024 * 1024, }; -const char *wal_mode_STRS[] = { "none", "write", "fsync", NULL }; +const char *wal_mode_STRS[WAL_MODE_MAX] = { + [WAL_NONE] = "none", + [WAL_WRITE] = "write", + [WAL_FSYNC] = "fsync", +}; int wal_dir_lock = -1; diff --git a/src/box/wal.h b/src/box/wal.h index a8a16ba2e..470aa1cc8 100644 --- a/src/box/wal.h +++ b/src/box/wal.h @@ -41,7 +41,29 @@ struct fiber; struct wal_writer; struct tt_uuid; -enum wal_mode { WAL_NONE = 0, WAL_WRITE, WAL_FSYNC, WAL_MODE_MAX }; +enum wal_mode { + /** + * Do not write data at all. + */ + WAL_NONE, + + /** + * Write without waiting the data to be + * flushed to the storage device. + */ + WAL_WRITE, + + /** + * Write data and wait the record to be + * flushed to the storage device. + */ + WAL_FSYNC, + + WAL_MODE_MAX +}; + +/** String constants for the supported modes. */ +extern const char *wal_mode_STRS[WAL_MODE_MAX]; enum { /** @@ -52,9 +74,6 @@ enum { WAL_ROWS_PER_YIELD = 1 << 15, }; -/** String constants for the supported modes. */ -extern const char *wal_mode_STRS[]; - extern int wal_dir_lock; #if defined(__cplusplus) -- 2.30.2
When limbo owner is about to change the state we should check if there are some pending transactions which are not yet processed, iow if queue is empty. No need to test if current limbo owner is zero. The owner is set to zero once -- when limbo is created during initialization. After all I think even if owner would ever zero and we're about to change it the queue simply must be empty, that is the only safe state. Acked-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- src/box/txn_limbo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index addcb0f97..2a10bd0ae 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -94,8 +94,7 @@ txn_limbo_append(struct txn_limbo *limbo, uint32_t id, struct txn *txn) id = instance_id; bool make_ro = false; if (limbo->owner_id != id) { - if (limbo->owner_id == REPLICA_ID_NIL || - rlist_empty(&limbo->queue)) { + if (rlist_empty(&limbo->queue)) { limbo->owner_id = id; limbo->confirmed_lsn = 0; if (id != instance_id) -- 2.30.2
There is no need to test @confirm_lsn at all because even with value -1 we're to continue iterating the queue. Lets drop it and save a branch. I keep "continue" here to be consistent with other "if"s. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- src/box/txn_limbo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index 2a10bd0ae..227b74764 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -505,8 +505,7 @@ txn_limbo_ack(struct txn_limbo *limbo, uint32_t replica_id, int64_t lsn) */ if (!txn_has_flag(e->txn, TXN_WAIT_ACK)) { assert(e->lsn == -1); - if (confirm_lsn == -1) - continue; + continue; } else if (e->lsn <= prev_lsn) { continue; } else if (++e->ack_count < replication_synchro_quorum) { -- 2.30.2
There is no need to test @confirm_lsn since we're continue the list traversing in any case. I keep "continue" here to be consistent with other "if"s. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- src/box/txn_limbo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index 0ac8fff25..c07db3025 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -707,8 +707,7 @@ txn_limbo_on_parameters_change(struct txn_limbo *limbo) assert(e->ack_count <= VCLOCK_MAX); if (!txn_has_flag(e->txn, TXN_WAIT_ACK)) { assert(e->lsn == -1); - if (confirm_lsn == -1) - continue; + continue; } else if (e->ack_count < replication_synchro_quorum) { continue; } else { -- 2.30.2
Hi! Thanks for the patch! > diff --git a/src/box/wal.h b/src/box/wal.h > index a8a16ba2e..470aa1cc8 100644 > --- a/src/box/wal.h > +++ b/src/box/wal.h > @@ -41,7 +41,29 @@ struct fiber; > struct wal_writer; > struct tt_uuid; > > -enum wal_mode { WAL_NONE = 0, WAL_WRITE, WAL_FSYNC, WAL_MODE_MAX }; > +enum wal_mode { > + /** > + * Do not write data at all. > + */ > + WAL_NONE, > + > + /** > + * Write without waiting the data to be > + * flushed to the storage device. > + */ > + WAL_WRITE, > + > + /** > + * Write data and wait the record to be > + * flushed to the storage device. > + */ > + WAL_FSYNC, > + > + WAL_MODE_MAX > +}; > + > +/** String constants for the supported modes. */ > +extern const char *wal_mode_STRS[WAL_MODE_MAX]; 1. Why do you need to declare in the header the array size? The old version with [] was just fine. And less places to change if becomes necessary. 2. Please, keep the global variable where it was. We usually group global variable declarations. It was grouped with wal_dir_lock below. > enum { > /** > @@ -52,9 +74,6 @@ enum { > WAL_ROWS_PER_YIELD = 1 << 15, > }; > > -/** String constants for the supported modes. */ > -extern const char *wal_mode_STRS[]; > - > extern int wal_dir_lock; > > #if defined(__cplusplus) >
On Fri, Apr 23, 2021 at 10:57:11PM +0200, Vladislav Shpilevoy wrote: > Hi! Thanks for the patch! > > > diff --git a/src/box/wal.h b/src/box/wal.h > > index a8a16ba2e..470aa1cc8 100644 > > --- a/src/box/wal.h > > +++ b/src/box/wal.h > > @@ -41,7 +41,29 @@ struct fiber; > > struct wal_writer; > > struct tt_uuid; > > > > -enum wal_mode { WAL_NONE = 0, WAL_WRITE, WAL_FSYNC, WAL_MODE_MAX }; > > +enum wal_mode { > > + /** > > + * Do not write data at all. > > + */ > > + WAL_NONE, > > + > > + /** > > + * Write without waiting the data to be > > + * flushed to the storage device. > > + */ > > + WAL_WRITE, > > + > > + /** > > + * Write data and wait the record to be > > + * flushed to the storage device. > > + */ > > + WAL_FSYNC, > > + > > + WAL_MODE_MAX > > +}; > > + > > +/** String constants for the supported modes. */ > > +extern const char *wal_mode_STRS[WAL_MODE_MAX]; > > 1. Why do you need to declare in the header the array size? > The old version with [] was just fine. And less places to change > if becomes necessary. If the size is known better to point it explicitly. Thus when you read this code you will notise the array size (yes, it doesn't matter from compiler pov if we declare it as a double pointer but still). But fine I'll leave this declaration untouched. > > 2. Please, keep the global variable where it was. We usually group > global variable declarations. It was grouped with wal_dir_lock > below. --- From: Cyrill Gorcunov <gorcunov@gmail.com> Date: Fri, 16 Apr 2021 15:54:52 +0300 Subject: [PATCH] wal: sanitize wal_mode - there is no need to set WAN_NONE to 0 explicitly - add comments about modes - there is no need to carry NULL in wal_mode_STRS - use designated assignment in wal_mode_STRS Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- src/box/wal.c | 6 +++++- src/box/wal.h | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/box/wal.c b/src/box/wal.c index 5b6200b81..6468df884 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -55,7 +55,11 @@ enum { WAL_FALLOCATE_LEN = 1024 * 1024, }; -const char *wal_mode_STRS[] = { "none", "write", "fsync", NULL }; +const char *wal_mode_STRS[WAL_MODE_MAX] = { + [WAL_NONE] = "none", + [WAL_WRITE] = "write", + [WAL_FSYNC] = "fsync", +}; int wal_dir_lock = -1; diff --git a/src/box/wal.h b/src/box/wal.h index a8a16ba2e..36fcd39bd 100644 --- a/src/box/wal.h +++ b/src/box/wal.h @@ -41,7 +41,26 @@ struct fiber; struct wal_writer; struct tt_uuid; -enum wal_mode { WAL_NONE = 0, WAL_WRITE, WAL_FSYNC, WAL_MODE_MAX }; +enum wal_mode { + /** + * Do not write data at all. + */ + WAL_NONE, + + /** + * Write without waiting the data to be + * flushed to the storage device. + */ + WAL_WRITE, + + /** + * Write data and wait the record to be + * flushed to the storage device. + */ + WAL_FSYNC, + + WAL_MODE_MAX +}; enum { /** -- 2.30.2
24.04.2021 00:17, Cyrill Gorcunov via Tarantool-patches пишет: > On Fri, Apr 23, 2021 at 10:57:11PM +0200, Vladislav Shpilevoy wrote: >> Hi! Thanks for the patch! >> >>> diff --git a/src/box/wal.h b/src/box/wal.h >>> index a8a16ba2e..470aa1cc8 100644 >>> --- a/src/box/wal.h >>> +++ b/src/box/wal.h >>> @@ -41,7 +41,29 @@ struct fiber; >>> struct wal_writer; >>> struct tt_uuid; >>> >>> -enum wal_mode { WAL_NONE = 0, WAL_WRITE, WAL_FSYNC, WAL_MODE_MAX }; >>> +enum wal_mode { >>> + /** >>> + * Do not write data at all. >>> + */ >>> + WAL_NONE, >>> + >>> + /** >>> + * Write without waiting the data to be >>> + * flushed to the storage device. >>> + */ >>> + WAL_WRITE, >>> + >>> + /** >>> + * Write data and wait the record to be >>> + * flushed to the storage device. >>> + */ >>> + WAL_FSYNC, >>> + >>> + WAL_MODE_MAX >>> +}; >>> + >>> +/** String constants for the supported modes. */ >>> +extern const char *wal_mode_STRS[WAL_MODE_MAX]; >> 1. Why do you need to declare in the header the array size? >> The old version with [] was just fine. And less places to change >> if becomes necessary. > If the size is known better to point it explicitly. Thus when you > read this code you will notise the array size (yes, it doesn't > matter from compiler pov if we declare it as a double pointer > but still). But fine I'll leave this declaration untouched. > >> 2. Please, keep the global variable where it was. We usually group >> global variable declarations. It was grouped with wal_dir_lock >> below. > --- > From: Cyrill Gorcunov <gorcunov@gmail.com> > Date: Fri, 16 Apr 2021 15:54:52 +0300 > Subject: [PATCH] wal: sanitize wal_mode > > - there is no need to set WAN_NONE to 0 explicitly > - add comments about modes > - there is no need to carry NULL in wal_mode_STRS > - use designated assignment in wal_mode_STRS > > Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> > --- > src/box/wal.c | 6 +++++- > src/box/wal.h | 21 ++++++++++++++++++++- > 2 files changed, 25 insertions(+), 2 deletions(-) > > diff --git a/src/box/wal.c b/src/box/wal.c > index 5b6200b81..6468df884 100644 > --- a/src/box/wal.c > +++ b/src/box/wal.c > @@ -55,7 +55,11 @@ enum { > WAL_FALLOCATE_LEN = 1024 * 1024, > }; > > -const char *wal_mode_STRS[] = { "none", "write", "fsync", NULL }; > +const char *wal_mode_STRS[WAL_MODE_MAX] = { > + [WAL_NONE] = "none", > + [WAL_WRITE] = "write", > + [WAL_FSYNC] = "fsync", > +}; > > int wal_dir_lock = -1; > > diff --git a/src/box/wal.h b/src/box/wal.h > index a8a16ba2e..36fcd39bd 100644 > --- a/src/box/wal.h > +++ b/src/box/wal.h > @@ -41,7 +41,26 @@ struct fiber; > struct wal_writer; > struct tt_uuid; > > -enum wal_mode { WAL_NONE = 0, WAL_WRITE, WAL_FSYNC, WAL_MODE_MAX }; > +enum wal_mode { > + /** > + * Do not write data at all. > + */ > + WAL_NONE, > + > + /** > + * Write without waiting the data to be > + * flushed to the storage device. > + */ > + WAL_WRITE, > + > + /** > + * Write data and wait the record to be > + * flushed to the storage device. > + */ > + WAL_FSYNC, > + > + WAL_MODE_MAX > +}; > Thanks for the patch! I'd leave an explicit WAL_NONE = 0. I didn't know that enums start at zero, TBH. This would be more readable IMO. Up to you. > enum { > /** -- Serge Petrenko
19.04.2021 11:37, Cyrill Gorcunov пишет:
> When limbo owner is about to change the state we should check
> if there are some pending transactions which are not yet processed,
> iow if queue is empty. No need to test if current limbo owner
> is zero. The owner is set to zero once -- when limbo is created
> during initialization.
>
> After all I think even if owner would ever zero and we're about
> to change it the queue simply must be empty, that is the only
> safe state.
>
> Acked-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> ---
> src/box/txn_limbo.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
> index addcb0f97..2a10bd0ae 100644
> --- a/src/box/txn_limbo.c
> +++ b/src/box/txn_limbo.c
> @@ -94,8 +94,7 @@ txn_limbo_append(struct txn_limbo *limbo, uint32_t id, struct txn *txn)
> id = instance_id;
> bool make_ro = false;
> if (limbo->owner_id != id) {
> - if (limbo->owner_id == REPLICA_ID_NIL ||
> - rlist_empty(&limbo->queue)) {
> + if (rlist_empty(&limbo->queue)) {
> limbo->owner_id = id;
> limbo->confirmed_lsn = 0;
> if (id != instance_id)
Thanks for the patch! LGTM.
--
Serge Petrenko
19.04.2021 11:37, Cyrill Gorcunov пишет:
> There is no need to test @confirm_lsn at all because
> even with value -1 we're to continue iterating the queue.
> Lets drop it and save a branch.
>
> I keep "continue" here to be consistent with other "if"s.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> ---
> src/box/txn_limbo.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
> index 2a10bd0ae..227b74764 100644
> --- a/src/box/txn_limbo.c
> +++ b/src/box/txn_limbo.c
> @@ -505,8 +505,7 @@ txn_limbo_ack(struct txn_limbo *limbo, uint32_t replica_id, int64_t lsn)
> */
> if (!txn_has_flag(e->txn, TXN_WAIT_ACK)) {
> assert(e->lsn == -1);
> - if (confirm_lsn == -1)
> - continue;
> + continue;
> } else if (e->lsn <= prev_lsn) {
> continue;
> } else if (++e->ack_count < replication_synchro_quorum) {
Thanks! LGTM.
--
Serge Petrenko
22.04.2021 14:34, Cyrill Gorcunov пишет:
> There is no need to test @confirm_lsn since we're
> continue the list traversing in any case.
>
> I keep "continue" here to be consistent with other "if"s.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> ---
> src/box/txn_limbo.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
> index 0ac8fff25..c07db3025 100644
> --- a/src/box/txn_limbo.c
> +++ b/src/box/txn_limbo.c
> @@ -707,8 +707,7 @@ txn_limbo_on_parameters_change(struct txn_limbo *limbo)
> assert(e->ack_count <= VCLOCK_MAX);
> if (!txn_has_flag(e->txn, TXN_WAIT_ACK)) {
> assert(e->lsn == -1);
> - if (confirm_lsn == -1)
> - continue;
> + continue;
> } else if (e->ack_count < replication_synchro_quorum) {
> continue;
> } else {
LGTM.
--
Serge Petrenko
Hi! Thanks for the patchset! LGTM.
On Sun, Apr 25, 2021 at 11:08:25AM +0300, Serge Petrenko wrote: > > +enum wal_mode { > > + /** > > + * Do not write data at all. > > + */ > > + WAL_NONE, > > + ... > Thanks for the patch! > > I'd leave an explicit WAL_NONE = 0. > I didn't know that enums start at zero, TBH. Yeah, this is a part of language standart. > This would be more readable IMO. I'll make it so and force push. Thanks a huge for review, guys!
25.04.2021 16:26, Cyrill Gorcunov пишет:
> On Sun, Apr 25, 2021 at 11:08:25AM +0300, Serge Petrenko wrote:
>>> +enum wal_mode {
>>> + /**
>>> + * Do not write data at all.
>>> + */
>>> + WAL_NONE,
>>> +
> ...
>> Thanks for the patch!
>>
>> I'd leave an explicit WAL_NONE = 0.
>> I didn't know that enums start at zero, TBH.
> Yeah, this is a part of language standart.
>
>> This would be more readable IMO.
> I'll make it so and force push. Thanks a huge for review, guys!
Thanks! Please, update the commit message:
"- there is no need to set WAN_NONE to 0 explicitly" is not true anymore.
LGTM.
--
Serge Petrenko
On Mon, Apr 26, 2021 at 12:40:57PM +0300, Serge Petrenko wrote:
> > I'll make it so and force push. Thanks a huge for review, guys!
>
> Thanks! Please, update the commit message:
> "- there is no need to set WAN_NONE to 0 explicitly" is not true anymore.
Done! Thanks for noticing.
Hello,
On 19 апр 11:37, Cyrill Gorcunov wrote:
> Hi! Here are a few cleanups for wal and txn_limbo.
> The txn_limbo cleanups shrinks code while wal modes
> rework allows to save a pointer.
>
> I made the series during work on issue 5447
> branch gorcunov/gh-5447-cleanup
>
> Cyrill Gorcunov (3):
> wal: sanitize wal_mode
> txn_limbo: simplify owner migration condition
> txn_limbo: simplify txn_limbo_ack
>
> src/box/txn_limbo.c | 6 ++----
> src/box/wal.c | 6 +++++-
> src/box/wal.h | 27 +++++++++++++++++++++++----
> 3 files changed, 30 insertions(+), 9 deletions(-)
I've checked your patchset into master.
--
Regards, Kirill Yukhin