Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 25572 invoked from network); 17 Dec 2008 14:44:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Dec 2008 14:44:49 -0000 Received: (qmail 1615 invoked by uid 500); 17 Dec 2008 14:45:02 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 1517 invoked by uid 500); 17 Dec 2008 14:45:01 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 1508 invoked by uid 99); 17 Dec 2008 14:45:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Dec 2008 06:45:01 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Dec 2008 14:44:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2D5782388979; Wed, 17 Dec 2008 06:44:21 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r727402 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/data/FileDataStore.java main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java Date: Wed, 17 Dec 2008 14:44:20 -0000 To: commits@jackrabbit.apache.org From: thomasm@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081217144421.2D5782388979@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: thomasm Date: Wed Dec 17 06:44:20 2008 New Revision: 727402 URL: http://svn.apache.org/viewvc?rev=727402&view=rev Log: JCR-1838 Garbage collection deletes temporary files in DataStore Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java?rev=727402&r1=727401&r2=727402&view=diff ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java Wed Dec 17 06:44:20 2008 @@ -165,6 +165,8 @@ File temporary = null; try { temporary = newTemporaryFile(); + DataIdentifier tempId = new DataIdentifier(temporary.getName()); + usesIdentifier(tempId); // Copy the stream to the temporary file and calculate the // stream length and the message digest of the stream long length = 0; @@ -211,7 +213,9 @@ throw new IOException(DIGEST + " collision: " + file); } } - + // this will also make sure that + // tempId is not garbage collected until here + inUse.remove(tempId); return new FileDataRecord(identifier, file); } catch (NoSuchAlgorithmException e) { throw new DataStoreException(DIGEST + " not available", e); @@ -275,8 +279,9 @@ int count = 0; if (file.isFile() && file.exists() && file.canWrite()) { synchronized (this) { + String fileName = file.getName(); if (file.lastModified() < min) { - DataIdentifier id = new DataIdentifier(file.getName()); + DataIdentifier id = new DataIdentifier(fileName); if (!inUse.containsKey(id)) { file.delete(); count++; Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java?rev=727402&r1=727401&r2=727402&view=diff ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java Wed Dec 17 06:44:20 2008 @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.WeakHashMap; @@ -282,6 +283,11 @@ * All data identifiers that are currently in use are in this set until they are garbage collected. */ protected Map inUse = Collections.synchronizedMap(new WeakHashMap()); + + /** + * The temporary identifiers that are currently in use. + */ + protected List temporaryInUse = Collections.synchronizedList(new ArrayList()); /** * {@inheritDoc} @@ -290,8 +296,8 @@ ResultSet rs = null; TempFileInputStream fileInput = null; ConnectionRecoveryManager conn = getConnection(); + String id = null, tempId = null; try { - String id = null, tempId = null; long now; for (int i = 0; i < ConnectionRecoveryManager.TRIALS; i++) { try { @@ -315,6 +321,7 @@ log.error(msg); throw new DataStoreException(msg); } + temporaryInUse.add(tempId); MessageDigest digest = getDigest(); DigestInputStream dIn = new DigestInputStream(stream, digest); TrackingInputStream in = new TrackingInputStream(dIn); @@ -372,6 +379,9 @@ } catch (Exception e) { throw convert("Can not insert new record", e); } finally { + if (tempId != null) { + temporaryInUse.remove(tempId); + } DatabaseHelper.closeSilently(rs); putBack(conn); if (fileInput != null) { @@ -404,13 +414,19 @@ public synchronized int deleteAllOlderThan(long min) throws DataStoreException { ConnectionRecoveryManager conn = getConnection(); try { - Iterator it = new ArrayList(inUse.keySet()).iterator(); - while (it.hasNext()) { + ArrayList touch = new ArrayList(); + for (Iterator it = new ArrayList(inUse.keySet()).iterator(); it.hasNext();) { DataIdentifier identifier = (DataIdentifier) it.next(); if (identifier != null) { - touch(identifier, 0); + touch.add(identifier.toString()); } } + touch.addAll(temporaryInUse); + Iterator it = touch.iterator(); + while (it.hasNext()) { + String key = (String) it.next(); + updateLastModifiedDate(key, 0); + } // DELETE FROM DATASTORE WHERE LAST_MODIFIED