Reproduce the procedure:
上次他们有一个集群上的问题,就是从节点1的控制面板中,上传一个图片,然后关闭节点1, 从节点2中看不到这个图片。这个问题的流程如下:
Following are the steps for the clustering issues
- Go to Control Panel.
- Click on "Documents and Media" from Left Nav.
- Add folder
- Add Basic document . Browse Image
- Add the Web content port let
- And configure it to use the above add image.
我后来在深入研究这个过程之后,解决了这个问题:
解决方法1: 用数据库存储media资源,以Blob形式:
Solution:
(1) In each node ,add the following lines in ${liferay_home}/portal-ext.properties:
- #added by charles to use the DBStore instead of default FileSystemStore when configuring the document library
- dl.store.impl=com.liferay.portlet.documentlibrary.store.DBStore
- #added by charles to fix the dbStore problem ,use the new portal hibernate mapping file
- hibernate.configs=\
- META-INF/mail-hbm.xml,\
- META-INF/portal-hbm-new.xml,\
- META-INF/ext-hbm.xml
(2) In each node ,copy the portal-hbm-new.xml from the attachment 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:
- public void addFile(
- long companyId, long repositoryId, String fileName,
- boolean validateFileExtension, File file)
- throws PortalException, SystemException {
- validate(fileName, validateFileExtension, file);
- if (PropsValues.DL_STORE_ANTIVIRUS_ENABLED) {
- AntivirusScannerUtil.scan(file);
- }
- store.addFile(companyId, repositoryId, fileName, file);
- }
Actually ,the Liferay framework has supplied 5 kinds of implementations for Store :
The default one is FileSystemStore, and it was configured in portal.properties:
- # Set the name of a class that implements
- # com.liferay.portlet.documentlibrary.store.Store. The
- # document library server will use this to persist documents.
- #
- #dl.store.impl=com.liferay.portlet.documentlibrary.store.AdvancedFileSystemStore
- #dl.store.impl=com.liferay.portlet.documentlibrary.store.CMISStore
- #dl.store.impl=com.liferay.portlet.documentlibrary.store.DBStore
- dl.store.impl=com.liferay.portlet.documentlibrary.store.FileSystemStore
- #dl.store.impl=com.liferay.portlet.documentlibrary.store.JCRStore
- #dl.store.impl=com.liferay.portlet.documentlibrary.store.S3Store
If we use the FileSystemStore ,the default location that store the file(such as image) 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 (image 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.