[ Content | View menu ]

Optimistic Locking or “Dude, Where’s My Data? ”

May 9, 2008 by Lee Horowitz
Filed in Uncategorized

Lets say Alice and Bob are using a web interface to maintain data stored in a back end
database.

First Alice brings up record 42 and begins reviewing it for potential corrections.

While she is working, Bob comes along, signs in at a different work station and reads the
same record 42. He notices that the field named “B” says “Kilroy was here”, so he changes
that to say “Bob was here” and saves the record back to the database.

Working carefully, Alice soon realizes that she should change the data in fhe field named “A”.
She makes the change and saves the record.

A little while later, Bob’s boss, Zelda, brings up record 42. There in field “B” she sees
“Kilroy was here”. Bob swears he changed that, Zelda is skeptical. Alice says “Hey, my edits
are just fine, whats the fuss about?”

What happened?

Alice and Bob both saw the same original record data, and brought separate copies of the
data into their local computer environments.

When Bob saved his work, he updated the copy in the database, but did nothing to Alice’s
copy that ALice has in her local working storage.

When Alice saved her edits, she also restored the original (Kilroy was here) version of
the data in field B which she did NOT edit.

When a record has multiple fields, as is the usual case, it is very common for the update
code to be implemented the following steps:
1. Acquire the original record and pass all fields to the end user for update
2. When the user is finished, replace each and every field in the database with the version
sent back to the updating program by the end user, whether the end user has in fact
“dirtied” (changed) the fields or not.

Doing it this way in effect implements a contract with the user saying “I’ll give you the
original data, You change it to the way you want it to be, and I’ll put all that back into the
database that way. This relieves the update program from having to “know” which fields the
user updated and which were left unchanged. For the sake of simplicity, all fields are
written back to the database.

“Aha!”, I hear you say. “If only the update program had kept track of which fields were
clean and which were dirty (i.e. which had been changed by ALice and which not) all
would be well”.

Close but no cigar. In this case, where Bob had changed field B but ALice had changed field
A, we would have escaped danger.

But suppose Bob had changed field A. Suppose field A had said “Kilroy was here” and Bob
had changed that to “Bob was here”. Alice’s original version still say’s “Kilroy was here”.
Had she changed that to “Alice was here”, the final version of the record would have said
“Alice was here” and Zelda would have seen “Alice was here” when she expected to see “Bob
was here”. Bob cant win.

The real problem is that by the time Alice came to the point where she wanted to commit
her changes, her working copy had become obsolete, because Bob had refreshed the database
without her knowing it.

The simple solution is to lock the record when it is selected for Update.

In this case (Called Pessimistic locking), we’ld lock the record when Alice reads it.

When Bob comes along, he’ll find that he cant aquire a lock on the same record, because Alice
beat him to it. Worse yet, we said that Alice was working slowly and carefully and would
hold the record lock for many minutes, so the “window” during which that record would be
locked could be relatively long. So Bob could keep trying to get the record for that many
minutes without success. Bob still cant win. He wont lose his edit, but now he’s got to
wait for ALice to finish with it.

Many web implementation favor the following “Optimistic” locking scheme:

1. Store something with the record which indicates its timeliness. A “date last updated”
will do, but some systems like to store a special “system commit number”.
For this to work, each time a record is updated, the “date last updated” field or the System
commit number field must be updated as well. The date field is set to the current date and
time, the SCN field is an integer which is incremented for each update.

2. When Alice reads the record, she also reads the “As of” information (the date or the SCN).

3. When Bob reads the record, he also reads the “As of” information.

4. When Bob saves his data to the database, the update routine locks the record, and reads
the “as of” information. If Bob’s “as of” data matches the current database version of the
as of value, (in this case it does), then the update routine performs the update and
releases the lock.

If the “as of data” had been a mis match, the update program would have simply released
the lock without doing the update, and then would have informed Bob that he’s lost this
round, he cant update his record because he was working from an old snapshot of the data.

(That doesnt happen to Bob in the scenario we’ve outlined because he was the first to
change the data)

