Merged BRANCHES/DEV/THOR1 to HEAD:

32579: Caching Content Store: fixes bug where cache-usage.ser wasn't loaded on startup.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32630 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2011-12-08 10:07:22 +00:00
parent a411eb6fe0
commit fde60b548c

View File

@@ -27,6 +27,8 @@ import java.util.concurrent.atomic.AtomicLong;
import org.alfresco.repo.content.caching.ContentCacheImpl; import org.alfresco.repo.content.caching.ContentCacheImpl;
import org.alfresco.repo.content.caching.cleanup.CachedContentCleaner; import org.alfresco.repo.content.caching.cleanup.CachedContentCleaner;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.repo.content.filestore.FileContentWriter;
import org.alfresco.util.PropertyCheck; import org.alfresco.util.PropertyCheck;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -53,7 +55,7 @@ import org.springframework.beans.factory.annotation.Required;
*/ */
public class StandardQuotaStrategy implements QuotaManagerStrategy, UsageTracker public class StandardQuotaStrategy implements QuotaManagerStrategy, UsageTracker
{ {
private static final String CACHE_USAGE_FILENAME = "cache-usage.ser"; private static final String CACHE_USAGE_FILENAME = "cache-usage.txt";
private final static Log log = LogFactory.getLog(StandardQuotaStrategy.class); private final static Log log = LogFactory.getLog(StandardQuotaStrategy.class);
private static final long DEFAULT_DISK_USAGE_ESTIMATE = 0L; private static final long DEFAULT_DISK_USAGE_ESTIMATE = 0L;
private int panicThresholdPct = 90; private int panicThresholdPct = 90;
@@ -108,26 +110,27 @@ public class StandardQuotaStrategy implements QuotaManagerStrategy, UsageTracker
private void loadDiskUsage() private void loadDiskUsage()
{ {
// Load the last known disk usage value. File usageFile = new File(cache.getCacheRoot(), CACHE_USAGE_FILENAME);
try
if (!usageFile.exists())
{ {
FileInputStream fis = new FileInputStream(new File(cache.getCacheRoot(), CACHE_USAGE_FILENAME));
ObjectInputStream ois = new ObjectInputStream(fis);
currentUsageBytes.set(ois.readLong());
ois.close();
if (log.isInfoEnabled())
{
log.info("Using last known disk usage estimate: " + getCurrentUsageBytes());
}
}
catch (Throwable e)
{
// Assume disk usage
setCurrentUsageBytes(DEFAULT_DISK_USAGE_ESTIMATE); setCurrentUsageBytes(DEFAULT_DISK_USAGE_ESTIMATE);
if (log.isInfoEnabled()) if (log.isInfoEnabled())
{ {
log.info("Unable to load last known disk usage estimate so assuming: " + getCurrentUsageBytes()); log.info("No previous usage file found (" + usageFile + ") so assuming: " +
getCurrentUsageBytes() + " bytes.");
}
}
else
{
FileContentReader reader = new FileContentReader(usageFile);
String usageStr = reader.getContentString();
long usage = Long.parseLong(usageStr);
currentUsageBytes.set(usage);
if (log.isInfoEnabled())
{
log.info("Using last known disk usage estimate: " + getCurrentUsageBytes());
} }
} }
} }
@@ -135,18 +138,9 @@ public class StandardQuotaStrategy implements QuotaManagerStrategy, UsageTracker
private void saveDiskUsage() private void saveDiskUsage()
{ {
// Persist the last known disk usage value. File usageFile = new File(cache.getCacheRoot(), CACHE_USAGE_FILENAME);
try FileContentWriter writer = new FileContentWriter(usageFile);
{ writer.putContent(currentUsageBytes.toString());
FileOutputStream fos = new FileOutputStream(new File(cache.getCacheRoot(), CACHE_USAGE_FILENAME));
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject(currentUsageBytes);
out.close();
}
catch (Throwable e)
{
throw new RuntimeException("Unable to save content cache disk usage statistics.", e);
}
} }