fix: move RetryCount default to config.Validate() across all drivers - #1058
fix: move RetryCount default to config.Validate() across all drivers#1058cotishq wants to merge 14 commits into
Conversation
|
@cotishq assigning @saksham-datazip to review your PR |
| d.config.RetryCount = utils.Ternary(d.config.RetryCount <= 0, 1, d.config.RetryCount+1).(int) | ||
| return nil |
There was a problem hiding this comment.
In olake , by backoff_retry_count we mean is number of retry count for example if user enters 3 backoff retry count than it means 1 main sync + 3 Retry count so can you please make changes according to that.
There was a problem hiding this comment.
yeahh that makes sense, i have updated all drivers to align with this semantic ( attempts = RetryCount + 1 )
please lmk if this looks good
aca23fb to
0bbc997
Compare
| m.CDCSupport = true | ||
| // check for default backoff count | ||
| m.config.RetryCount = utils.Ternary(m.config.RetryCount == 0, 1, m.config.RetryCount+1).(int) | ||
| pingCtx, cancel := context.WithTimeout(ctx, 1*time.Minute) |
There was a problem hiding this comment.
So what i was suggesting is instead of removing this part you can let it stay as it is and just remove that check from validate function so it would be single source of truth and just add a small comment over here specifying why we are doing +1 .
if you have some other reasoning for the changes you made than feel free to discuss.
There was a problem hiding this comment.
ok, i actually agree the +1 is intentional, my pr doesnt remove it, it relocates it, retry_count is the no. of retries in RetryOnBackoff expects total attempts, so Maxretries now returns retrycount + 1 ( same behaviour btw ) but the conversation happens at the interface boundary instead of mutating config,
and on single source of truth: the line was copy-pasted into 9 drivers setup() method. after my change it exists once i.e constants. DefaultRetryCount + Validate().
also, keeping it in Setup() cant fix the actual bug cleanly imo, like the unset retry_count became 1 attempt (zero retries). That fix requires an inline DefaultRetryCount+1 inside the Ternary, which is exactly what needs the comment you're asking for. In Validate() it reads naturally, and it follows the existing MaxThreads precedent in the same file
i think the middle ground would be : i'll add the comment you suggested at the conversion point in MaxRetries() , like
// RetryCount is the number of retries; +1 accounts for the initial attempt,
// since RetryOnBackoff expects total attempts.
return p.config.RetryCount + 1
lmk if that works
There was a problem hiding this comment.
I understand what you mean. I think we can handle this in the Setup() function itself: if RetryCount < 0, we fail the sync, and if RetryCount == 0, we set it to the default retry count.
if c.RetryCount < 0 {
return fmt.Errorf("retry count is required")
}
if c.RetryCount == 0 {
c.RetryCount = constants.DefaultRetryCount
}Apart from that, instead of modifying the value in MaxRetries, we can handle the +1 in a single place inside RetryOnBackoff() and add a comment explaining why it is needed:
func RetryOnBackoff(ctx context.Context, attempts int, sleep time.Duration, f func(ctx context.Context) error) (err error) {
// Add 1 because attempts represents the number of retries,
// while the function needs the total number of attempts.
attempts = attempts + 1This way, we are not manipulating the input provided by the user in multiple places, and the retry-count logic stays centralized in RetryOnBackoff().
And just FYI, in your approach, Mongo is directly calling RetryOnBackoff like this:
err = utils.RetryOnBackoff(ctx, m.config.RetryCount, constants.DefaultRetryTimeout, func(ctx context.Context) error {
chunksArray, retryErr = m.splitChunks(ctx, collection, stream, storageSize)
return retryErr
})
So it would bypass the changes you're making in MaxRetries and use default values.
There was a problem hiding this comment.
Also their is one more thing we have changed the scope of this pr that we dont want config file to be manipulated directly so can you once check in entire pr that what we should do for instance in mysql if db name is empty we are setting it to "mysql" but we should fail the sync itself can you once check and made the respective changes
32a2d4b to
f3b2014
Compare
|
Thanks for the review @saksham-datazip I agree with your suggestion to make
lmk if this looks good, or we have to make more changes |
|
@cotishq Just fyi we avoid using force push or rebase in olake so please dont do it from now onwards |
There was a problem hiding this comment.
@cotishq I think there may be some misunderstanding regarding my last comment:
1->As mentioned, the scope of this PR has changed, and we now want the ConfigMap to remain unaffected, so could you please go through my previous comment once again before making any changes?
2->If anything is unclear, please feel free to ask me directly rather than making assumptions.
3->Regarding Testing just running unit tests is not enough you have to run sync as well and think about edge cases w.r.t. changes you have made.
Also, if you're making a change in one place, please check whether the same change should be applied elsewhere and make the corresponding changes where applicable.
| // default backoff retry count | ||
| if c.RetryCount <= 0 { | ||
| c.RetryCount = constants.DefaultRetryCount | ||
| } | ||
|
|
There was a problem hiding this comment.
I told you to fail the sync for c.RetryCount<0 case right ?Please do it for all the drivers.
ok i'll keep this in mind |
…lake into fix/retry-count-initialization # Conflicts: # drivers/db2/internal/config.go # drivers/mongodb/internal/config.go # drivers/oracle/internal/config.go # drivers/postgres/internal/config.go # utils/utils.go
|
Apologies for the previous misunderstanding, i just took that in wrong way but i have fixed the things now like this:
lmk, if this looks good to you, comfortable to address more suggestions too |
| if c.Database == "" { | ||
| c.Database = "mysql" | ||
| return fmt.Errorf("database name is required") | ||
| } |
There was a problem hiding this comment.
hey sorry for the to and fro, we had an internal discussion and after thinking this particular change might be destructive and of low priority so can you please revert it and dont forget to revert the respective unit test for this fail ?
| return fmt.Errorf("retry count is required") | ||
| } | ||
| if c.RetryCount == 0 { | ||
| c.RetryCount = constants.DefaultRetryCount |
There was a problem hiding this comment.
Can you please add a space between two if conditions and do it for all the drivers wherever needed?
| @@ -152,7 +152,10 @@ func (c *Config) Validate() error { | |||
| } | |||
There was a problem hiding this comment.
Also can you make the same changes for this one as well as i told you and also do this for other drivers as well
|
@cotishq I’ve reviewed your PR. Please make the necessary changes accordingly. If there’s no response or progress on the requested changes within two days, we’ll close the PR. |
yess, making the changes, will update you shortly |
|
@saksham-datazip i have addressed all the suggestions, ptal and lmk i we have to do more changes |
Description
Fixes #993
Previously, every driver's Setup() method contained an ad-hoc line that both set the default retry count and silently mutated it, incrementing it by 1 when a value was already present:
This had two bugs:
This PR removes all those lines and moves the default initialisation into each driver's Config.Validate():
constants.DefaultRetryCount = 3 is now consistently used as the fallback across all drivers. The value is set once, early, and never mutated again.
Type of change
How Has This Been Tested?
Previously, Setup() would have set it to 1.
Added "retry_count": 5 to source.json and re-ran the same sync command. Logs confirmed:
Screenshots or Recordings
https://drive.google.com/file/d/1S1Nzz4CWyiUkyBCyCM5HqSHa2H6rMFZm/view?usp=sharing
Documentation