Dear all,

The forthcoming version of NaviServer will support transaction semantics
for ns_cache.

Background: when ns_cache_* commands are used within DB transactions
(e.g. in OpenACS), it might occur, that partial results of the
transaction are cached before the transaction is committed. When the
transaction is rolled back, invalid values might be kept in the cache
leading to erroneous and hard to debug behavior. Furthermore,
information about committed changes might leak into other threads via
the cache.

The new cache transaction semantics is implemented via the
three new commands

   ns_cache_transaction_begin
   ns_cache_transaction_commit
   ns_cache_transaction_rollback

When no ns_cache_transaction* command is used, the
behavior is exactly as before. When cache transactions
are used (initiated by a ns_cache_transaction_begin
and ended via ns_cache_transaction_commit or
ns_cache_transaction_rollback, the ns_cache commands
provide in essence the following functionalities:

a) The ability to rollback of the values since the matching
   ns_cache_transaction_begin
b) Isolation of behavior: cached values from incomplete cache
   transactions are just visible from the current thread, but not
   from other threads.
c) Nesting: transactions can be nested
   (up to a compile time constant, currently 16)
d) Introspection: the statistics about cache commits and rollbacks
   are included in the cache statistics.

Implementation: The implementation is an extension of the pre-existing
update semantics and follows as close as possible the existing
model used in ns_cache_eval. The "value" of a cache entry is NULL
until a commit is performed, other threads competing for the same
cache entry have to wait for the "commit" operations.

The old C-API continues to work as before. The new transaction
aware interface is implemented over the following C functions

  Ns_CacheFindEntryT()
  Ns_CacheFirstEntryT()
  Ns_CacheGetValueT()
  Ns_CacheNextEntryT()
  Ns_CacheWaitCreateEntryT()

In order to avoid potential unwanted long-time locks on cache entries
when cache transactions are not properly closed (e.g. in error cases),
"ns_cleanup" is now extended to roll back all changes.

The following ns_cache commands are now cache transaction aware:

 ns_cache_get
 ns_cache_eval
 ns_cache_incr
 ns_cache_append
 ns_cache_lappend
 ns_cache_keys
 ns_cache_flush

All the best

-gn


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to