mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged BRANCHES/DEV/THOR1 to HEAD:
32602: THOR-659: Caching Content Store blocked readers git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32631 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -20,7 +20,6 @@ package org.alfresco.repo.content.caching.cleanup;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
||||||
|
|
||||||
import org.alfresco.repo.content.caching.CacheFileProps;
|
import org.alfresco.repo.content.caching.CacheFileProps;
|
||||||
import org.alfresco.repo.content.caching.ContentCacheImpl;
|
import org.alfresco.repo.content.caching.ContentCacheImpl;
|
||||||
@@ -46,7 +45,6 @@ public class CachedContentCleaner extends Thread implements FileHandler, Applica
|
|||||||
private ContentCacheImpl cache; // impl specific functionality required
|
private ContentCacheImpl cache; // impl specific functionality required
|
||||||
private long minFileAgeMillis = 0;
|
private long minFileAgeMillis = 0;
|
||||||
private Integer maxDeleteWatchCount = 1;
|
private Integer maxDeleteWatchCount = 1;
|
||||||
private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
|
||||||
private boolean running;
|
private boolean running;
|
||||||
private UsageTracker usageTracker;
|
private UsageTracker usageTracker;
|
||||||
private long newDiskUsage;
|
private long newDiskUsage;
|
||||||
@@ -58,7 +56,6 @@ public class CachedContentCleaner extends Thread implements FileHandler, Applica
|
|||||||
private Date timeFinished;
|
private Date timeFinished;
|
||||||
private ApplicationEventPublisher eventPublisher;
|
private ApplicationEventPublisher eventPublisher;
|
||||||
private long targetReductionBytes;
|
private long targetReductionBytes;
|
||||||
private boolean cleanRequested;
|
|
||||||
private String reasonMessage;
|
private String reasonMessage;
|
||||||
|
|
||||||
|
|
||||||
@@ -99,9 +96,9 @@ public class CachedContentCleaner extends Thread implements FileHandler, Applica
|
|||||||
execute(reason);
|
execute(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void doClean()
|
private void doClean()
|
||||||
{
|
{
|
||||||
while (running || (!cleanRequested))
|
synchronized(this)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -112,7 +109,6 @@ public class CachedContentCleaner extends Thread implements FileHandler, Applica
|
|||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
running = true;
|
running = true;
|
||||||
if (log.isInfoEnabled())
|
if (log.isInfoEnabled())
|
||||||
{
|
{
|
||||||
@@ -138,18 +134,19 @@ public class CachedContentCleaner extends Thread implements FileHandler, Applica
|
|||||||
", target: " + targetReductionBytes + " bytes");
|
", target: " + targetReductionBytes + " bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanRequested = false;
|
|
||||||
this.targetReductionBytes = 0;
|
this.targetReductionBytes = 0;
|
||||||
running = false;
|
running = false;
|
||||||
|
|
||||||
notifyAll();
|
synchronized(this)
|
||||||
|
{
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized void execute(String reasonMessage)
|
public synchronized void execute(String reasonMessage)
|
||||||
{
|
{
|
||||||
this.reasonMessage = reasonMessage;
|
this.reasonMessage = reasonMessage;
|
||||||
cleanRequested = true;
|
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,15 +383,7 @@ public class CachedContentCleaner extends Thread implements FileHandler, Applica
|
|||||||
|
|
||||||
public boolean isRunning()
|
public boolean isRunning()
|
||||||
{
|
{
|
||||||
lock.readLock().lock();
|
return running;
|
||||||
try
|
|
||||||
{
|
|
||||||
return running;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
lock.readLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getNumFilesSeen()
|
public long getNumFilesSeen()
|
||||||
|
@@ -29,7 +29,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.repo.content.ContentContext;
|
import org.alfresco.repo.content.ContentContext;
|
||||||
@@ -48,7 +47,6 @@ import org.junit.AfterClass;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mozilla.javascript.ObjToIntMap.Iterator;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,4 +189,82 @@ public class StandardQuotaStrategyTest
|
|||||||
{
|
{
|
||||||
return FileUtils.listFiles(cacheRoot, new SuffixFileFilter(".bin"), TrueFileFilter.INSTANCE);
|
return FileUtils.listFiles(cacheRoot, new SuffixFileFilter(".bin"), TrueFileFilter.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Not a unit test, but useful to fire up a lot of writers that will push the
|
||||||
|
* CachingContentStore's StandardQuotaStrategy beyond the panic threshold. The
|
||||||
|
* behaviour can then be monitored with, for example, a profiler.
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private void concurrencySmokeTest() throws Exception
|
||||||
|
{
|
||||||
|
StandardQuotaStrategyTest.beforeClass();
|
||||||
|
setUp();
|
||||||
|
// Need to set maxDeleteWatch count to > 0
|
||||||
|
// (0 is useful in unit tests, but for real usage must not be used)
|
||||||
|
cleaner.setMaxDeleteWatchCount(1);
|
||||||
|
|
||||||
|
final int numThreads = 100;
|
||||||
|
Thread[] writers = new Thread[numThreads];
|
||||||
|
for (int i = 0; i < numThreads; i++)
|
||||||
|
{
|
||||||
|
final String threadName = "WriterThread[" + i + "]";
|
||||||
|
Runnable runnable = new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
writeFile();
|
||||||
|
pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeFile()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
writeSingleFileInMB(1);
|
||||||
|
}
|
||||||
|
catch (IOException error)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(threadName + " couldn't write file.", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pause()
|
||||||
|
{
|
||||||
|
long pauseTimeMillis = Math.round(Math.random() * 2000);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(pauseTimeMillis);
|
||||||
|
}
|
||||||
|
catch (InterruptedException error)
|
||||||
|
{
|
||||||
|
// Swallow the exception and carry on.
|
||||||
|
System.out.println(threadName + " InterruptedException.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Thread writerThread = new Thread(runnable);
|
||||||
|
writerThread.setName(threadName);
|
||||||
|
writers[i] = writerThread;
|
||||||
|
|
||||||
|
writerThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// StandardQuotaStrategyTest.afterClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception
|
||||||
|
{
|
||||||
|
StandardQuotaStrategyTest test = new StandardQuotaStrategyTest();
|
||||||
|
test.concurrencySmokeTest();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
class="org.alfresco.repo.content.caching.quota.StandardQuotaStrategy"
|
class="org.alfresco.repo.content.caching.quota.StandardQuotaStrategy"
|
||||||
init-method="init"
|
init-method="init"
|
||||||
destroy-method="shutdown">
|
destroy-method="shutdown">
|
||||||
<property name="maxUsageBytes" value="20971520"/><!-- 20971520 = 20MB -->
|
<property name="maxUsageMB" value="20"/>
|
||||||
<property name="cleaner" ref="cachedContentCleaner"/>
|
<property name="cleaner" ref="cachedContentCleaner"/>
|
||||||
<property name="cache" ref="contentCache"/>
|
<property name="cache" ref="contentCache"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
Reference in New Issue
Block a user