refactor: store cleanup#1705
Conversation
✅ Deploy Preview for polite-licorice-3db33c canceled.
|
There was a problem hiding this comment.
Summary of Changes
Hello @andreyturkov, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've refactored the core store package to enhance its design and concurrency. The primary goal was to introduce and enforce the use of an IStore interface, abstracting the underlying implementation. This involved renaming the concrete Store struct to an unexported store and updating its constructor to return the interface. A significant improvement in concurrency was achieved by separating the single read-write mutex into two distinct mutexes, one for flag data and another for metadata, allowing for more efficient concurrent access. Additionally, I've centralized the logic for synchronizing source configurations by moving it into a new method on the IStore interface. These changes promote a more robust, testable, and maintainable store component by adhering to interface-driven design principles and improving internal concurrency.
Highlights
- Store Implementation Encapsulation: The
Storestruct has been renamed tostore(lowercase) and is now unexported, ensuring that external packages interact with it only through theIStoreinterface. - IStore Interface Expansion: The
IStoreinterface has been extended with new methods, includingGetMetadataForSource,Update,String, andSyncConfig, providing a more comprehensive contract for store operations. - Finer-Grained Concurrency Control: The single
sync.RWMutex(mx) has been replaced by two distinctsync.RWMutexinstances:flagMxfor flag data andmetaMxfor metadata. This allows for more granular locking, potentially reducing contention and improving performance for concurrent read/write operations on different parts of the store. - Factory Function Returns Interface: The
NewStorefunction now returns theIStoreinterface, reinforcing the pattern of programming against interfaces rather than concrete implementations. - Centralized Source Configuration: The logic for configuring flag sources, previously handled directly in
flagd/pkg/runtime/from_config.go, has been moved into a newSyncConfigmethod on theIStoreinterface and implemented in thestorestruct. This centralizes source configuration management within the store itself. - Consumer Migration to IStore: All internal components that previously directly depended on
*store.Store, such as the JSON evaluator and various sync services, have been updated to use thestore.IStoreinterface, aligning with the new architectural design.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request refactors the store to use an IStore interface instead of the concrete Store implementation, improving decoupling. It also introduces separate read-write locks for flag data and metadata. The changes are mostly clean and follow the stated goals. However, I've identified a race condition and some potentially unnecessary locking which I've detailed in my comments.
|
Hey @andreyturkov, thanks for the PR. There's a fairly large refactor open right now that we're hoping to get in soon. I'd like to hold off on making this change until that one has been merged. FYI @toddbaert |
…ementation after global refactoring Signed-off-by: Andrey <andreyturkov@google.com>
ef3a3c3 to
ebdd616
Compare
I'have rebased my branch with the latest main. Please take a look. |
|
The licensing issue was a false positive and I've added an exception in FOSSA. |
Signed-off-by: Andrey <andreyturkov@google.com>
tangenti
left a comment
There was a problem hiding this comment.
Could you also check the usages of lock in Store?
Now the lock should only be used for metadata, as flag CRUD is done with transaction. In String() for example, the lock is still used which is not needed I think
Signed-off-by: Andrey <andreyturkov@google.com>
You are absolutely right. The lock in the String() method is unnecessary as the underlying GetAll() call is transactional and doesn't rely on the mutex. |
Signed-off-by: Andrey <andreyturkov@google.com>
Signed-off-by: Andrey <andreyturkov@google.com>
|
Great work @andreyturkov , thanks! merging once the CI completes... Do you have any interest in implementing this? It's something we believe is important; there's also room for an optional refactor if you're keen to that. |
🤖 I have created a release *beep* *boop* --- <details><summary>flagd: 0.13.0</summary> ## [0.13.0](flagd/v0.12.9...flagd/v0.13.0) (2025-12-23) ### 🐛 Bug Fixes * fixing sync return format missing flag layer, adding full e2e suite ([#1827](#1827)) ([570693d](570693d)) * **security:** update module github.com/go-viper/mapstructure/v2 to v2.4.0 [security] ([#1784](#1784)) ([037e30b](037e30b)) * **security:** update module golang.org/x/crypto to v0.45.0 [security] ([#1826](#1826)) ([7e0762b](7e0762b)) ### ✨ New Features * add support for http-based ofrep metrics ([#1803](#1803)) ([fcd19b3](fcd19b3)) * cleanup evaluator interface ([#1793](#1793)) ([aa504f7](aa504f7)) * enable parsing of array flag configurations for flagd ([#1797](#1797)) ([97c6ffa](97c6ffa)) * multi-project support via selectors and flagSetId namespacing ([#1702](#1702)) ([f9ce46f](f9ce46f)) * normalize selector in sync (use header as in OFREP and RPC) ([#1815](#1815)) ([c1f06cb](c1f06cb)) ### 🧹 Chore * **refactor:** use memdb for flag storage ([#1697](#1697)) ([5c5c1cf](5c5c1cf)) ### 🔄 Refactoring * store cleanup ([#1705](#1705)) ([bcff8d7](bcff8d7)) </details> <details><summary>flagd-proxy: 0.8.1</summary> ## [0.8.1](flagd-proxy/v0.8.0...flagd-proxy/v0.8.1) (2025-12-23) ### 🐛 Bug Fixes * **security:** update module github.com/go-viper/mapstructure/v2 to v2.4.0 [security] ([#1784](#1784)) ([037e30b](037e30b)) * **security:** update module golang.org/x/crypto to v0.45.0 [security] ([#1826](#1826)) ([7e0762b](7e0762b)) </details> <details><summary>core: 0.13.0</summary> ## [0.13.0](core/v0.12.1...core/v0.13.0) (2025-12-23) ### ⚠ BREAKING CHANGES * enable parsing of array flag configurations for flagd ([#1797](#1797)) * cleanup evaluator interface ([#1793](#1793)) * removes the `fractionalEvaluation` operator since it has been replaced with `fractional`. ([#1704](#1704)) ### 🐛 Bug Fixes * **security:** update module github.com/go-viper/mapstructure/v2 to v2.4.0 [security] ([#1784](#1784)) ([037e30b](037e30b)) * **security:** update module golang.org/x/crypto to v0.45.0 [security] ([#1825](#1825)) ([44edcc9](44edcc9)) * **security:** update module golang.org/x/crypto to v0.45.0 [security] ([#1826](#1826)) ([7e0762b](7e0762b)) ### ✨ New Features * Add OAuth support for HTTP Sync ([#1791](#1791)) ([268fd75](268fd75)) * Add OTEL default variables ([#1812](#1812)) ([c2e3fc6](c2e3fc6)) * allow null flagSetId Selector, restrict Selector to single key-value-pairs ([#1708](#1708)) ([#1811](#1811)) ([c12a0ae](c12a0ae)) * change jsonschema parser ([#1794](#1794)) ([bf3f722](bf3f722)) * cleanup evaluator interface ([#1793](#1793)) ([aa504f7](aa504f7)) * enable parsing of array flag configurations for flagd ([#1797](#1797)) ([97c6ffa](97c6ffa)) * multi-project support via selectors and flagSetId namespacing ([#1702](#1702)) ([f9ce46f](f9ce46f)) ### 🧹 Chore * **refactor:** use memdb for flag storage ([#1697](#1697)) ([5c5c1cf](5c5c1cf)) * removes the `fractionalEvaluation` operator since it has been replaced with `fractional`. ([#1704](#1704)) ([3228ad8](3228ad8)) ### 🔄 Refactoring * remove deprecated bearerToken option ([#1816](#1816)) ([efda06a](efda06a)) * removed unused Selector from Flag and Store. ([#1747](#1747)) ([1083005](1083005)) * store cleanup ([#1705](#1705)) ([bcff8d7](bcff8d7)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com> Signed-off-by: Todd Baert <todd.baert@dynatrace.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
This PR
IStore interface usage instead of Store implementation
Separate locks for flag data and metadata in store - no longer valid point