Refactor use of ensureStructure to reduce locking #295

Open
opened 2020-03-30 13:41:12 +00:00 by matthijskooijman · 0 comments
matthijskooijman commented 2020-03-30 13:41:12 +00:00 (Migrated from github.com)

Currently, the mailinglist and article datatypes use an ensureStructure() method that creates any missing structure if needed. It is called on every request, which seems a bit much.

In practice, there might be two problems:

  • The mailinglist version always starts by locking the XML file, even if nothing turns out to need changes. This means that all requests take a write lock and can no longer run entirely in parallel, which might be inefficient.
  • The peer reviewed article version only takes a lock (and only does work) when the status is NEWLY_CREATED, but it does not recheck the status after taking the lock. If two requests happen concurrently, both might end up adding structure, resulting in duplicate elements. This is rather unlikely, since the first request after creating a page (by the page creator) will usually create the structure anyway.

I think it might be better to have a scheme where the datatype is involved in creating the page, so the initial content can be added as part of the page creation and happen just once.

Currently, the mailinglist and article datatypes use an `ensureStructure()` method that creates any missing structure if needed. It is called on *every* request, which seems a bit much. In practice, there might be two problems: - The mailinglist version *always* starts by locking the XML file, even if nothing turns out to need changes. This means that all requests take a write lock and can no longer run entirely in parallel, which might be inefficient. - The peer reviewed article version only takes a lock (and only does work) when the status is `NEWLY_CREATED`, but it does not recheck the status after taking the lock. If two requests happen concurrently, both might end up adding structure, resulting in duplicate elements. This is rather unlikely, since the first request after creating a page (by the page creator) will usually create the structure anyway. I think it might be better to have a scheme where the datatype is involved in creating the page, so the initial content can be added as part of the page creation and happen just once.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
harmen/hypha#295
No description provided.