Reproduce the procedure:

上次他们有一个集群上的问题,就是从节点1的控制面板中,上传一个图片,然后关闭节点1, 从节点2中看不到这个图片。这个问题的流程如下:

 

Following are the steps for the clustering issues

  1. Go to Control Panel.

  2. Click on "Documents and Media" from Left Nav.

  3. Add folder

  4. Add Basic document . Browse Image

  5. Add the Web content port let

  6. And configure it to use the above add p_w_picpath.

 

我后来在深入研究这个过程之后,解决了这个问题:

 

 解决方法1: 用数据库存储media资源,以Blob形式:

Solution:

(1)   In each node ,add the following lines in ${liferay_home}/portal-ext.properties:


 
  
  1.   
  2.  
  3. #added by charles to use the DBStore instead of default FileSystemStore when configuring the document library 
  4.  
  5. dl.store.impl=com.liferay.portlet.documentlibrary.store.DBStore 
  6.  
  7.   
  8.  
  9.   
  10.  
  11. #added by charles to fix the dbStore problem ,use the new portal hibernate mapping file 
  12.  
  13.   hibernate.configs=\ 
  14.  
  15.         META-INF/mail-hbm.xml,\ 
  16.  
  17.         META-INF/portal-hbm-new.xml,\ 
  18.  
  19.         META-INF/ext-hbm.xml 
  20.  
  21.   

(2)   In each node ,copy the portal-hbm-new.xml from the p_w_upload to /ROOT/WEB-INF/classes/META-INF/ folder.

 

 

Reason for this solution:

 

                When we add “Basic Document” to  created folder in control panel ,the liferay system will do the following tasks:

                You can read my article http://supercharles888.blog.51cto.com/609344/921761 for very detailed analysis process.

 

a.       Add an entry in “DLFILEENTRY” table to stand for the new added document.

b.      Add an entry in  “DLFILEENTRYVERSION” table to record the version information of the new added document ,it will related to “DLFILEENTRY” table by foreign key “fileEntryId”

c.       Update the new posted timestamp in “DLFOLDER” table ,which means the latest timestamp that this folder has been posted by some file.

d.      Add an entry in “ASSETENTRY” table ,because  file is also one kind of asset. This table will be related to “DLFILEENTRY” table by foreign key “classpk”

e.       Upload the file to the store based on the liferay server configuration:

 

In DLStoreImpl class addFile method:

 


 
  
  1. public void addFile( 
  2.  
  3.                   long companyId, long repositoryId, String fileName, 
  4.  
  5.                   boolean validateFileExtension, File file) 
  6.  
  7.             throws PortalException, SystemException { 
  8.  
  9.   
  10.  
  11.             validate(fileName, validateFileExtension, file); 
  12.  
  13.   
  14.  
  15.             if (PropsValues.DL_STORE_ANTIVIRUS_ENABLED) { 
  16.  
  17.                   AntivirusScannerUtil.scan(file); 
  18.  
  19.             } 
  20.  
  21.   
  22.  
  23.             store.addFile(companyId, repositoryId, fileName, file); 
  24.  
  25.    } 
  26.  
  27.   

Actually ,the Liferay framework has supplied 5 kinds of implementations for Store :

 


 

The default one is FileSystemStore, and it was configured in portal.properties:

 

 
  
  1. Set the name of a class that implements 
  2.  
  3.           # com.liferay.portlet.documentlibrary.store.Store. The 
  4.  
  5.            # document library server will use this to persist documents. 
  6.  
  7.             # 
  8.  
  9.            #dl.store.impl=com.liferay.portlet.documentlibrary.store.AdvancedFileSystemStore 
  10.  
  11.            #dl.store.impl=com.liferay.portlet.documentlibrary.store.CMISStore 
  12.  
  13.            #dl.store.impl=com.liferay.portlet.documentlibrary.store.DBStore 
  14.  
  15.            dl.store.impl=com.liferay.portlet.documentlibrary.store.FileSystemStore 
  16.  
  17.            #dl.store.impl=com.liferay.portlet.documentlibrary.store.JCRStore 
  18.  
  19.   #dl.store.impl=com.liferay.portlet.documentlibrary.store.S3Store 


If we use the FileSystemStore ,the default location that store the file(such as p_w_picpath) is in each nodes $liferay_home/data/document_library, once a node is shutdown ,although the session is replicated to other node ,but the resource can’t be copied to other node (Which means ,the location of resource is not a Single point), so when the backup node need resource ,but the resource is in a shutdowned server ,how can this backup node get it?

That’s the reason.

 

 

 

So we changed it to DBStore ,since all nodes share the same database(Database is a Single point in cluster environment) ,so if we use database to store the resource ,all nodes can access it .so it work as our expected. In this way ,the resource (p_w_picpath for example) are stored in the form of “Blob”  ,and stored in “DLCONTENT” table:

 


 

 

Reason why we need to re-configure the hibernate-configs?

 

If you read my solution carefully ,you can see that I don’t use the default hibernate.configs ,I change the “META-INF/portal-hbm.xml” to “META-INF/portal-hbm-new.xml” and do some modifications to this mapping file .Why?

Because when you persist the resource to “DLCONTENT” table , you may meet with the following exception:

 


 

The reason is in portal-hbm.xml Line 1416, the default type for dataBlob is “org.hibernate.type.BlobType” ,but when we want to persist into database ,what we want is  “java.sql.Blob

 


 

So I modify this type of dataBlob in portal-hbm-new.xml and let Liferay framework to read this new file (portal-hbm-new.xml) instead of the default( portal-hbm.xml) ,then problem solved.

 

 解决方法2:用共享的文件服务器存储media资源

Suppose we put the shared folder in 192.168.0.138, this physical ip address is neither the same as node1 nor node2.

 

1.       Keep everything setting default ,then in each node ,add the following line in ${liferay_home}/portal-ext.properties (You must use  “ \\”  instead of “\”  as path separator):

#added by charles to use the file store to fixed the cluster

dl.store.file.system.root.dir=\\\\192.168.0.238\\WalmartShare\\Platform\\ClusterSharedFolder\\data\\document_library

 

2.       Then restart the clustering environment  and do the procedure as you supplied, you will see this issue is fixed.

You can check the location of shared file system,and will find the media files has been uploaded to this location successfully.