[tahoe-dev] Lock files in Tahoe directories

Shawn Willden shawn-tahoe at willden.org
Tue Jul 21 15:55:25 UTC 2009


I have a situation where I need to allow multiple clients to update 
directories full of mutable files in a controlled way.  On a local file 
system, I'd use lockfiles to synchronize/serialize access.  I'm looking for 
some way to do that effectively with Tahoe files.

According to mutable.txt, the Prime Coordination Directive is "Don't Do That".  
Specifically, uncoordinated writes to tahoe mutable slots are just asking for 
bad things to happen.  However, it occurs to me that perhaps I can coordinate 
writes through Tahoe if I use different slots to do it.

The idea is that I'll create a "lockfile directory", in which each client will 
write a lockfile named, say, "<clientid>.lock".  This directory and its 
lockfiles will be populated in a controlled way so that no two clients are 
updating it at once.  The lockfiles will all be empty to begin with.

When a client needs to update shared files, it will do the following:

1.  Scan the lockfile dir and load all lockfile contents.
2.  If any lockfile is non-empty, sleep a random amount of time (say, 20-60s) 
and go to step 1.
3.  Write a timestamp and textual description of the planned update into its 
lockfile.
4.  Wait a few seconds (say 10-20) and re-read all lockfile contents.
5.  If any lockfile other than its own is non-empty, truncate its lockfile and 
go to step 1.
6.  Make updates to shared files.
7.  Truncate the lockfile.

The use of a timestamp and update description in step 3 is just to facilitate 
manual debugging.

The big question is whether or not the delay in step 4 is sufficient and, 
indeed, whether *any* amount of delay is sufficient to guarantee that write 
conflicts cannot occur.

I guess the best approach would be to implement a coordination server, as 
suggested by mutable.txt.  Perhaps if someone who knows the codebase outlined 
where I should look to get started on that, mayabe I could do that.  I would 
think coordination should be a service offered by a node, rather than a node 
type, probably enabled by setting "[coordinator]/enabled=true" in tahoe.cfg, 
similar to the helper config.

Comments, suggestions?

Thanks,

	Shawn.



More information about the tahoe-dev mailing list