Sunday, 20 July 2014

Locking Implementation Refined Ideas

A new database containing the following information would be created in the database:-

(Content_id, User_id, Last login/edit time)

In this the content_id would be the primary key, hence only one entry for each content_id would be possible and necessary. Whenever, a shared content is edited, it's corresponding entry would be added in the database.

1. Suppose User “A” wants to edit a page “p1”, and currently no one hold the lock on “p1”  i.e., there is no entry in the database for page “p1”, then “A” gets the lock for “p1” and a row is inserted in database for “A”.

2. Now if “A” remains inactive for 14 min, then a notification pop up is shown to “A”, warning him that his lock would expire in a minute if he remains inactive and could be given to any other user requesting the lock.

3. If another user “B” asks for lock held by “A”, then we check:-
If (Present_time – Last_edited_time(from DB) by A > 15 min), then{
“B” is given the lock of “p1” and database is updated. Now if “A” tries to edit after he has lost his lock then he would not be able to do so and would be notified that some other user has the lock now and he should request for lock again.
}
else {
“B” would wait for the session of “A” to end.
}

4. If “A” completes the editing and clicks on save button then the row from database corresponding to “A” and “p1” is removed. This is important so that any other user could get the lock even before 15 minutes.

5. If two or more users are waiting for lock held by “A”, then the user who would refresh first or send the request for the lock first after expiration of time would receive the lock. In this way no priority is given to user who comes first and demands for the lock, but is given to the user who demands for the lock once the lock is released.

No comments:

Post a Comment