Skip to content

Refactor syncWithPrimary and replicaTryPartialResynchronization#1476

Merged
PingXie merged 1 commit intovalkey-io:unstablefrom
nitaicaro:unstable
Apr 25, 2025
Merged

Refactor syncWithPrimary and replicaTryPartialResynchronization#1476
PingXie merged 1 commit intovalkey-io:unstablefrom
nitaicaro:unstable

Conversation

@nitaicaro
Copy link
Contributor

@nitaicaro nitaicaro commented Dec 23, 2024

In continuation to #945

syncWithPrimary:

  • Refactored all error handling to function syncWithPrimaryHandleError
  • Refactored repl_state state machine from if-else format to switch-case format
  • Besides changing the repl_state, all state machine logic moved to helper functions

replicaTryPartialResynchronization:
This function was performing two different jobs based on the value of the read_reply argument -

  • read_reply == 0: Sends the PSYNC command to the primary server.
  • read_reply == 1: Reads and processes the reply to the PSYNC command.

This change simplifies the logic by clearly separating the writing and reading stages of the PSYNC process.

@nitaicaro nitaicaro force-pushed the unstable branch 2 times, most recently from e52808f to 6df1d3c Compare December 23, 2024 11:44
@codecov
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 71.30045% with 64 lines in your changes missing coverage. Please review.

Project coverage is 71.04%. Comparing base (1840871) to head (b912bfc).
Report is 7 commits behind head on unstable.

Files with missing lines Patch % Lines
src/replication.c 71.30% 64 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1476      +/-   ##
============================================
+ Coverage     71.03%   71.04%   +0.01%     
============================================
  Files           123      123              
  Lines         66033    66087      +54     
============================================
+ Hits          46908    46954      +46     
- Misses        19125    19133       +8     
Files with missing lines Coverage Δ
src/replication.c 86.76% <71.30%> (-0.49%) ⬇️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@naglera naglera requested a review from PingXie December 23, 2024 12:38
Copy link
Member

@PingXie PingXie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of refactoring is really valuable for the long-term health of Valkey. It makes the codebase easier to understand, maintain, and improve, which ultimately helps us deliver better features faster. Thanks @nitaicaro and @naglera!

My main focus in this review is on the high level code structure, which looks great to me. That said, the use of goto in syncWithPrimary stands out. Let's aim to eliminate all goto statements from that function. I'll take another look and provide more detailed feedback once that's addressed.

@nitaicaro
Copy link
Contributor Author

This kind of refactoring is really valuable for the long-term health of Valkey. It makes the codebase easier to understand, maintain, and improve, which ultimately helps us deliver better features faster. Thanks @nitaicaro and @naglera!

My main focus in this review is on the high level code structure, which looks great to me. That said, the use of goto in syncWithPrimary stands out. Let's aim to eliminate all goto statements from that function. I'll take another look and provide more detailed feedback once that's addressed.

Done

@nitaicaro nitaicaro force-pushed the unstable branch 2 times, most recently from 2e42f15 to 813ef82 Compare February 18, 2025 10:18
@nitaicaro nitaicaro requested a review from PingXie February 27, 2025 12:33
@PingXie
Copy link
Member

PingXie commented Feb 28, 2025

@nitaicaro thanks for the reminder! I didn't forget about this one :) I am planning to continue my review next week.

@PingXie
Copy link
Member

PingXie commented Feb 28, 2025

btw, there seems to be some merge conflicts. do you have a plan to resolve them soon?

Copy link
Member

@PingXie PingXie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience, @nitaicaro. The overall code structure LGTM and it is a lot cleaner!

I have some local comments that I think should be easy to address. We can aim at merging this PR shortly after 8.1 GA.

Copy link
Member

@PingXie PingXie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with only one last comment. Will approve once it is addressed. Thanks @nitaicaro

Copy link
Member

@PingXie PingXie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks so much for your patience, @nitaicaro! Really appreciate it. Let's merge it!

@nitaicaro nitaicaro force-pushed the unstable branch 6 times, most recently from 924274b to d3ef66f Compare April 22, 2025 07:46
@nitaicaro nitaicaro force-pushed the unstable branch 3 times, most recently from 9ad7e78 to ccdb1c1 Compare April 22, 2025 11:41
@PingXie
Copy link
Member

PingXie commented Apr 23, 2025

@valkey-io/core-team anyone else would like to take a look at this pr before it gets merged?

Copy link
Member

@enjoy-binbin enjoy-binbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am worry this will cause conflict with #1949. @murphyjacob4

@murphyjacob4
Copy link
Contributor

Sadly, a merge conflict seems inevitable. I wouldn't block this PR on #1949, I can handle the merge conflicts in that PR

@PingXie PingXie merged commit 5df95b3 into valkey-io:unstable Apr 25, 2025
51 checks passed
rainsupreme pushed a commit to rainsupreme/valkey that referenced this pull request May 14, 2025
…ey-io#1476)

In continuation to valkey-io#945

**syncWithPrimary:**
- Refactored all error handling to function `syncWithPrimaryHandleError`
- Refactored repl_state state machine from if-else format to switch-case
format
- Besides changing the repl_state, all state machine logic moved to
helper functions

**replicaTryPartialResynchronization:**
This function was performing two different jobs based on the value of
the read_reply argument -
- read_reply == 0: Sends the PSYNC command to the primary server.
- read_reply == 1: Reads and processes the reply to the PSYNC command.

This change simplifies the logic by clearly separating the writing and
reading stages of the PSYNC process.

Signed-off-by: Nitai Caro <[email protected]>
Co-authored-by: Nitai Caro <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants