From: Matthew B. <mat...@ou...> - 2006-06-14 12:13:41
|
Jon Maber wrote: > Matthew Buckett wrote: >> User 1: get current quota 8.5MB of 10MB >> User 2: get current quota 8.5MB of 10MB >> User 2: set quota to 9.5MB and upload 1MB file. >> User 1: set quota to 10.5MB and upload 1MB file. >> >> Now user 1 has exceeded the quota but still has the file uploaded which >> shouldn't be allowed (or should it?) >> >> The other option is to check after changing the quota with another >> select that the quota is set to the expected value (although this really >> is just an expansion of the collection of fields update) > I'll let you and Ian discuss the general case (because id have to study > a book on the subject to catch up with you). > > Did you say if your code is directly calls the SQL or wraps records in > the quotas table in a Bodington PersistentObject subclass? At the moment I don't have a quota table but use two metadata entries as most of the time we don't need to know the quota so performance isn't crucial. This could change in the future. > If the latter then database reading and writing will operate through a > single instance of that class so you could add a method like this; > > public synchronized boolean attemptUpload( long size ) > { > // this class knows the value of current uploaded bytes > // return false if already over limit. > // add to uploaded bytes record. > // call standard save record routine > // return true > } > > The important thing is that this routine does the 'over limit' > calculation and the save record part in the same synchronized block. Even if I don't have a Quota class I could do the synchronization on the resource object to which the quota is attached. This only works in a single JVM although there are some projects attempting to weave extra bits in to allow locking primatives to work across JVMs. http://www.terracottatech.com/terracotta_Spring.shtml -- -- Matthew Buckett, VLE Developer -- Learning Technologies Group, Oxford University Computing Services -- Tel: +44 (0)1865 283660 http://www.oucs.ox.ac.uk/ltg/ |