ModeShape/modeshape — pull request #633 by rhauch (2012-12-22 22:07:09+00:00)
Title: MODE-1733 Corrected clustering behavior when using eviction

The original problem is that the delta is being merged to a null entry reference when the entry has been evicted from the cache. The correct behavior would be to look up the persisted entry and merge the detal with that. Infinispan is not behaving correctly.

This problem appears to be very similar to ISPN-2095, though we're not using AtomicHashMap but have our own DeltaAware implementation (called SchematicEntry).

The fix for ISPN-2095 involved changing AtomicHashMapProxy to use a specific "DELTA_WRITE" cache flag that was added in Infinispan 5.1.6.FINAL. That means we don't have access to the fix in 5.1.2.FINAL, so we need to provide an alternative solution for pre-5.1.6.FINAL releases.

The CacheContext now attempts to set that flag only when we're using Infinispan 5.1.6 or later (e.g., if we can find the "DELTA_WRITE" flag), but the changes still don't seem to correct the behavior with
Infinispan 5.1.2.FINAL, 5.1.6.FINAL or 5.1.8.Final. Even if it worked on 5.1.6 or later, we would still have the issue when using 5.1.2.FINAL (which is all AS7.1.1 installations).

We need a solution that works with Infinispan 5.1.2 or later. One option was to make the SchematicEntryLiteral instances no longer implement DeltaAware. However, that means that we'd be changing the class for the values we're storing in Infinispan. It also means that we could not use DeltaAware in some environments (for example, when we're using newer versions of Infinispan).

A better approach taken with this commit is to use different Delta implementations depending upon the configuration. With this commit there are two Delta implementations: one that works like before by recording the Operations used to manipulate the documents, and a new one that simply contains the whole document.

The benefit of this approach is that we can then choose which Delta implementation we use based upon the Infinispan configuration and version:
* In local (non-clustered) caches, we actually don't need to compute a Delta. In this case we can use the whole document Delta and a different DocumentEditor that doesn't actually create any operations.
* In clustered caches that do not use eviction, we can use the diff-based Delta with an editor that does calculate the change operations. These Delta instances are correctly merged.
* In clustered caches that do use eviction, we need to use the whole-document Delta. And since this delta doesn't record operations, we could use a DocumentEditor that doesn't actually create operations.

All tests (including several new clustering tests) pass with these changes. Additionally, the clustering test attached by the reporter to MODE-1733 also passes with these changes, when using either Infinispan 5.1.2.FINAL or 5.1.8.Final.