Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding mutex to functions that use ForEachMaster method #102

Merged
merged 17 commits into from
Jan 24, 2024
Merged

Conversation

mativm02
Copy link
Contributor

@mativm02 mativm02 commented Jan 11, 2024

Description

ForEachMaster is a Redis' method that concurrently iterates over each master of the cluster instance. We weren't using a mutex, so this caused a race condition and the final results were randomly incorrect.
Also, I deleted the return of cursor in GetKeysWithOpts since we're not using it nowhere and it causes confusion when the instance is a cluster (since each master node could return a different cursor).

New GetKeysWithOpts can be used in the following way:

var cursor map[string]uint64
var keys []string
var continueScan bool
var err error
for {
  keys, newCursor, continueScan, err = kv.GetKeysWithOpts(ctx, "keys*", continueScan, 10)
  if err != nil {
    return err
  }

 // handle logic

 if !continueScan {
  break
}
}

Note that it's important to use the returned cursor map on each new GetKeysWithOpts call.

Related Issue

Motivation and Context

Test Coverage For This Change

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)
  • Documentation updates or improvements.

Checklist

  • I have reviewed the guidelines for contributing to this repository.
  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If PRing from your fork, don't come from your master!
  • Make sure you are making a pull request against our master branch (left side). Also, it would be best if you started your change off our latest master.
  • My change requires a change to the documentation.
    • I have manually updated the README(s)/documentation accordingly.
    • If you've changed APIs, describe what needs to be updated in the documentation.
  • I have updated the documentation accordingly.
  • Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • When updating library version must provide reason/explanation for this update.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Check your code additions will not fail linting checks:
    • gofmt -s -w .
    • go vet ./...

@mativm02 mativm02 changed the title restructuring FlushAll method in tests Adding mutex to functions that use ForEachMaster method Jan 11, 2024
@mativm02 mativm02 marked this pull request as ready for review January 11, 2024 15:23
@mativm02 mativm02 requested review from sredxny and tbuchaillot and removed request for sredxny January 23, 2024 16:39
@mativm02 mativm02 merged commit 47e8a77 into main Jan 24, 2024
11 checks passed
@mativm02 mativm02 deleted the fix/flaky-test branch January 24, 2024 12:27
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

3 New issues
0 Security Hotspots
87.9% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

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.

2 participants