portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r727772 - in /portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src: main/java/org/apache/jetspeed/page/impl/ test/java/org/apache/jetspeed/page/cache/
Date Thu, 18 Dec 2008 17:25:43 GMT
Author: rwatler
Date: Thu Dec 18 09:25:43 2008
New Revision: 727772

URL: http://svn.apache.org/viewvc?rev=727772&view=rev
Log:
DB Page Manager Distributed Cache
- ensure notification of updates and removes is sent if underlying object has been evicted
from or is new to the cache
- extend distributed cache test coverage for above cases


Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/TestDatabasePageManagerCache.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java?rev=727772&r1=727771&r2=727772&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
Thu Dec 18 09:25:43 2008
@@ -959,8 +959,7 @@
 
                 // update page and mark cache transaction
                 page.setParent(parent);
-                getPersistenceBrokerTemplate().store(page);
-                DatabasePageManagerCache.addTransaction(new TransactionedOperation(page.getPath(),
TransactionedOperation.ADD_OPERATION));
+                storeEntity( page, pagePath, true);
 
                 // reset parent folder pages cache
                 if (parent != null)
@@ -977,8 +976,7 @@
                 page.checkAccess(JetspeedActions.EDIT);
 
                 // update page and mark cache transaction
-                getPersistenceBrokerTemplate().store(page);
-                DatabasePageManagerCache.addTransaction(new TransactionedOperation(page.getPath(),
TransactionedOperation.UPDATE_OPERATION));
+                storeEntity( page, page.getPath(), false);
                 
                 // reset parent folder pages cache in case
                 // parent is holding an out of date copy of
@@ -1102,8 +1100,7 @@
 
                 // update folder and mark cache transaction
                 folder.setParent(parent);
-                getPersistenceBrokerTemplate().store(folder);
-                DatabasePageManagerCache.addTransaction(new TransactionedOperation(folder.getPath(),
TransactionedOperation.ADD_OPERATION));
+                storeEntity(folder, folderPath, true);
 
                 // reset parent folder folders cache
                 if (parent != null)
@@ -1122,20 +1119,21 @@
                 // check for edit access on folder and parent folder
                 // if not being initially created; access is not
                 // checked on create
-                if (!newFolder || !folder.getPath().equals(Folder.PATH_SEPARATOR))
+                String folderPath = folder.getPath();
+                if (!newFolder || !folderPath.equals(Folder.PATH_SEPARATOR))
                 {
                     folder.checkAccess(JetspeedActions.EDIT);
                 }
 
                 // create root folder or update folder and mark cache transaction
-                getPersistenceBrokerTemplate().store(folder);
+                storeEntity(folder, folderPath);
                 if (newFolder && !folder.getId().equals("0"))
                 {
-                    DatabasePageManagerCache.addTransaction(new TransactionedOperation(folder.getPath(),
TransactionedOperation.ADD_OPERATION));
+                    DatabasePageManagerCache.addTransaction(new TransactionedOperation(folderPath,
TransactionedOperation.ADD_OPERATION));
                 }
                 else
                 {
-                    DatabasePageManagerCache.addTransaction(new TransactionedOperation(folder.getPath(),
TransactionedOperation.UPDATE_OPERATION));
+                    DatabasePageManagerCache.addTransaction(new TransactionedOperation(folderPath,
TransactionedOperation.UPDATE_OPERATION));
                 }
 
                 // reset parent folder folders cache in case
@@ -1411,8 +1409,7 @@
 
                 // update link and mark cache transaction
                 link.setParent(parent);
-                getPersistenceBrokerTemplate().store(link);
-                DatabasePageManagerCache.addTransaction(new TransactionedOperation(link.getPath(),
TransactionedOperation.ADD_OPERATION));
+                storeEntity(link, linkPath, true);
 
                 // reset parent folder links cache
                 if (parent != null)
@@ -1429,8 +1426,7 @@
                 link.checkAccess(JetspeedActions.EDIT);
 
                 // update link and mark cache transaction
