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

fix: adds order by timestamp #4316

Merged

Conversation

wolf4ood
Copy link
Contributor

@wolf4ood wolf4ood commented Jul 1, 2024

What this PR changes/adds

Adds a deterministic order by stateTimestamp field in nextNotLeased method of state machines:

  • PolicyMonitor
  • DataPlane
  • ContractNegotiation
  • TransferProcess

This will allow a consistent and fair processing order for entities based on their state.
By using an index on state + timestamp it will also speedup processing states that need to transition and it will also lower down the usage of the database which we constantly poll for next states to process. State machine should not poll final state or states that needs to be monitored for a long period of time.

While profiling state machine the PolicyMonitor was on of those which spikes the CPU usage of both connector and
database since basically it's constantly polling the database for the entries in STARTED state, which grows over time without transitioning. Also the edc.policy.monitor.state-machine.iteration-wait-millis didn't help since the state machine does not wait if at least one entry has been process in a tick. To lower down the load to the database usage of the PolicyMonitor state machine the processMonitoring processor now return false if no state transition is made. In this way the wait configuration can be applied.

Why it does that

Briefly state why the change was necessary.

Further notes

We might think of reworking PolicyMonitor state machine, since it's a bit different from the other state machine and it needs constantly checking on transfer process states and policy evaluation. In the current form can be a CPU hog

Linked Issue(s)

Closes #4308

Please be sure to take a look at the contributing guidelines and our etiquette for pull requests.

@wolf4ood wolf4ood self-assigned this Jul 1, 2024
@wolf4ood wolf4ood added the bug Something isn't working label Jul 1, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 81.13208% with 10 lines in your changes missing coverage. Please review.

Project coverage is 75.18%. Comparing base (7f20ba5) to head (9957c93).
Report is 331 commits behind head on main.

Files Patch % Lines
...negotiation/store/SqlContractNegotiationStore.java 81.48% 4 Missing and 1 partial ⚠️
...transferprocess/store/SqlTransferProcessStore.java 73.68% 4 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4316      +/-   ##
==========================================
+ Coverage   71.74%   75.18%   +3.43%     
==========================================
  Files         919     1052     +133     
  Lines       18457    21114    +2657     
  Branches     1037     1180     +143     
==========================================
+ Hits        13242    15874    +2632     
+ Misses       4756     4725      -31     
- Partials      459      515      +56     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wolf4ood wolf4ood marked this pull request as ready for review July 2, 2024 06:02
@wolf4ood wolf4ood requested a review from ndr-brt July 2, 2024 06:02
Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

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

I also agree that the PolicyMonitor could be refactored into a watchdog, when it was implemented the state machine looked like the more natural thing to do, but in fact there's only one non final state (STARTED) so the SM is definitely overkill

@wolf4ood wolf4ood merged commit 97a4f64 into eclipse-edc:main Jul 2, 2024
22 checks passed
paullatzelsperger pushed a commit that referenced this pull request Aug 13, 2024
* fix: adds order by timestamp + tests in state machines

* pr remarks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing order by on nextNotLeased in stateful entity store (SQL)
4 participants