Skip to content

refactor: store cleanup#1705

Merged
toddbaert merged 6 commits into
open-feature:mainfrom
andreyturkov:refactor/store-cleanup
Aug 21, 2025
Merged

refactor: store cleanup#1705
toddbaert merged 6 commits into
open-feature:mainfrom
andreyturkov:refactor/store-cleanup

Conversation

@andreyturkov
Copy link
Copy Markdown
Contributor

@andreyturkov andreyturkov commented Aug 7, 2025

This PR

IStore interface usage instead of Store implementation
Separate locks for flag data and metadata in store - no longer valid point

@andreyturkov andreyturkov requested a review from a team August 7, 2025 11:30
@andreyturkov andreyturkov requested a review from a team as a code owner August 7, 2025 11:30
@netlify
Copy link
Copy Markdown

netlify Bot commented Aug 7, 2025

Deploy Preview for polite-licorice-3db33c canceled.

Name Link
🔨 Latest commit 3e8aea6
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/68a5a522ba6ab4000864d17f

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 7, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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 Store struct has been renamed to store (lowercase) and is now unexported, ensuring that external packages interact with it only through the IStore interface.
  • IStore Interface Expansion: The IStore interface has been extended with new methods, including GetMetadataForSource, Update, String, and SyncConfig, providing a more comprehensive contract for store operations.
  • Finer-Grained Concurrency Control: The single sync.RWMutex (mx) has been replaced by two distinct sync.RWMutex instances: flagMx for flag data and metaMx for 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 NewStore function now returns the IStore interface, 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 new SyncConfig method on the IStore interface and implemented in the store struct. 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 the store.IStore interface, 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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

@beeme1mr
Copy link
Copy Markdown
Member

beeme1mr commented Aug 7, 2025

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>
@andreyturkov andreyturkov force-pushed the refactor/store-cleanup branch from ef3a3c3 to ebdd616 Compare August 18, 2025 14:14
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Aug 18, 2025
@andreyturkov
Copy link
Copy Markdown
Contributor Author

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

I'have rebased my branch with the latest main. Please take a look.

@beeme1mr
Copy link
Copy Markdown
Member

The licensing issue was a false positive and I've added an exception in FOSSA.

Signed-off-by: Andrey <andreyturkov@google.com>
@andreyturkov andreyturkov requested a review from a team as a code owner August 19, 2025 08:50
Copy link
Copy Markdown
Contributor

@tangenti tangenti left a comment

Choose a reason for hiding this comment

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

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

Comment thread core/pkg/store/store.go Outdated
Signed-off-by: Andrey <andreyturkov@google.com>
@andreyturkov
Copy link
Copy Markdown
Contributor Author

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

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.
The same logic applies to the Update method.
I'll remove the mutex usage from both methods, and since it's no longer needed, I'll also remove the mutex field from the store struct itself.

Signed-off-by: Andrey <andreyturkov@google.com>
Comment thread core/pkg/store/store.go Outdated
Signed-off-by: Andrey <andreyturkov@google.com>
@toddbaert
Copy link
Copy Markdown
Member

toddbaert commented Aug 21, 2025

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.

@toddbaert toddbaert merged commit bcff8d7 into open-feature:main Aug 21, 2025
15 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 18, 2025
toddbaert added a commit that referenced this pull request Dec 24, 2025
🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants