inmanta / inmanta-core

Inmanta is an automation and orchestration tool
https://inmanta.com
Apache License 2.0
27 stars 7 forks source link

Allow top-level lsm layer to be constructed first #7379

Open sanderr opened 8 months ago

sanderr commented 8 months ago

Use case

Force lsm top-level instance creation to finish (breadth-first) before continuing execution. The main motivation is to not trigger side effects (e.g. allocation) until all instances are constructed. This allows us to guarantee that no side effects will happen if e.g. an instance fails to construct because of an index collision.

Other potential benefits could be to avoid list freezes unitl all instances are unwrapped etc.

Ideas

(brainstorm-grade)

Atomic for

A new type of statement for a non-gradual, atomic for loop:

Open questions/issues:

immediate keyword

Add an immediate (/ urgent / ...) keyword that signifies that a statement should get priority. This would allow for a two-layered execution: the compiler guarantees that no non-urgent statements (with some well-defined exceptions) will be executed until the urgent ones have finished execution.

immediate condition = true

for instance in lsm::all(...):  # parent of immediate statement -> immediate itself but other children aren't
    immediate MyEntity(...)
end

Alternatively, the keyword could be part of an entity definition.

Open questions/issues

edvgui commented 8 months ago

what if allocation is part of the for body?

I can tell you it most certainly is, this is the only way to not have the allocated attributes set to null on the constructed object (as the api requires a default value defined in the model for these read-only attributes). The alternative to setting these attribute in the constructor call is to call the allocator plugin everywhere we need it, but this looks a lot less clean (imo).

With partial compile, indexes are not a suitable guard for the primary invariant check. Instead, I believe plugins / allocation is used, which is exactly what we're trying to postpone here.

This makes me think that the way forward is maybe simply to make it easier for the developer to check these index constraints with plugins. I think it would be possible to have such plugins with a generic implementation, looking up the relevant index in the model, and making all the required checks based on the service attributes (not the service instance). Such plugin could then be called as the condition of an if in which the instance would be constructed.