-                getPersistenceBrokerTemplate().store(link);
-                DatabasePageManagerCache.addTransaction(new TransactionedOperation(link.getPath(),
TransactionedOperation.UPDATE_OPERATION));
+                storeEntity(link, link.getPath(), false);
 
                 // reset parent folder links cache in case
                 // parent is holding an out of date copy of
@@ -1549,8 +1545,7 @@
                     
                     // update document and mark cache transaction
                     pageSecurity.setParent(parent);
-                    getPersistenceBrokerTemplate().store(pageSecurity);
-                    DatabasePageManagerCache.addTransaction(new TransactionedOperation(pageSecurity.getPath(),
TransactionedOperation.ADD_OPERATION));
+                    storeEntity(pageSecurity, pageSecurityPath, true);
 
                     // reset parent folder page security cache
                     if (parent != null)
@@ -1572,8 +1567,7 @@
                 pageSecurity.checkAccess(JetspeedActions.EDIT);
 
                 // update document and mark cache transaction
-                getPersistenceBrokerTemplate().store(pageSecurity);
-                DatabasePageManagerCache.addTransaction(new TransactionedOperation(pageSecurity.getPath(),
TransactionedOperation.UPDATE_OPERATION));
+                storeEntity(pageSecurity, pageSecurity.getPath(), false);
 
                 // reset parent folder page security cache in case
                 // parent is holding an out of date copy of this
@@ -1653,6 +1647,43 @@
             throw new FailedToDeleteDocumentException("Document " + pageSecurity.getPath()
+ " not removed.", e);
         }
     }
+    
+    /**
+     * Add or update persistence object by storing to persistence broker.
+     *  
+     * @param node node to store
+     * @param path node path
+     */
+    private void storeEntity(Object node, String path)
+    {
+        // store object for add/update and interoperate with cache
+        // to signal update operations
+        DatabasePageManagerCache.addUpdatePath(path);
+        try
+        {
+            getPersistenceBrokerTemplate().store(node);
+        }
+        finally
+        {
+            DatabasePageManagerCache.removeUpdatePath(path);
+        }
+    }
+
+    /**
+     * Add or update persistence object by storing to persistence broker
+     * with thread cache transaction management.
+     *  
+     * @param node node to store
+     * @param path node path
+     * @param add whether transaction operation is add or update
+     */
+    private void storeEntity(Object node, String path, boolean add)
+    {
+        // store object for add/update and interoperate with cache
+        // to signal update operations and record thread transactions
+        storeEntity(node, path);
+        DatabasePageManagerCache.addTransaction(new TransactionedOperation(path, (add ? TransactionedOperation.ADD_OPERATION
: TransactionedOperation.UPDATE_OPERATION)));
+    }
 
     /* (non-Javadoc)
      * @see org.apache.jetspeed.page.PageManager#copyPage(org.apache.jetspeed.om.page.Page,java.lang.String)

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java?rev=727772&r1=727771&r2=727772&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
Thu Dec 18 09:25:43 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.jetspeed.page.impl;
 
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -47,6 +48,7 @@
     private static boolean constraintsEnabled;
     private static boolean permissionsEnabled;
     private static PageManager pageManager;
+    private static List updatePathsList = new ArrayList();
     private static ThreadLocal transactionedOperations = new ThreadLocal();
 
     // Implementation
@@ -264,6 +266,19 @@
     }
 
     /**
+     * Add path to list of updating paths; this list is used to
+     * distinguish cache add operations that are probably the
+     * result of writes vs. those that are associated with reads.
+     *
+     * @param path object path
+     */
+    public synchronized static void addUpdatePath(final String path)
+    {
+        // add path for later examination, (duplicates allowed)
+        updatePathsList.add(path);
+    }
+
+    /**
      * Add object to cache and cache instances by unique path;
      * infuse nodes loaded by OJB with page manager configuration.
      *
@@ -277,17 +292,39 @@
             final NodeImpl node = (NodeImpl)obj;
             final String nodePath = node.getPath();
 
-            // add node to caches
+            // add node to caches; note that removes force notification
+            // of update to distributed caches
             oidCache.remove(oid);
             final CacheElement element = oidCache.createElement(oid, node);
             oidCache.put(element);
-            pathCache.remove(nodePath);
+            final boolean removed = pathCache.remove(nodePath);
             final CacheElement pathElement = pathCache.createElement(nodePath, new DatabasePageManagerCacheObject(oid,
nodePath));
             pathCache.put(pathElement);
+            // if a remove was not successful from the path cache, update
+            // notification to distributed peers was not performed;
+            // for updates of objects evicted from the cache or newly
+            // created ones, this is problematic: remove and put into
+            // path cache a second time to force
+            if (!removed && updatePathsList.contains(nodePath))
+            {
+                pathCache.remove(nodePath);
+                pathCache.put(pathElement);
+            }
         }
     }
 
     /**
+     * Remove path from list of updating paths.
+     *
+     * @param path object path
+     */
+    public synchronized static void removeUpdatePath(final String path)
+    {
+        // remove single path from list
+        updatePathsList.remove(path);
+    }
+
+    /**
      * Clear object and path caches.
      */
     public synchronized static void cacheClear()
