星空网 > 软件开发 > Java

PortalException in moveFolders method will cause inconsistency issue between database and file system

 

When we try to move folders from one repository to another one, if the source file is deleted in file system, the move process would be roll back due to transaction, while files before exception would be moved to new repository. This causes inconsistency.

 

The detail https://issues.liferay.com/browse/LPS-61337

It depends on https://issues.liferay.com/browse/LPS-60884

 

Here is what I do:

I delete a file in file system and try to move it to another folder. Then I debug that in FileSystemStore.getFileAsStream(companyId, repositoryId, fileName, versionLabel)

public InputStream getFileAsStream(   long companyId, long repositoryId, String fileName,   String versionLabel)  throws PortalException {  if (Validator.isNull(versionLabel)) {   versionLabel = getHeadVersionLabel(     companyId, repositoryId, fileName);  }  File fileNameVersionFile = getFileNameVersionFile(   companyId, repositoryId, fileName, versionLabel);  try {   return new FileInputStream(fileNameVersionFile);  }  catch (FileNotFoundException fnfe) {   throw new NoSuchFileException(fileNameVersionFile.getPath(), fnfe);  }}


It throws FileNotFoundException. But the moving file action processed successfully.

I continue debug about the exception, portal goes to DLFileEntryIndexer.doGetDocument(obj) // It's about update index

protected Document doGetDocument(Object obj) throws Exception {  DLFileEntry dlFileEntry = (DLFileEntry)obj;  if (_log.isDebugEnabled()) {   _log.debug("Indexing document " + dlFileEntry);  }  boolean indexContent = true;  InputStream is = null;  try {   String[] ignoreExtensions = PrefsPropsUtil.getStringArray(     PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA);   if (ArrayUtil.contains(      ignoreExtensions,      StringPool.PERIOD + dlFileEntry.getExtension())) {     indexContent = false;   }   if (indexContent) {     is = dlFileEntry.getFileVersion().getContentStream(false);   }  }  catch (Exception e) {  }   DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();


You can see that it catch the exception, but does nothing. So the code continue doing the rest process.

I come up with an idea about moveFolder, we can doing the same thing when the file is lost. But you know, we just hide the exception to make the process continue. Because in all, liferay doesn't support transaction for file system.

 

Here is my solution https://github.com/daledotshan/liferay-portal/pull/367

In my first commit, I catch the exception and print it out. I don't throw exception in order to continue the moving process. In this way, we can avoid the inconsistency thing.

In my second commit, I don't delete the source folder if the source folder is not empty. Because if the files are all good, they will be moved to new folder. So the source folder would be empty and it can be deleted. So the left files are not found in file system.

 

my github: https://github.com/bejondshao




原标题:PortalException in moveFolders method will cause inconsistency issue between database and file system

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

给新西兰寄国际快递:https://www.goluckyvip.com/tag/100022.html
程洋国际快递:https://www.goluckyvip.com/tag/100023.html
国际快递哪几家:https://www.goluckyvip.com/tag/100024.html
大阪国际快递:https://www.goluckyvip.com/tag/100025.html
国际快递寄烟:https://www.goluckyvip.com/tag/100026.html
国际快递要多少:https://www.goluckyvip.com/tag/100027.html
三百元以内千兆路由器怎么选择?:https://www.vstour.cn/a/363184.html
千岛湖绿城度假酒店的简介:https://www.vstour.cn/a/363185.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流