Database Management for Smalltalk

Optimistic Locking

Optimistic Locking

 
“Labelling this scheme optimistic maligns a perfectly good philosophy.”
(“Transaction Processing: Concepts and Techniques”, p435, Gray & Reuter, 1993, ISBN 1-55860-190-2).

In an effort to increase concurrency, some database management systems offer optimistic locking, in which locks in a read-write transaction are released early, and the transaction proceeds on the assumption that data objects will not be changed before commit. This assumption is checked at commit, causing the transaction to be rolled back if it is found that an object has indeed been changed by another transaction in the meantime.

Optimistic locking can improve concurrency in applications where the majority of transactions are read-only, since these are able to proceed when they might otherwise be blocked by an exclusive lock of a read-write transaction. However, if too many transactions are read-write then it causes all but one of the contending transactions to abort commit and rollback, to be re-tried from the beginning, which, as the above quotation suggests, may be worse than just waiting for locked objects to become available.

Optimistic locking is a special case of a more general technique known as a “field-call”, in which the assumption checked on commit is a more general predicate than just “not changed by another transaction”. For example, the condition tested could be the that the quantity-on-hand of an inventory item is still greater than zero at commit, even if it has been changed in the meantime, together with a deferred update in a redo log entry which is applied if the condition stored there is found still to be true. Unlike simple optimistic locking, field-calls do improve concurrency of contending read-write transactions, but the disadvantage is that such transactions do not see their own updates if they make more than one change to the same object.

 

Application-specific optimistic locking

Neither optimistic locking nor field calls are implemented in VOSS 3.1. However, application-specific optimistic locking can be programmed for specified objects by designing the application to make working copies (VORefPublic>>realCopy) and note their last commit timestamp (VORefPublic>>timestamp), during a preliminary read-only transaction which then rolls back, releasing its locks.
These real (i.e. non-virtual) working copies may be changed at leisure in a read-write transaction, and then used to update their respective virtual (persistent) originals (VORefPublic>>voPoke:), after having checked that none of them (this is an all or nothing transaction) has a timestamp (VORefPublic>>timestamp) later than it had when the working copy was made, which would indicate a change having been committed by another transaction in the meantime, thus invalidating the basis for commit.

Before poking in the changed working copy, be sure that that copy is never going to be sent another message, as it is that actual granule which is to be poked into the virtual object, and direct messages to it are then subversive and illegal. In practice this may be assured by using temporary variables to reference the working copies. If for some reason this cannot be assured, then update the virtual object by poking in a copy of the modified working copy. As the working copy is an arbitrary structure of Smalltalk objects, this copy of it should be made using the message: Object>>voTotalCopy.

Will optimistic locking help or hinder? When choosing between automatic pessimistic locking and programmed optimistic locking, consider the statistics of the application. How often will other transactions need objects whilst they are being updated? Does it matter if their transaction has to wait for an updating user to finish?

Consider imposing a time limit on potentially long open-ended read-write transactions, which a user might begin and accidentally leave open, holding locks, whilst attending to some other task such as lunch.

If the majority of transactions are updates, programmed optimistic locking will probably not give better results than the automatic pessimistic locking, as it means that lock waits are converted into aborted commits, which require the transaction to be restarted from the beginning.




 
cancer treatment effects of celexa buy proscar real levitra online online cialis no prescription buy cialis where luvox cr cialis online without prescription rx-viagra chewable cialis buy levitra onlines cialis 10 online allegra effects of high blood pressure buy alpha lipoic acid phentermine no perscription medician for heart attacks chlamydia medication dosage alternative cholesterol treatment buy lasuna natural constipation remedies nitroglycerin sublingual site viagra treatment of heart attacks seroquel for depression buy cialis how to boost immune system healthy pets cialis alcohol buy canada levitra scabies medicine cheapest cialis price buy pain medicine on-line immune system support products cats hairball low prices pain meds alcoholism treatment option new treatment for depression buy tribulus discount vitamin vitamin a natural arthritis cures chlamydia antibiotics viagra prescription lisinopril 10mg celecoxib medicine ultram buy discount cialis famvir dose buspar viagra online usa herbal antifungal and antibacterial buy viagra hypnosis to stop smoking buy discount cialis depakote 250mg buy lipothin viagra to buy how to take a beta-blocker buy cialis without prescription diazepam 10 mg what causes hair loss in women buy cheap cialis without a prescription cheap cialis tadalafil generic viagra on line menopause treatment zantac medication dog tooth infection cialis 30 effexor dose buy glucosamine sulfate metoprolol dose diet hoodia gum side effects levitra cialis on line stomach parasites viagra online cheap breast increasing oils buy paxil online online cheap viagra buy buy viagra order viagra cialis 5 aspirin medicine at home acne treatment canada cialis generic buy mycelex treatment of stroke order viagra plus zyprexa 5mg buy diazepam approved cialis fda itching relief viagra online usa hair loss treatment online information on levitra immune system supplement how to buy viagra beta blocker uses adhd treatment buy online viagra buy cialis online in usa adhd in women cats inflammatory bowel disease cialis viagra valtrex dosage cheap breast augmentation buy cialis online with a prescription prescription ibuprofen healthy women's vitamins dog site health treatment for lung cancer cialis without a prescription cialis 5mg cheap order viagra online discount viagra online order celebrex hypnotherapy for health synthroid doses hypothyroidism medication discount cialis online cialis 50mg help for infertility top ten acne products buy pain killers reducing cholesterol naturally viagra tablet dosage zoloft viagra cialis cialis comparison online stores hair loss products medications ativan lowering blood pressure naturally fluconazole cialis 20 mg buy augmentin buy cialis online cold flu menopause gum online pharmacy viagra buy cymbalta fluconazole capsule jelly kamagra brand viagra online cialis prescription online cialis without rx irritable bowel syndrome cures zestril medication cheapest online cialis buy celebrex online buy viagra on line