How to Use the enable-async-apply-prewrite Parameter

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 怎样使用enable-async-apply-prewrite参数

| username: TiDBer_lmKxZw6J

Could the expert please explain the usage of enable-async-apply-prewrite? Thanks.
If the enable-async-apply-prewrite parameter is set to true, how will the write process change? Does it mean that the write can be confirmed as completed by only finishing the store thread without waiting for the apply thread? Will there be any negative impacts with this setting?

| username: TiDBer_jYQINSnf | Original post link

After enabling it, some asynchronous prewrites can return success directly after the raft log is applied. I understand that enabling it has no negative impact, it just speeds up the quick return of some prewrites.

| username: TiDBer_lmKxZw6J | Original post link

Thank you. So, after successfully writing to raftDB, the write operation is directly confirmed as successful without waiting for KVDB to write?

| username: 小于同学 | Original post link

There should be no negative impact.

| username: TiDBer_jYQINSnf | Original post link

Yes, it doesn’t have any impact and won’t cause data loss.

| username: TiDBer_Z2xKPnNe | Original post link

If there are no negative impacts, why not use this mechanism directly instead of setting this parameter switch? I would like to hear a detailed explanation.

| username: TiDBer_Z2xKPnNe | Original post link

Additionally, on the leader node, the apply action involves writing data from memory to the KV DB. The reason for applying, as I heard, is that subsequent reads are also performed on the leader node, so the data must be written to disk to ensure that it can be read normally later, ensuring read consistency.

Assuming the above reason is valid, I have another question: why does the leader node have to read from the disk instead of from memory? Is it because the data format in memory is incomplete and different from the data written to disk, making it impossible to parse the data format when reading from memory? (At least in MySQL and Oracle, data is read from memory, which is commonly referred to as memory hit rate, a key factor in database performance.)