CMIS creating duplicates when i make a folder creation call successively.

I have a logic in my client java code, which creates a document given the path, where it should reside. My logic checks for non-existing folders in a path. This check is in place to avoid FileNotFound exception and create the hierarchy first before creating the actual leaf document. As per our requirement, we don't want two documents to have the same name & path. What happens is, the folder creation logic when invoked in succession for missing folders, ends up creating two folders in the nuxeo. Both the folders have the same name & path extension. I know this is happening due to race condition. But i want to handle this issue in the nuxeo side by adding an eventHandler or something else.


To circumvent this issue, i added a eventHandler for 'AboutToCreate' and checked if the document with same name exists in that location. Provided which, i will throw an error back after marking the transaction as rollback.

This solution that i tried does not work for two successive or consecutive requests, which results in a racing conditions and ends up creating duplicates.

I m able to replicate this issue by calling the nuxeo rest api via nodeJS and try to create two folders with same name in the same location. Please find the nodeJS code below.

var nxfd = [{  "entity-type": "document",  "type": "Folder",  "name": "fol2",  "properties": {    "dc:title": "fol2"  }},{  "entity-type": "document",  "type": "Folder",  "name": "fol2",  "properties": {    "dc:title": "fol2"  }}];

nxfd.forEach(function (form) { 
        var options = {    uri: 'http://localhost:8080/nuxeo/api/v1/path/DevPortal/workspaces/Work/',    headers: {      "Content-Type": "application/json",      "Authorization": "Basic *****************"    },    body: JSON.stringify(form)  }; 

     , function optionalCallback(err, httpResponse, body) {   if (err) {      console.log(err);      // res.send(err);    } else {      console.log(body);      if (!res._sent100)        res.sendStatus(201);    }  });

More related to this question below,

0 votes

1 answers



Got a fix working yesterday after posting this.

Created a eventHandler for 'AboutToCreate' event, checked for the documentType, (so that i do this only for types i want it to kick in for), Made the handleEvent method of the eventHandler as 'SYNCHRONIZED'. This makes the second wait for the first thread to complete.

Added a caffiene cache to record the state of eventHandler just incase, if it is required for the other threads.

0 votes

Be aware that this solution will likely not work in a clustered environment and the synchronization may negatively impact the scalability of the platform.