Azure / azure-functions-durable-python

Python library for using the Durable Functions bindings.
MIT License
136 stars 55 forks source link

Proposal: Support Entity Locking #277

Open davidmrdavid opened 3 years ago

davidmrdavid commented 3 years ago

We need to support the Durable Functions lock API that allows users to establish a critical section for serial Entity updates. I believe this would be the first OOProc PL to support this feature, so I want to make sure we're in the same page about how we plan to implement it.

I imagine the API would be yieldable, giving us an opportunity to pause the orchestrator execution if the lock cannot be readily acquired, and that it would take as argument a list of EntityIds.

In other words, I expect its interface to be as follows:

def lock(entityIds: List[string]):

Proposed syntax and usage patterns

The first, and recommended, usage pattern would be one where the lock disposal is automatically managed by some context manager, so as follows:

entityIds: List[string] = ["myEntity1", "myEntity2", ... ]
with (yield context.lock(entityIds)):
    # entity ops ... the lock is released at the end of this segment

The second usage pattern is one where entities are locked and released manually by separate APIs

entityIds: List[string] = ["myEntity1", "myEntity2", ... ]
yield context.lock(entityIds)
yield context.release(entityIds)

I expect we'll want to support this second option because not all OOProc PLs with necessarily have a convenient lock-disposal syntax such as Python's "with" statement.

Please let me know if y'all have any thoughts. Otherwise, I'll proceed to prioritize this for an upcoming release. Thanks!

matthewdelaney commented 2 years ago

Hey @davidmrdavid . I just ran into a pressing need for this and was wondering: in the meantime, is there anything you could advise that would do as a workaround? It seems like there probably wouldn't be but I figured there's no harm in asking.

davidmrdavid commented 2 years ago

Hi @matthewdelaney.

Thanks for reaching out. Unfortunately, I'm not personally aware of any workarounds for this, but reaching entity feature parity is next on our list, so this feature should be coming up in the coming months.

Taking a step back, perhaps your scenario does not necessitate entity locking. Please feel free to create a new issue describing your scenario and we may be able to provide guidance on workarounds :-)

fernandorovai commented 1 year ago

Hi @davidmrdavid, do you have any news regarding this feature? I'm facing issues on using entities as flags for my logic in orchestrators.

I realized we have some overwriting/reading on the entities when we use multiple orchestrators, making the entity state not reliable and eventually destroying our logic. Any suggestions?