@@ -344,9 +381,21 @@
             final NodeImpl node = (NodeImpl)cacheLookup(oid);
             if (node != null)
             {
-                // remove from caches
+                final String nodePath = node.getPath();
+                // remove from caches; note that removes are
+                // propagated to distributed caches
                 oidCache.remove(oid);
-                pathCache.remove(node.getPath());
+                final boolean removed = pathCache.remove(nodePath);
+                // if a remove was not successful from the path cache,
+                // remove notification to distributed peers was not
+                // performed; this is problematic: put into path cache
+                // and remove a second time to force
+                if (!removed)
+                {
+                    final CacheElement pathElement = pathCache.createElement(nodePath, new
DatabasePageManagerCacheObject(oid, nodePath));
+                    pathCache.put(pathElement);
+                    pathCache.remove(nodePath);
+                }
             }
         }
     }
@@ -361,14 +410,25 @@
         // remove from cache by path
         if (path != null)
         {
-            final CacheElement pathElement = pathCache.get(path);
+            CacheElement pathElement = pathCache.get(path);
             if (pathElement != null)
             {
                 final DatabasePageManagerCacheObject cacheObject = (DatabasePageManagerCacheObject)pathElement.getContent();
-                // remove from caches
+                // remove from caches; note that removes are
+                // propagated to distributed caches
                 oidCache.remove(cacheObject.getId());
                 pathCache.remove(path);
             }
+            else
+            {
+                // if an object is not found in the path cache, remove
+                // notification to distributed peers will not be performed;
+                // this is problematic: put into path cache and remove to
+                // force
+                pathElement = pathCache.createElement(path, new DatabasePageManagerCacheObject(path));
+                pathCache.put(pathElement);
+                pathCache.remove(path);                
+            }
         }
     }
     

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java?rev=727772&r1=727771&r2=727772&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManagerCacheObject.java
Thu Dec 18 09:25:43 2008
@@ -40,12 +40,22 @@
     /**
      * Construct new cache object with id and path
      * 
+     * @param path
+     */
+    public DatabasePageManagerCacheObject(final String path)
+    {
+        this.path = path;
+    }
+
+    /**
+     * Construct new cache object with id and path
+     * 
      * @param id
      * @param path
      */
     public DatabasePageManagerCacheObject(final Identity id, final String path)
     {
-        this.path = path;
+        this(path);
         this.id = id;
     }
 

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/TestDatabasePageManagerCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/TestDatabasePageManagerCache.java?rev=727772&r1=727771&r2=727772&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/TestDatabasePageManagerCache.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/cache/TestDatabasePageManagerCache.java
Thu Dec 18 09:25:43 2008
@@ -264,7 +264,7 @@
             boolean deepPage1Removed = false;
             boolean deep1FolderRemoved = false;
             boolean rootFolderFoldersCountOne = false;