5. When ALice moves to save her data, she’s the one to get the “Sorry, too old” message.
because when Bob saved his data, the “As of” information in the database became different
from the “As of” information that Alice has stored in her local working memory.

Now ALice needs to re-aquire the record to see the latest and greatest data, to decide
if it still needs updating.

Since ALice held the record longer, it is arguably fairer that she has a better chance
of running into the “snapshot too old” error than Bob who quickly aquired the record, did
his edit and saved the data.

There are some tools (Oracle’s Sql*Forms, for example) that do optimistic locking for you,
behind your back. But if you are using some lower level tools, the onus is on you the
developer to understand the locking issues and to implement an effective locking strategy.

Fortunately, “Optimistic Locking” is easy to implement and well suited to most web
applications.

Post or View Comments (0)

The Once and Future Genre: Online Exhibitions

May 1, 2008 by Jennifer Anderson
Filed in Omeka, interfaces, Collections, Design

[Barbara Gittings and Randy Wi... Digital ID: 1605792. New York Public LibraryOn April 3, NYPL launched (with fantastic success!) its LGBT Committee program and its accompanying website, LGBT@NYPL. Originally the site had a specifically bloglike purpose; it evolved into more of a portal for accessing the LGBT-themed collections and events at the Library. To the site’s images, posts, lists of resources, and opportunities to become involved with the LGBT Committee, we are about to add an online exhibition of the photographs of activist Barbara Gittings. Tracy Bunting, our intern from NYU, has been working with editor of LGBT@NYPL and staff manager of the LGBT Committee Jason Baumann to collect and contextualize the photos for the exhibition. For my part, I’m designing the exhibition using Omeka—an online exhibition platform developed by The Center for History and New Media and the Minnesota Historical Society.

Omeka is similar to Wordpress (which we’ve also used here at NYPL) in that it’s written largely in PHP and depends on CSS for all its layout. I’m pleased to be taking what I know from Wordpress and applying it here, but I’m even more excited to try my hand at designing an online exhibition—something I feel is almost never executed correctly. I’m not sure I even like the term “online exhibition.” Placing “online” as a modifier to “exhibition” suggests two things: a webified version of the physical, “real” exhibition, or a static website that displays a bunch of stuff (usually images) in some kind of linear order. Either way, you get an imitation of a real-world circumstance, which is not what the web should be at all.

More on The Once and Future Genre: Online Exhibitions

Post or View Comments (3)

Rethinking the Redesign

April 18, 2008 by Jennifer Anderson
Filed in Usability, Design, Digital Gallery

Lost ball.  Digital ID: 1134444. New York Public LibraryThere’s nothing like a good old round of user testing to humble you. On Tuesday and Wednesday of this week, myself, Joe Dalton, and Michelle Misner went among our public to find volunteers to run through our short testing script on the Digital Gallery redesign. While we’ve got some more testing to do (for example, among some staff users), I can make a couple predictions based on our tests so far. First, there’s some confusion about the difference between “search” and “browse.” Second, our users rely on the Collection Guides for more than I thought. And finally, our search functionality kind of sucks.

More on Rethinking the Redesign

Post or View Comments (1)

Fun with jQuery

April 16, 2008 by Greg Kallenberg
Filed in Development, Code, Ajax

International Code

Am experimenting with the jQuery library for fun effects on the calendar application. I’m going to be replacing the “show/hide” function with a jQuery.slideToggle() and the AJAX calls for the calendar widget with jQuery.load().

This will help to reduce the amount of code developers will have to write in order to achieve the same effects. Instead of having to write 80+ lines of code, I can use jQuery and 5 lines of code to perform the same actions.

Have successfully added all of the effects and AJAX calls to the calendar application front-end, and now on to the testing phase. Hurray for cleaner code!!

I hope to post the new effects to the calendar front-end soon. Stay tuned.

Post or View Comments (0)

NYPL on iTunes U.

April 8, 2008 by Barbara Taranto
Filed in Communities, Collections, Collaboration

New York Public Library has joined the universe of cultural and educational institutions making their content available on iTunes U.

Take a look at our new site.

iTunes

Thanks to Brian Hurley, Don Mennerich, James Briggs Murray, Rich Stalzer and Michelle Misner who worked together to make this happen.

Post or View Comments (10)

Ah, Timeshifting: From Betamax to Blockbuster (review)

by Jay Datema
Filed in Development, authors, Communities

From Betamax to BlockbusterAlthough he’s been too modest to mention it here, Josh’s first book comes out this month from MIT Press. Entitled From Betamax to Blockbuster, it charts the history of the video store, the dueling formats that made it work, and the inevitable consolidation that changed a conversation point into a commodity.

The introduction is available for download, as is the appendix, which charts the development of a survey (now living in DSpace) which provided additional information to supplement scholarly research.

There’s a podcast on the book page that further whets my interest in reading it in its entirety. The interview with Josh starts about 17 minutes into the recording.

Post or View Comments (0)

Paper Dolls, Skins, Lenses - what have you.

April 4, 2008 by Barbara Taranto
Filed in Taxonomy, interfaces, Content, Collections

Last week Susan Schreibman (recently of UMD) and David Kennedy (presently at UMD) visited NYPL Labs to share their experiences with operationalizing FEDORA as a digital collections management tool. Susan spoke mostly to the organizational challenges and successes and David spoke to the technical implementation and goals for the project. Their presentation was a reprise of the one they gave at CNI last year and it was clear and right to the point. Repositories are for “dipping in” and the more tools we can develop to make the “dipping” easier, the more use the collections will have.

Paper cutouts

It was reassuring to hear that other libraries are tackling the issues around different layers of abstraction in the service of presenting repository materials for consumption by a non-technical audience.

Of course, we have all been worrying this for years and for years we have been doing the work manually by building stand alone applications to meet the needs and the peculiarities of our collections.

One of the key strategies in the UMD approach (so as to avoid the handcrafted work) was to model a set of presentation skins that could be employed agnostically to content in the repository. What was different about UMD’s approach was that the skins were incorporated into the data model and were a clever implementation of the disseminator features of FEDORA architecture.

This of course speaks to my obsession with multiple views on the same content.

More on Paper Dolls, Skins, Lenses - what have you.

Post or View Comments (1)

LGBT site goes live!

by Barbara Taranto
Filed in interfaces, Content, Collections, Design

Check out the new site LGBT@NYPL - Connecting you with the LGBT collections, programs and expertise that The New York Public Library has to offer.

LGBT

Kudos to Jason Baumann, Jennifer Anderson and Michelle Misner who worked on putting it together.

Post or View Comments (0)

Launching Softly

March 25, 2008 by Jennifer Anderson
Filed in Development, Usability, Design, Digital Gallery

Sailing. Digital ID: 833234. New York Public LibraryI’ve been thinking a lot lately about new methods of releasing products/art/information. I am a serious Nine Inch Nails fan, so imagine my surprise a few weeks ago when I discovered their new album via the official website. No press, no ads, just a post on the website. While I could care less who “did it first/best/etc” of the artists who have recently released music this way, I do care about the general concept of the fanfare-free release. Is it even a real launch without the publicity? Is the correct term a “soft launch?” Is a soft launch ultimately a better release method—at least for usability-driven sites like the Digital Gallery?

More on Launching Softly

Post or View Comments (4)

Haven’t We Met Before?

March 24, 2008 by Kristopher Kelly
Filed in interfaces, users, Databases, Metadata

The Scout’s Handshake and Salu... Digital ID: 1135560. New York Public LibraryIt’s a useful skill in life to remember the people you’ve already met, if only to avoid the ‘Hey, it’s … YOU!’ conversation. A personal rule of thumb when I don’t remember someone’s name is to say with confidence some other name, and, even if corrected, to continually refer to that person by the wrong name. That way, you’re remembering something, which is a little better than remembering nothing. No?

More on Haven’t We Met Before?

Post or View Comments (0)