Portalexception in Movefolders method would cause inconsistency issue between database and file system

Source: Internet
Author: User
Tags throw exception

When we try to move folders from one repository to another one, if the source file was deleted in file system, the move Pro Cess would is roll back due to transaction, while files before exception would is 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's what I do:

I Delete a file in the file system and try to move it to another folder. Then I debug this in Filesystemstore.getfileasstream (CompanyID, Repositoryid, FileName, Versionlabel)

 PublicInputStream Getfileasstream (LongCompanyID,LongRepositoryid, String fileName, string Versionlabel)throwsportalexception {if(Validator.isnull (Versionlabel)) {Versionlabel=Getheadversionlabel (CompanyID, Repositoryid, fileName); } File filenameversionfile=getfilenameversionfile (CompanyID, Repositoryid, FileName, Versionlabel); Try {      return NewFileInputStream (Filenameversionfile); }   Catch(FileNotFoundException fnfe) {Throw Newnosuchfileexception (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

protectedDocument dogetdocument (Object obj)throwsException {dlfileentry dlfileentry=(dlfileentry) obj; if(_log.isdebugenabled ()) {_log.debug ("Indexing document" +dlfileentry); }   BooleanIndexcontent =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 a idea on 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, we can avoid the inconsistency thing.

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

My Github:https://github.com/bejondshao

Portalexception in Movefolders method would cause inconsistency issue between database and file system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.