-            final long coherencyCheckStarted = System.currentTimeMillis();
+            long coherencyCheckStarted = System.currentTimeMillis();
             do
             {
                 // check cache coherency
@@ -325,6 +325,70 @@
             assertTrue(deep1FolderRemoved);
             assertTrue(rootFolderFoldersCountOne);
 
+            // add new objects in first page manager
+            result = server0.execute("page = pageManager.newPage(\"/new-page.psml\");");
+            assertTrue(result.indexOf("Exception") == -1);
+            result = server0.execute("page.setTitle(\"New Page\");");
+            assertTrue(result.indexOf("Exception") == -1);
+            result = server0.execute("pageManager.updatePage(page);");
+            assertTrue(result.indexOf("Exception") == -1);
+            result = server0.execute("folder = pageManager.newFolder(\"/deep-2\");");
+            assertTrue(result.indexOf("Exception") == -1);
+            result = server0.execute("folder.setTitle(\"Deep 2 Folder\");");
+            assertTrue(result.indexOf("Exception") == -1);
+            result = server0.execute("pageManager.updateFolder(folder);");
+            assertTrue(result.indexOf("Exception") == -1);
+            
+            // test objects in both page managers for cache coherency
+            result = server0.execute("pageManager.getFolder(\"/\").getPages().size();");
+            assertTrue(result.endsWith("3"));
+            result = server0.execute("pageManager.getFolder(\"/\").getFolders().size();");
+            assertTrue(result.endsWith("2"));
+            result = server0.execute("pageManager.getPage(\"/new-page.psml\").getTitle();");
+            assertTrue(result.endsWith("New Page"));
+            result = server0.execute("pageManager.getFolder(\"/deep-2\").getTitle();");
+            assertTrue(result.endsWith("Deep 2 Folder"));
+            boolean rootFolderPagesCountThree = false;
+            boolean rootFolderFoldersCountTwo = false;
+            boolean newPageCreated = false;
+            boolean deep2FolderCreated = false;
+            coherencyCheckStarted = System.currentTimeMillis();
+            do
+            {
+                // check cache coherency
+                if (!rootFolderPagesCountThree)
+                {
+                    result = server1.execute("pageManager.getFolder(\"/\").getPages().size();");
+                    rootFolderPagesCountThree = result.endsWith("3");
+                }
+                if (!rootFolderFoldersCountTwo)
+                {
+                    result = server1.execute("pageManager.getFolder(\"/\").getFolders().size();");
+                    rootFolderFoldersCountTwo = result.endsWith("2");
+                }
+                if (!newPageCreated)
+                {
+                    result = server1.execute("pageManager.getPage(\"/new-page.psml\").getTitle();");
+                    newPageCreated = result.endsWith("New Page");
+                }
+                if (!deep2FolderCreated)
+                {
+                    result = server1.execute("pageManager.getFolder(\"/deep-2\").getTitle();");
+                    deep2FolderCreated = result.endsWith("Deep 2 Folder");
+                }
+
+                // wait for cache coherency
+                if (!rootFolderPagesCountThree || !rootFolderFoldersCountTwo || !newPageCreated
|| !deep2FolderCreated)
+                {
+                    Thread.sleep(250);
+                }
+            }
+            while ((!rootFolderPagesCountThree || !rootFolderFoldersCountTwo || !newPageCreated
|| !deep2FolderCreated) && (System.currentTimeMillis()-coherencyCheckStarted <
5000));
+            assertTrue(rootFolderPagesCountThree);
+            assertTrue(rootFolderFoldersCountTwo);
+            assertTrue(newPageCreated);
+            assertTrue(deep2FolderCreated);
+
             // reset database page managers
             result = server0.execute("pageManager.reset();");
             assertTrue(!result.contains("Exception"));



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message