valkey-io / valkey

A flexible distributed key-value datastore that is optimized for caching and other realtime workloads.
https://valkey.io
Other
17.36k stars 656 forks source link

Use goto to cleanup error handling in readSyncBulkPayload #1332

Closed enjoy-binbin closed 1 day ago

enjoy-binbin commented 1 day ago

The goto error label is the same as the error return, use goto to reduce the references.

error:
    cancelReplicationHandshake(1);
    return;

Also this can make the log printing more continuous under the error, that is, we print the error log first, and then print the reconnecting log at the last (in cancelReplicationHandshake).

codecov[bot] commented 1 day ago

Codecov Report

Attention: Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 70.69%. Comparing base (4986310) to head (f3ffeaa). Report is 1 commits behind head on unstable.

Files with missing lines Patch % Lines
src/replication.c 50.00% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## unstable #1332 +/- ## ========================================= Coverage 70.68% 70.69% ========================================= Files 115 115 Lines 63177 63171 -6 ========================================= - Hits 44657 44656 -1 + Misses 18520 18515 -5 ``` | [Files with missing lines](https://app.codecov.io/gh/valkey-io/valkey/pull/1332?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valkey-io) | Coverage Δ | | |---|---|---| | [src/replication.c](https://app.codecov.io/gh/valkey-io/valkey/pull/1332?src=pr&el=tree&filepath=src%2Freplication.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valkey-io#diff-c3JjL3JlcGxpY2F0aW9uLmM=) | `87.44% <50.00%> (+0.17%)` | :arrow_up: | ... and [13 files with indirect coverage changes](https://app.codecov.io/gh/valkey-io/valkey/pull/1332/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valkey-io)

🚨 Try these New Features:

enjoy-binbin commented 1 day ago

a test log example:

67697:S 21 Nov 2024 16:01:03.309 * Loading RDB produced by Valkey version 255.255.255
67697:S 21 Nov 2024 16:01:03.309 * RDB age 0 seconds
67697:S 21 Nov 2024 16:01:03.309 * RDB memory usage when created 1.23 Mb
67697:S 21 Nov 2024 16:01:03.309 # binbintest load error
67697:S 21 Nov 2024 16:01:03.309 # Failed trying to load the PRIMARY synchronization DB from disk, check server logs.
67697:S 21 Nov 2024 16:01:03.310 * Reconnecting to PRIMARY 127.0.0.1:6379 after failure
67697:S 21 Nov 2024 16:01:03.310 * PRIMARY <-> REPLICA sync started
67697:S 21 Nov 2024 16:01:03.310 * PRIMARY <-> REPLICA sync: Discarding the half-loaded data

the reconnecting and sync started should be after discarding one.

enjoy-binbin commented 1 day ago

cancelReplicationHandshake is a no-op in some cases where we just did return before, right?

no, cancelReplicationHandshake is not a no-op, and we are not just did return before, we did cancelReplicationHandshake and return together before, this commit just like, adjust the code location (or order).

zuiderkwast commented 1 day ago

cancelReplicationHandshake is a no-op in some cases where we just did return before, right?

no, cancelReplicationHandshake is not a no-op, and we are not just did return before, we did cancelReplicationHandshake and return together before, this commit just like, adjust the code location (or order).

Ah, I see now. Every goto error replaces cancelReplicationHandshake + return.