Pinning items into memory

June 3rd, 2004 at 5:06 pm (3 years, 11 months ago) by Andi Vajda under chandlerdb

OSAF chose a non-locking transaction model for Chandler’s repository. One advantage of that choice is that items are never locked. Conflicts between concurrent changes to the same item in different repository views are detected and reported at the time they’re committed to persistent storage - sophisticated version merging is planned but not yet implemented.

One disadvantage of that choice is that as items get changed in several views, when a view is refreshed - right after a commit operation - out-of-date items held by this view are marked stale and are no longer usable. The programmer must fetch the item again from the repository via a find() call to get a fresh item instance.

One consequence is that keeping python pointers to items past commit operations is unsafe and unpredictable. A workaround has been to keep pointers to their UUID instead and always find the items by these cached UUIDs when an item’s instance is needed again. While functional, this workaround is somewhat cumbersome.

Given that only the Chandler attributes of an item instance are persisted and that the innards of Chandler attributes are entirely controlled by the data model implementation, except for collection values, it is actually possible to refresh an item in-place after it was marked stale during a repository view refresh, thereby avoiding that the item’s python pointer is not marked stale.

But guaranteeing that item pointers never go stale contradicts repository view pruning. A repository view is pruned of its least used items when it exceeds by 10% a certain item count (currently 10,000, an arbitrary value) so that its item count goes below 90% of that threshhold.

Therefore, a new API was added for pinning an item into memory. Pinning an item guarantees that the item’s python pointer is never marked stale, unless the item is actually deleted. Overusing pinned items defeats repository view pruning and should be used sparingly. Because schema items are so essential to Chandler’s operation they are pinned into memory by default. Programmers needs to decide when to pin and unpin non schema items into memory on an as-needed basis.

To pin an item into memory : item.setPinned()
To unpin an item from memory: item.setPinned(False)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit

2 Responses to “Pinning items into memory”

  1. vajda Says:

    Well, yes and no. Yes, the repository is sending out notifications to all the callbacks listening to them - typically, Chandler’s Notification manager - so there’s a way to get notified but no, there is no callback being invoked directly on the item when it is marked stale and refreshing it fails because of it being deleted. It would be simple enough to add one if needed.

  2. bear Says:

    Very cool - thanks for blogging items like this. It’s much easier than tracking down commit entries :)

    About the pinning - if an item is deleted will the owner of the pin receive some sort of notification? Or is that even an worry?

Leave a Reply