diff --git a/source/java/org/alfresco/repo/content/filestore/FileContentStore.java b/source/java/org/alfresco/repo/content/filestore/FileContentStore.java index 32472a2476..a436329f78 100644 --- a/source/java/org/alfresco/repo/content/filestore/FileContentStore.java +++ b/source/java/org/alfresco/repo/content/filestore/FileContentStore.java @@ -167,7 +167,7 @@ public class FileContentStore extends AbstractContentStore * * @see #setReadOnly(boolean) */ - public File createNewFile(String newContentUrl) throws IOException + private File createNewFile(String newContentUrl) throws IOException { if (readOnly) { @@ -180,7 +180,7 @@ public class FileContentStore extends AbstractContentStore File dir = file.getParentFile(); if (!dir.exists()) { - dir.mkdirs(); + makeDirectory(dir); } // create a new, empty file @@ -197,6 +197,46 @@ public class FileContentStore extends AbstractContentStore return file; } + /** + * Synchronized and retrying directory creation. Repeated attempts will be made to create the + * directory, subject to a limit on the number of retries. + * + * @param dir the directory to create + * @throws IOException if an IO error occurs + */ + private synchronized void makeDirectory(File dir) throws IOException + { + /* + * Once in this method, the only contention will be from other file stores or processes. + * This is OK as we have retrying to sort it out. + */ + if (dir.exists()) + { + // Beaten to it during synchronization + return; + } + // 20 attempts with 20 ms wait each time + for (int i = 0; i < 20; i++) + { + boolean created = dir.mkdirs(); + if (created) + { + // Successfully created + return; + } + // Wait + try { this.wait(20L); } catch (InterruptedException e) {} + // Did it get created in the meantime + if (dir.exists()) + { + // Beaten to it while asleep + return; + } + } + // It still didn't succeed + throw new ContentIOException("Failed to create directory for file storage: " + dir); + } + /** * Takes the file absolute path, strips off the root path of the store * and appends the store URL prefix. diff --git a/source/java/org/alfresco/repo/node/db/hibernate/HibernateNodeDaoServiceImpl.java b/source/java/org/alfresco/repo/node/db/hibernate/HibernateNodeDaoServiceImpl.java index d1b2a0f487..3397738835 100644 --- a/source/java/org/alfresco/repo/node/db/hibernate/HibernateNodeDaoServiceImpl.java +++ b/source/java/org/alfresco/repo/node/db/hibernate/HibernateNodeDaoServiceImpl.java @@ -1166,6 +1166,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements // Loop through, extracting content URLs List convertedValues = new ArrayList(1000); TypeConverter converter = DefaultTypeConverter.INSTANCE; + int unflushedCount = 0; while(results.next()) { Node node = (Node) results.get()[0]; @@ -1200,8 +1201,13 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements } } } - // evict all data from the session - getSession().clear(); + unflushedCount++; + if (unflushedCount >= 1000) + { + // evict all data from the session + getSession().clear(); + unflushedCount = 0; + } } return convertedValues; }