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

Allow configuring options per Execute calls #738

Closed
lahma opened this issue May 26, 2020 · 6 comments
Closed

Allow configuring options per Execute calls #738

lahma opened this issue May 26, 2020 · 6 comments

Comments

@lahma
Copy link
Collaborator

lahma commented May 26, 2020

Allow overriding defaults for max statements for example for trusted scripts, otherwise would run with engine level constraints. This would probably mean creating a context that would pass through statement calls, context would have options which is engine default or user provided.

Relates to RavenDB's need to change max statement on use case basis.

@ppekrol
Copy link

ppekrol commented May 26, 2020

In RavenDB we have 3 flows for this:

  1. Change it permanently to X value
  2. Change it temporarily to X value, then go back to original (using dispose pattern)
  3. Disable it temporarily (set to int.MaxValue), then go back to original (using dispose pattern)

If 1. will return the old value, then 2. and 3. could be easily handled by us, no need to for a built-in mechanism for that.

As @lahma wrote, the reasoning is the source of the script, when it is an internal one (e.g. parsing our built-in scripts or a library - done on engine initialization) then we do not care about the max statements constraint, but when the script is passed by the user, then we need to have some safe guards.

@lahma
Copy link
Collaborator Author

lahma commented Oct 24, 2020

Hey @ppekrol sorry for the long wait. I think I've solved this in #789 where we also want to disable constrains when initializing engine pool. Basically for your use case:

var options = new Options(); // the defaults you want to go with
var engine = new Engine();
using (engine.ActivateTemporaryConstraints(Array.Empty<IConstraint>()))
{
    // do a lot of things with engine
}

var tempConstraints = new Options().MaxStatements(42).LimitMemory(1024).CancellationToken(token).BuildConstraints();
using (engine.ActivateTemporaryConstraints(tempConstraints))
{
   // allow calling engine with limited resources
}

Please note that we are also in that PR building a safer (but probably not bullet proof) context that is able to dispose registered variables etc.

API may change and all feedback welcome!

@ppekrol
Copy link

ppekrol commented Oct 28, 2020

Hi @lahma

Will there be an ability to change just one constraint? Now I see you need to create new options for those each time. Can options be cloned maybe? What do you think?

@lahma
Copy link
Collaborator Author

lahma commented Oct 28, 2020

My thinking was that you have like three sets of constraints pre-built. You can build those as static arrays using the example Options and then just switch between them during your specific use case. There's no need to build them every time.

In other words you would switch between constraint sets instead of replacing constraint in one set.

@lahma
Copy link
Collaborator Author

lahma commented Oct 28, 2020

And correcting previous, because constraints have state, they need to be build per use case, but the options are static.

@lahma
Copy link
Collaborator Author

lahma commented Jul 13, 2024

I'm closing this as there are workarounds and this would be non-trivial to implement.

@lahma lahma closed this as completed Jul 13, 2024
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 a pull request may close this issue.

2 participants