[Tarantool-patches] [PATCH 4/7] txn_limbo: persist the latest effective promote in snapshot
Serge Petrenko
sergepetrenko at tarantool.org
Fri Jun 18 00:00:14 MSK 2021
15.06.2021 23:59, Vladislav Shpilevoy пишет:
> Danke schön für der Patch!
>
> See 3 comments below.
>
>> diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c
>> index 6c4982b9f..3713d39d0 100644
>> --- a/src/box/memtx_engine.c
>> +++ b/src/box/memtx_engine.c
>> @@ -225,6 +226,22 @@ memtx_engine_recover_raft(const struct xrow_header *row)
>> return 0;
>> }
>>
>> +static int
>> +memtx_engine_recover_promote(const struct xrow_header *row)
> 1. Maybe call it recover_synchro instead of promote? Even in the
> body PROMOTE is not mentioned anyhow except for the assertion.
> What if we ever add more members to the synchro state?
Ok.
>> +{
>> + assert(row->type == IPROTO_PROMOTE);
>> + struct synchro_request req;
>> + if (xrow_decode_synchro(row, &req) != 0)
>> + return -1;
>> + /*
>> + * Origin id cannot be deduced from row.replica_id in a checkpoint,
>> + * because all it's rows have a zero replica_id.
>> + */
>> + req.origin_id = req.replica_id;
>> + txn_limbo_process(&txn_limbo, &req);
>> + return 0;
>> +}
>> @@ -655,6 +676,17 @@ finish:
>> return rc;
>> }
>>
>> +static int
>> +checkpoint_write_promote(struct xlog *l, const struct synchro_request *req)
>> +{
>> + struct xrow_header row;
>> + char body[XROW_SYNCHRO_BODY_LEN_MAX];
>> + xrow_encode_synchro(&row, body, req);
>> + if (checkpoint_write_row(l, &row) != 0)
>> + return -1;
>> + return 0;
> 2. Could also make 'return checkpoint_write_row(...);'
> without branching + that might activate the tail call
> optimization.
Sure, thanks for noticing!
>> diff --git a/src/box/txn_limbo.h b/src/box/txn_limbo.h
>> index e409ac657..84a19bb40 100644
>> --- a/src/box/txn_limbo.h
>> +++ b/src/box/txn_limbo.h
>> @@ -311,6 +311,12 @@ txn_limbo_process(struct txn_limbo *limbo, const struct synchro_request *req);
>> int
>> txn_limbo_wait_confirm(struct txn_limbo *limbo);
>>
>> +/**
>> + * Persist limbo state to a given synchro request.
>> + */
>> +void
>> +txn_limbo_checkpoint(struct txn_limbo *limbo, struct synchro_request *req);
> 3. Lets make the limbo a const pointer. It does not change, does it?
Ok. Please, find the incremental diff below.
==================================
diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c
index a2ba17855..a2cfb2615 100644
--- a/src/box/memtx_engine.c
+++ b/src/box/memtx_engine.c
@@ -227,7 +227,7 @@ memtx_engine_recover_raft(const struct xrow_header *row)
}
static int
-memtx_engine_recover_promote(const struct xrow_header *row)
+memtx_engine_recover_synchro(const struct xrow_header *row)
{
assert(row->type == IPROTO_PROMOTE);
struct synchro_request req;
@@ -235,7 +235,7 @@ memtx_engine_recover_promote(const struct
xrow_header *row)
return -1;
/*
* Origin id cannot be deduced from row.replica_id in a checkpoint,
- * because all it's rows have a zero replica_id.
+ * because all its rows have a zero replica_id.
*/
req.origin_id = req.replica_id;
txn_limbo_process(&txn_limbo, &req);
@@ -251,7 +251,7 @@ memtx_engine_recover_snapshot_row(struct
memtx_engine *memtx,
if (row->type == IPROTO_RAFT)
return memtx_engine_recover_raft(row);
if (row->type == IPROTO_PROMOTE)
- return memtx_engine_recover_promote(row);
+ return memtx_engine_recover_synchro(row);
diag_set(ClientError, ER_UNKNOWN_REQUEST_TYPE,
(uint32_t) row->type);
return -1;
@@ -561,7 +561,7 @@ struct checkpoint {
struct vclock vclock;
struct xdir dir;
struct raft_request raft;
- struct synchro_request promote;
+ struct synchro_request synchro_state;
/**
* Do nothing, just touch the snapshot file - the
* checkpoint already exists.
@@ -587,7 +587,7 @@ checkpoint_new(const char *snap_dirname, uint64_t
snap_io_rate_limit)
xdir_create(&ckpt->dir, snap_dirname, SNAP, &INSTANCE_UUID, &opts);
vclock_create(&ckpt->vclock);
box_raft_checkpoint_local(&ckpt->raft);
- txn_limbo_checkpoint(&txn_limbo, &ckpt->promote);
+ txn_limbo_checkpoint(&txn_limbo, &ckpt->synchro_state);
ckpt->touch = false;
return ckpt;
}
@@ -677,14 +677,12 @@ finish:
}
static int
-checkpoint_write_promote(struct xlog *l, const struct synchro_request *req)
+checkpoint_write_synchro(struct xlog *l, const struct synchro_request *req)
{
struct xrow_header row;
char body[XROW_SYNCHRO_BODY_LEN_MAX];
xrow_encode_synchro(&row, body, req);
- if (checkpoint_write_row(l, &row) != 0)
- return -1;
- return 0;
+ return checkpoint_write_row(l, &row);
}
static int
@@ -724,7 +722,7 @@ checkpoint_f(va_list ap)
}
if (checkpoint_write_raft(&snap, &ckpt->raft) != 0)
goto fail;
- if (checkpoint_write_promote(&snap, &ckpt->promote) != 0)
+ if (checkpoint_write_synchro(&snap, &ckpt->synchro_state) != 0)
goto fail;
if (xlog_flush(&snap) < 0)
goto fail;
diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
index 57f105ee3..c4ff5cc34 100644
--- a/src/box/txn_limbo.c
+++ b/src/box/txn_limbo.c
@@ -297,7 +297,8 @@ complete:
}
void
-txn_limbo_checkpoint(struct txn_limbo *limbo, struct synchro_request *req)
+txn_limbo_checkpoint(const struct txn_limbo *limbo,
+ struct synchro_request *req)
{
req->type = IPROTO_PROMOTE;
req->replica_id = limbo->owner_id;
diff --git a/src/box/txn_limbo.h b/src/box/txn_limbo.h
index 84a19bb40..f5079d577 100644
--- a/src/box/txn_limbo.h
+++ b/src/box/txn_limbo.h
@@ -315,7 +315,8 @@ txn_limbo_wait_confirm(struct txn_limbo *limbo);
* Persist limbo state to a given synchro request.
*/
void
-txn_limbo_checkpoint(struct txn_limbo *limbo, struct synchro_request *req);
+txn_limbo_checkpoint(const struct txn_limbo *limbo,
+ struct synchro_request *req);
/**
* Write a PROMOTE request, which has the same effect as CONFIRM(@a
lsn) and
==================================
--
Serge Petrenko
More information about the Tarantool-patches
mailing list