Coding best practice : Lucene search query : resultSet.close() : part2

November 27, 2009

To continue on the same topic (see Part1 of this post):

I have open a JIRA issue, because I think we have identified a code defect in Alfresco code itself…Click here for more details.

Basically the “symptom” is that we can see that our lucene index seems to grow continuously in production.

When running the command:
find . -type d | wc -l
in:
<alfresco>/alf_data/lucene-indexes/workspace/SpacesStore/

It returns more than 21000 directories !

As per our discussion with Alfresco service guy, we should not have more than 100 directories in “<alfresco>/alf_data/lucene-indexes/workspace/SpacesStore/”.

This is a know issue in v2.1.1 when Lucene ResultSet are not closed properly.

We have checked the code of alfresco-enterprise-sdk-2.1.1 and it seems that ResultSet is not closed properly in:
java.org.alfresco.web/bean.wizard.InviteUsersWizard.java

Also, As per our discussion with Alfresco service:
– in release 2.1.6 and higher, the issue is fixed (i.e not closing resultset does not leads to a growing lucene index).

– if we want to “merge” the current lucene indexes to reduce the number of files, we must upgrade to release 2.2.3 (E ?). When the server will start, it will be able to automatically merge the lucene indexes.

Please note that this has to be confirmed by support, so check JIRA issue ALFCOM-3683 status for latest update on this.

Advertisements

Coding best practice : Lucene search query : resultSet.close()

November 19, 2009

Just want to share a very important coding best practice if you are using Lucence search query in Alfresco : do not forget to close the ResultSet object (org.alfresco.service.cmr.search.ResultSet) at the end of your treatments.

This is very important to avoid disk space issue (and also probably memory leak issue). Indeed, if the ResultSet object is not closed properly, then it seems that Lucene will have to “keep it on disk” as a “piece of Lucene index” (serialization here ?) and this block will not be removed by the “index cleaner process”. So space of Lucene index will continue to grow indefinitely….

There are a lots of  ” ” here, but I think you understand that this could be a major issue.

Code sample:

try {

 ResultSet resultSet = null;
 
 resultSet = searchService.query(
 Repository.getStoreRef(), SearchService.LANGUAGE_LUCENE, query.toString());           
 List<NodeRef> nodes = resultSet.getNodeRefs();
 for (int index=0; index<nodes.size(); index++) {
 
 //Do whatever you want here
 
 }

catch (Throwable err) {
 (…)
}
finally {
         if (resultSet != null)
         {
          resultSet.close();
         }
}