none
How to ensure the coherence in this case? RRS feed

  • Question

  • I have work orders and tasks.

    WorkOrders(IDWorkOrder, status,...)

    Tasks(IDTask, IDWorkOrder, status,...)

    The status of the work order is open or close and the task is pending or finished. A work order can not be closed if there is any task pending, so when I want to close the work order, I have to ensure that all tasks are finished.

    Also, it is possible that when I am closing a work order, another user is changing the status from finalized to pending to correct an error.

    Another problem if all the tasks are finished and I try to close the work order, another user can add a new task while the work order is trying to be closed. It is possible that at the end, the work order will be closed but with one task pending.

    The basic problem is of concurrency.

    The process is:

    I load the work order and include all the tasks.

    Check if all the tasks are finished. If yes, I can close the work order, if not, no. But here another user can add a new pending task.

    So in this case, how can I ensure the coherence of the data?

    I am thinking in the posibility to block the work order when I want to update the work order, when I want to add a new task or when I want to add a new task.

    So the prcess would be:

    I create a transaction

    I update the work order to block the record. When I want to add a new task, first I try to update the work order in which I want to add the task. If another user is updating the work order, add a new task or update a task, the user was blocked and then has to wait.

    When the first user that blocks the work order finished her action, the next user can start her action.

    This is a solution, but I have some questions:

    The cost of the transaction. Is it very expensive to use a transaction?

    Is it a good solution?

    Another option is to use concurrency, with a timestamp field in the work order, and update the work order. When I save changes in entity framwork, check the timestamp and if is the same, is because nobody add or update a task, o update the status of the work order.

    The problem with this solution is that if the work order has many tasks and I have to load all of them to ensure that all are finished, if another user change the timestamp value of the work order before the first user finish her action, has to repeat all the process and load all the tasks again. This has a cost too.

    What is better solution for scalability and performance? Block the work order to ensure that process can start and finish in the first attemp but block to another process or use concurrency with the problem that perhaps I have to retry N times until no other process update the work order (and to load N times all the tasks)?

    Thank so much.

    Tuesday, March 17, 2015 9:36 PM

Answers

  • Hello,

    >>The cost of the transaction. Is it very expensive to use a transaction?

    Actually, Entity Framework would use a internal transaction when we call the SaveChanges method everytime and close it. It is equal to use the explicit transaction by using the TransactionScope class, the difference is the scope of the transaction.

    Your second solution seems that you will check the status of WorkOrder in a loop, I think it might not be a good idea since in real environment, it is hard to ensure how many time it needs to check the status.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 18, 2015 6:37 AM
    Moderator