Skip to content

OAK-11766 Write Throttling Mechanism - Session.save() delay #2339

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

Merged
merged 4 commits into from
Jun 24, 2025

Conversation

thomasmueller
Copy link
Member

@thomasmueller thomasmueller commented Jun 18, 2025

A minimal configuration for this is:
Staring the process using -Doak.sessionSaveDelayer=true
RepositoryManagement - SessionSaveDelayerConfig: {"entries":[{"delayMillis":1,"threadNameRegex":".*"}]}

Copy link

Commit-Check ✔️

return cachedMbean;
}

public long delayIfNeeded() {

Choose a reason for hiding this comment

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

Can this method be called by multiple threads?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. By default it is disabled. We need to be extremely careful that there is no error, or performance issue, if disabled.

If enabled, I think we don't need synchronization. It is fine if the configuration is read multiple times in some edge cases. But even in this case, we should try to prevent errors (NPE etc, setting the interrupt flag). But performance issues are not the highest priority in this case.

Choose a reason for hiding this comment

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

Good point. I think that the disabled path is fine. The enabled path is a bit tricky though: since we access non-volatile fields from multiple threads without any synchronization, we have race conditions (according to the Java memory model). This might work fine but is hard to analyze. For example, if one thread sets lastConfig and another thread reads the new value, I'm not sure if we don't risk NPE accessing individual fields of the referenced object (since there was no safe publish of the object). IMHO, protecting the "enabled" path with a single lock, even a simple synchronized { ... } block, has less chance of introducing errors than unsafe access.

Copy link
Member Author

@thomasmueller thomasmueller Jun 24, 2025

Choose a reason for hiding this comment

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

It is sufficient if the fields of SessionSaveDelayerConfig are final; see https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.1
that means the JVM memory model guarantees that other threads see the fully constructed object if the constructor returns, via memory barrier.

We actually had an issue where we missed this, and this caused issues for ARM CPUs: https://issues.apache.org/jira/browse/OAK-9634

@thomasmueller thomasmueller requested a review from mkapalka June 20, 2025 15:14
Copy link

@thomasmueller thomasmueller merged commit 201c1c8 into trunk Jun 24, 2025
5 checks passed
reschke added a commit that referenced this pull request Jun 24, 2025
reschke added a commit that referenced this pull request Jun 25, 2025
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