Folder creation conflict in clustered environment with policy

cancel
Showing results for 
Search instead for 
Did you mean: 
signjoy
Active Member II

Folder creation conflict in clustered environment with policy

Hello,

We have two nodes in a cluster.  Whenever a new file comes in a DROP folder a onUpdatePolicy runs and move the document to the appropriate folder. 

We have metadata called caseNumber. So if the caseNumber is 12345678 then the onUpdatePolicy will create a folder structure like 12->123->12345->12345678->abc.pdf. 

Issue:

We have to bulk import around 50 documents with the same caseNumber 12345678.

During the bulk import if two documents comes at the same time in the DROP folder, the policy will run on both the nodes and  it creates a race condition between two threads or nodes and one thread/node is throwing duplicate folder exception. 

I also tried to write a simple JavaScript based rule that will move the documents as when they created into DROP folder. It also throws the same exception or some documents are not getting moved.

For the time being I have written a Scheduler that moves the documents at certain interval. But I would like to know if there is a better way to do this with policy.

Alfresco 5.1.2

Thank you

2 Replies
krutik_jayswal
Senior Member II

Re: Folder creation conflict in clustered environment with policy

Please add the code for Java Policy and the Javascript as well.

Roughly it can be because of any of below reason.

1. In code you are not checking the folder is already exist or not.

2. Files which you are trying to upload have the same name.(this is not allowed in alfresco , to have same file name under same folder)

signjoy
Active Member II

Re: Folder creation conflict in clustered environment with policy

Hi,

I do check for the folder already exists or not and also if the file already present or not. Below is the javascript code in that I am calling childByNamePath. If too many files come at the same time with same case number then the createFolder method is throwing duplicate folder exception.

var step1 = csNumber.substring(0, 2);
var stepFolder1 = root.childByNamePath(step1);
if (stepFolder1 == null) {
    // This sometimes throws an exception as some other thread just created a folder step1
    stepFolder1 = root.createFolder(step1, folderType);
}
var step2 = csNumber.substring(2, 5);
var stepFolder2 = stepFolder1.childByNamePath(step2);
if (stepFolder2 == null) {
    stepFolder2 = stepFolder1.createFolder(step2, folderType);
}
var step3 = csNumber.substring(5, 8);
var stepFolder3 = stepFolder2.childByNamePath(step3);
if (stepFolder3 == null) {
     stepFolder3 = stepFolder2.createFolder(step3, folderType);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Below is the code form the policy

// This method will return the destincation folder. 
// If not found then it will create it in 12->345->678 manner
// This method sometimes throws duplicate folder exception if two threads calls it
parentFolder = getCaseParentFolder(cId);


nodeService.moveNode(csNode, parentFolder, ContentModel.ASSOC_CONTAINS,
QName.createQName(CustomConstants.SBS_MODEL_1_0_URI, cId));‍‍‍‍‍‍‍‍

We are not getting the duplicate file exception. Also sometimes the policy keep throwing exception called "Detected stale node entry exception"

Thank you for your time