Suppose that I have stored procedure that does following:
- Selects top 10 records matching a condition. Like say, Select TOP 10 * FROM c WHERE c.complete=false.
- It updates the complete flag to true for the 10 documents selected.
- Replaces these 10 documents that have the updated flag.
- Returns to client these 10 documents.
Suppose, from the client application, I spawn multiple tasks that all run this same stored procedure simultaneously.
Questions:
Is it possible that the two or more simultaneous run of the stored procedure can cause it to return similar documents? Or will they run in complete isolation?
Does Cosmos DB stored procedure lock the data being read?
Results observed:
None of the tasks returned same documents and the return from stored procedure was always a set of distinct documents. But I am not sure whether this behavior will be consistent. I tried running the stored procedure by spawning varying numbers of tasks as high as 20 but could not observe inconsistency.