I am trying to solve an issue of concurrency in my system without trying to use locks. So, far I am unable to think of any solution to this. Any suggestions / ideas will be of great help.
Scenario:
There exists two types of entities in my system (stored separately in databases):
- Documents (There can be a large number of documents)
- Templates for categorizing those documents. Templates contains attributes and documents matching those attributes become member of the templates.
There is no sequence to action on templates and documents. Action on both can happen parallely at any point of time.
Following actions happen on Templates
- New template creation leads to the first version of the template
- Any updation of the template leads to a newer version of the template
- Template creation and updation leads to a query to map documents matching the template and the list of document identifiers are mapped and stored along with the template.
Following actions can happen to documents at any time:
- New documents can be added
- Existing document properties can be modified
- Existing documents can be deleted
Each of the above operation on documents leads to re-evaluation of the document's membership to the template and the template's current version document is updated to reflect the correct set of document identifiers which are members of the template. For Ex: when a new document is added, it is checked to see if it's attributes matches to ones in the current version of the template and if so, it is added to list of document identifiers in the template.
The concurrency issue arises mainly on the template document and in it's list of member document identifier storage. Since, the updation of member document list for a template can happen parallely between template creation / updation and creation / updation of different documents, this can lead to incorrect data if not handled correctly.
Right now, this is being solved by using a lock such that creation / updation of a template and creation / updation of documents are mutually exclusive.
Are there any mechanisms using which the concurrency can be handled without locks?
Aucun commentaire:
Enregistrer un commentaire