Minor fixes:

- ContentStore directory creation does a few retries if it fails
 - A little less Session clearing during content store cleaning


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5941 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-06-13 19:33:30 +00:00
parent 2794a59085
commit 7735ae0acd
2 changed files with 50 additions and 4 deletions

View File

@@ -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.

View File

@@ -1166,6 +1166,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
// Loop through, extracting content URLs
List<Serializable> convertedValues = new ArrayList<Serializable>(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
}
}
}
unflushedCount++;
if (unflushedCount >= 1000)
{
// evict all data from the session
getSession().clear();
unflushedCount = 0;
}
}
return convertedValues;
}