claudioc / jingo

Node.js based Wiki
MIT License
1.02k stars 184 forks source link

File locking #180

Open TakahashiNZ opened 7 years ago

TakahashiNZ commented 7 years ago

Hi Claudioc,

Firstly can I say thanks for all the hard work you have put into this project, it looks really good.

Secondly, I have read through a number of the issues on here and I can see that you are not keen on gold-plating jingo as you are worried about it getting hard to maintain - I completely understand and support your position.

Bearing that in mind, I was wondering if you would consider including a config option that would prevent users from editing a page if another user was already editing it? I see that you currently get a warning, I just want a way to make that warning physically stop you from trying to edit the page.

Secondly, would you consider a config option that added a warning when a user opened multiple sessions, I've noticed if the same user starts editing a page in two different sessions then it is easy to overwrite work.

Thanks for your time and consideration,

cheers James

claudioc commented 7 years ago

Hi @TakahashiNZ,

and thanks for your kind words :)

Soooo... the locking problem is a very tricky one and a lot of people have tried fixing it and died trying (just half-joking :P)

The problem with an "hard lock", one which prevents someone to edit a page while someone else is editing the same page is the management of the "stale" lock. Consider this scenario:

At this point the system is in a unstable situation and recovering from it is tricky. As far as Jingo is concerned the page is still "locked", and User B is still unable to access it.

Jingo could automatically remove locks than are older than... what? One hour? One day? So User B won't be able to edit that page for so long. At this point someone will come asking for a system to FORCE the clearing of locks "If I know what I am doing, I'd like Jingo to remove that lock because I say so"... and so on and so forth.

Not to mention that at the moment the locking mechanism is in memory, so when the server is restarted all the lock will be cleared and this will happen:

This means that the locking system needs to be moved out from memory to the file system, using a lock file. But I know that people runs Jingo in multiprocess which means that at that point I'd need to consider multiple processes trying to access the same file...

As you see, locking is easy to explain, hard to implement.

claudioc commented 7 years ago

For the second question: what do you mean with "session"? Can you picture me a use case?

watashiarc commented 7 years ago

Hey claudioc,

I really love your wiki and actually would love a similar feature as well. I use Confluence at work for wikis and I've attached their document on how they handle concurrent edits. Let me know your thoughts on this implementation:

https://confluence.atlassian.com/doc/concurrent-editing-and-merging-changes-144719.html

Basically, the minor change is that users don't lock each other out, but the last person to submit changes has an option on what to do with the conflict, similar to how git merge would handle conflicts.

FranklinYu commented 5 years ago

Agree with @watashiarc. Also called optimistic lock. This should be enough for a small- to medium-sized site.