jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1585460 - in /jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data: AsyncUploadCache.java LocalCache.java
Date Mon, 07 Apr 2014 11:53:14 GMT
Author: chetanm
Date: Mon Apr  7 11:53:14 2014
New Revision: 1585460

URL: http://svn.apache.org/r1585460
Log:
JCR-3754 [jackrabbit-aws-ext] Add retry logic to S3 asynchronous failed upload

Applying patch from Shashank.
-- Using parameterized logging stmts. No logic changes

Modified:
    jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AsyncUploadCache.java
    jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AsyncUploadCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AsyncUploadCache.java?rev=1585460&r1=1585459&r2=1585460&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AsyncUploadCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AsyncUploadCache.java
Mon Apr  7 11:53:14 2014
@@ -93,14 +93,11 @@ public class AsyncUploadCache {
             throws IOException {
         AsyncUploadCacheResult result = new AsyncUploadCacheResult();
         if (asyncUploadMap.entrySet().size() >= asyncUploadLimit) {
-            if (LOG.isInfoEnabled()) {
-                LOG.info("Async write limit [" + asyncUploadLimit
-                    + "] reached. File [" + fileName
-                    + "]  not added to async write cache.");
-            }
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("current set =" + asyncUploadMap.keySet());
-            }
+            LOG.info(
+                "Async write limit [{}]  reached. File [{}] not added to async write cache.",
+                asyncUploadLimit, fileName);
+            LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]",
+                asyncUploadMap.size(), asyncUploadMap.keySet());
             result.setAsyncUpload(false);
         } else {
             long startTime = System.currentTimeMillis();
@@ -109,13 +106,10 @@ public class AsyncUploadCache {
             }
             asyncUploadMap.put(fileName, System.currentTimeMillis());
             serializeAsyncUploadMap();
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("added file [" + fileName
-                    + "] to asyncUploadMap upoad took ["
-                    + ((System.currentTimeMillis() - startTime) / 1000)
-                    + "] sec");
-                LOG.debug("current set =" + asyncUploadMap.keySet());
-            }
+            LOG.debug("added file [{}] to asyncUploadMap upoad took [{}] sec",
+                fileName, ((System.currentTimeMillis() - startTime) / 1000));
+            LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]",
+                asyncUploadMap.size(), asyncUploadMap.keySet());
             result.setAsyncUpload(true);
         }
         return result;
@@ -135,21 +129,15 @@ public class AsyncUploadCache {
         Long retVal = asyncUploadMap.remove(fileName);
         if (retVal != null) {
             serializeAsyncUploadMap();
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("removed file [" + fileName
-                    + "] from asyncUploadMap took ["
-                    + ((System.currentTimeMillis() - startTime) / 1000)
-                    + "] sec");
-                LOG.debug("current set =" + asyncUploadMap.keySet());
-            }
+            LOG.debug("removed file [{}] from asyncUploadMap took [{}] sec",
+                fileName, ((System.currentTimeMillis() - startTime) / 1000));
+            LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]",
+                asyncUploadMap.size(), asyncUploadMap.keySet());
         } else {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("cannot remove file [" + fileName
-                    + "] from pending upoad took ["
-                    + ((System.currentTimeMillis() - startTime) / 1000)
-                    + "] sec. File not found");
-                LOG.debug("current set =" + asyncUploadMap.keySet());
-            }
+            LOG.debug("cannot removed file [{}] from asyncUploadMap took [{}] sec. File not
found.",
+                fileName, ((System.currentTimeMillis() - startTime) / 1000));
+            LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]",
+                asyncUploadMap.size(), asyncUploadMap.keySet());
         }
         AsyncUploadCacheResult result = new AsyncUploadCacheResult();
         result.setRequiresDelete(toBeDeleted.contains(fileName));
@@ -219,7 +207,7 @@ public class AsyncUploadCache {
     public synchronized Set<String> deleteOlderThan(long min)
             throws IOException {
         min = min - 1000;
-        LOG.info("deleteOlderThan min =" + min);
+        LOG.info("deleteOlderThan min [{}]", min);
         Set<String> deleteSet = new HashSet<String>();
         for (Map.Entry<String, Long> entry : asyncUploadMap.entrySet()) {
             if (entry.getValue() < min) {
@@ -227,7 +215,7 @@ public class AsyncUploadCache {
             }
         }
         if (deleteSet.size() > 0) {
-            LOG.info("deleteOlderThan set =" + deleteSet);
+            LOG.debug("deleteOlderThan set [{}]", deleteSet);
             toBeDeleted.addAll(deleteSet);
             serializeToBeDeleted();
         }
@@ -247,8 +235,9 @@ public class AsyncUploadCache {
         this.homeDir = homeDir;
         this.path = path;
         this.asyncUploadLimit = asyncUploadLimit;
-        LOG.info("AsynWriteCache:homeDir [" + homeDir + "], path [" + path
-            + "], asyncUploadLimit [" + asyncUploadLimit + "].");
+        LOG.info(
+            "AsynWriteCache:homeDir=[{}], path=[{}], asyncUploadLimit=[{}].",
+            new Object[] { homeDir, path, asyncUploadLimit });
         pendingUploads = new File(homeDir + "/" + PENDIND_UPLOAD_FILE);
         if (pendingUploads.exists()) {
             deserializeAsyncUploadMap();

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java?rev=1585460&r1=1585459&r2=1585460&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java
Mon Apr  7 11:53:14 2014
@@ -36,7 +36,6 @@ import javax.jcr.RepositoryException;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.core.data.LazyFileInputStream;
 import org.apache.jackrabbit.util.TransientFileFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -109,9 +108,10 @@ public class LocalCache {
         this.maxSize = size;
         directory = new File(path);
         tmp = new File(tmpPath);
-        LOG.info("cachePurgeTrigFactor = " + cachePurgeTrigFactor + ", cachePurgeResizeFactor
= " + cachePurgeResizeFactor
-            + ", cachePurgeTrigFactorSize = " + (cachePurgeTrigFactor * size) + ", cachePurgeResizeFactor
= "
-            + (cachePurgeResizeFactor * size));
+        LOG.info(
+            "cachePurgeTrigFactor =[{}], cachePurgeResizeFactor =[{}],  cachePurgeTrigFactorSize
=[{}], cachePurgeResizeFactorSize =[{}]",
+            new Object[] { cachePurgeTrigFactor, cachePurgeResizeFactor,
+                (cachePurgeTrigFactor * size), (cachePurgeResizeFactor * size) });
         cache = new LRUCache(size, cachePurgeTrigFactor, cachePurgeResizeFactor);
         this.asyncUploadCache = asyncUploadCache;
 
@@ -151,13 +151,10 @@ public class LocalCache {
                     && (f.getParentFile().exists() || f.getParentFile().mkdirs())
                     && transFile.renameTo(f) && f.exists()) {
                     if (transFile.exists() && transFile.delete()) {
-                        LOG.info("tmp file = " + transFile.getAbsolutePath()
-                            + " not deleted successfully");
+                        LOG.info("tmp file [{}] not deleted successfully", transFile.getAbsolutePath());
                     }
                     transFile = null;
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("file [" + fileName + "] added to local cache.");
-                    }
+                    LOG.debug("file [{}] added to local cache.", fileName);
                     cache.put(fileName, f.length());
                 } else {
                     f = transFile;
@@ -223,9 +220,7 @@ public class LocalCache {
                 dest.setLastModified(System.currentTimeMillis());
             }
             cache.put(fileName, dest.length());
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("file [" + fileName + "] added to local cache.");
-            }
+            LOG.debug("file [{}] added to local cache.", fileName);
             result.setFile(dest);
             if (tryForAsyncUpload) {
                 result.setAsyncUpload(asyncUploadCache.add(fileName).canAsyncUpload());
@@ -251,7 +246,9 @@ public class LocalCache {
         // return file in purge mode = true and file present in asyncUploadCache
         // as asyncUploadCache's files will be not be deleted in cache purge.
         if (!f.exists() || (isInPurgeMode() && !asyncUploadCache.hasEntry(fileName,
false))) {
-            log("purgeMode true or file doesn't exists: getFileIfStored returned");
+            LOG.debug(
+                "getFileIfStored returned: purgeMode=[{}], file=[{}] exists=[{}]",
+                new Object[] { isInPurgeMode(), fileName, f.exists() });
             return null;
         } else {
             // touch entry in LRU caches
@@ -269,7 +266,7 @@ public class LocalCache {
      */
     public synchronized void delete(String fileName) {
         if (isInPurgeMode()) {
-            log("purgeMode true :delete returned");
+            LOG.debug("purgeMode true :delete returned");
             return;
         }
         fileName = fileName.replace("\\", "/");
@@ -302,7 +299,7 @@ public class LocalCache {
      * unsuccessful delete files.
      */
     public void close() {
-        log("close");
+        LOG.debug("close");
         deleteOldFiles();
     }
 
@@ -315,7 +312,8 @@ public class LocalCache {
       //order is important here
         boolean value = !isInPurgeMode() && (cache.canAdmitFile(length));
         if (!value) {
-            log("cannot admit file of length=" + length + " and currentSizeInBytes=" + cache.currentSizeInBytes);
+            LOG.debug("cannot admit file of length=[{}] and currentSizeInBytes=[{}] ",
+                length, cache.currentSizeInBytes);
         }
         return value;
     }
@@ -349,7 +347,7 @@ public class LocalCache {
                 count++;
             }
         }
-        LOG.info("deleted [" + count + "]/[" + initialSize + "] files");
+        LOG.info("deleted [{}]/[{}] files.", count, initialSize);
     }
 
     /**
@@ -360,10 +358,10 @@ public class LocalCache {
      * @return true if this method deletes file successfuly else return false.
      */
     boolean tryDelete(final String fileName) {
-        log("cache delete " + fileName);
+        LOG.debug("try deleting file [{}]", fileName);
         File f = getFile(fileName);
         if (f.exists() && f.delete()) {
-            log(fileName + "  deleted successfully");
+            LOG.debug("File [{}]  deleted successfully", fileName);
             toBeDeleted.remove(fileName);
             while (true) {
                 f = f.getParentFile();
@@ -375,7 +373,7 @@ public class LocalCache {
             }
             return true;
         } else if (f.exists()) {
-            LOG.info("not able to delete file = " + f.getAbsolutePath());
+            LOG.info("not able to delete file [{}]", f.getAbsolutePath());
             toBeDeleted.add(fileName);
             return false;
         }
@@ -391,10 +389,6 @@ public class LocalCache {
         return count;
     }
 
-    static void log(final String s) {
-        LOG.debug(s);
-    }
-
     /**
      * A LRU based extension {@link LinkedHashMap}. The key is file name and
      * value is length of file.
@@ -433,28 +427,30 @@ public class LocalCache {
                 // not removing file from local cache, if there is in progress
                 // async upload on it.
                 if (asyncUploadCache.hasEntry(fileName, false)) {
-                    LOG.info("AsyncUploadCache upload contains file [" + fileName
-                        + "]. Not removing it from LocalCache.");
+                    LOG.info(
+                        "AsyncUploadCache upload contains file [{}]. Not removing it from
LocalCache.",
+                        fileName);
                     return null;
                 }
             } catch (IOException e) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("error: ", e);
-                }
+                LOG.debug("error: ", e);
                 return null;
             }
             Long flength = null;
             if (tryDelete(fileName)) {
                 flength = super.remove(key);
                 if (flength != null) {
-                    log("cache entry { " + fileName + "} with size {" + flength + "} removed.");
+                    LOG.debug("cache entry [{}], with size [{}] removed.",
+                        fileName, flength);
                     currentSizeInBytes -= flength.longValue();
                 }
             } else if (!getFile(fileName).exists()) {
                 // second attempt. remove from cache if file doesn't exists
                 flength = super.remove(key);
                 if (flength != null) {
-                    log(" file not exists. cache entry { " + fileName + "} with size {" +
flength + "} removed.");
+                    LOG.debug(
+                        "file not exists. cache entry [{}], with size [{}] removed.",
+                        fileName, flength);
                     currentSizeInBytes -= flength.longValue();
                 }
             }
@@ -481,14 +477,15 @@ public class LocalCache {
         synchronized void tryPurge() {
             if (currentSizeInBytes > cachePurgeTrigSize && !isInPurgeMode()) {
                 setPurgeMode(true);
-                LOG.info("currentSizeInBytes[" + cache.currentSizeInBytes + "] exceeds (cachePurgeTrigSize)["
+ cache.cachePurgeTrigSize
-                    + "]");
+                LOG.info(
+                    "currentSizeInBytes=[{}]  exceeds cachePurgeTrigSize=[{}]",
+                    cache.currentSizeInBytes, cache.cachePurgeTrigSize);
                 new Thread(new PurgeJob()).start();
             } else {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("currentSizeInBytes[" + cache.currentSizeInBytes + "] and 
(cachePurgeTrigSize)[" + cache.cachePurgeTrigSize
-                        + "], isInPurgeMode =[" + isInPurgeMode() + "]");
-                }
+                LOG.debug(
+                    "currentSizeInBytes=[{}],cachePurgeTrigSize=[{}], isInPurgeMode =[{}]",
+                    new Object[] { cache.currentSizeInBytes,
+                        cache.cachePurgeTrigSize, isInPurgeMode() });
             }
         }
         /**
@@ -537,10 +534,9 @@ public class LocalCache {
                         }
 
                     }
-                    LOG.info(" cache purge job completed: cleaned ["
-                        + (initialSize - cache.size())
-                        + "] files and currentSizeInBytes = [ "
-                        + cache.currentSizeInBytes + "]");
+                    LOG.info(
+                        " cache purge job completed: cleaned [{}] files and currentSizeInBytes
= [{}]",
+                        (initialSize - cache.size()), cache.currentSizeInBytes);
                 }
             } catch (Exception e) {
                 LOG.error("error in purge jobs:", e);
@@ -564,9 +560,8 @@ public class LocalCache {
                 allFiles.add(f);
             }
             long t1 = System.currentTimeMillis();
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Time taken to recursive [" + allFiles.size() + "] took [" + ((t1
- startTime) / 1000) + "]sec");
-            }
+            LOG.debug("Time taken to recursive [{}] took [{}] sec",
+                allFiles.size(), ((t1 - startTime) / 1000));
             Collections.sort(allFiles, new Comparator<File>() {
                 public int compare(File o1, File o2) {
                     long l1 = o1.lastModified(), l2 = o2.lastModified();
@@ -574,9 +569,8 @@ public class LocalCache {
                 }
             });
             long t2 = System.currentTimeMillis();
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Time taken to sort [" + allFiles.size() + "] took [" + ((t2 -
t1) / 1000) + "]sec");
-            }
+            LOG.debug("Time taken to sort [{}] took [{}] sec",
+                allFiles.size(), ((t2 - t1) / 1000));
             String dataStorePath = directory.getAbsolutePath();
             long time = System.currentTimeMillis();
             int count = 0;
@@ -600,12 +594,14 @@ public class LocalCache {
                     }
                 }
             }
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Processed {" + count + "}/{" + allFiles.size() + "} , currentSizeInBytes
= " + cache.currentSizeInBytes
-                    + ",  maxSizeInBytes = " + cache.maxSizeInBytes + ",  cache.filecount
= " + cache.size());
-            }
+            LOG.debug(
+                "Processed [{}]/[{}], currentSizeInBytes = [{}], maxSizeInBytes = [{}], cache.filecount
= [{}]",
+                new Object[] { count, allFiles.size(),
+                    cache.currentSizeInBytes, cache.maxSizeInBytes,
+                    cache.size() });
             long t3 = System.currentTimeMillis();
-            LOG.info("Time to build cache of  [" + allFiles.size() + "] took [" + ((t3 -
startTime) / 1000) + "]sec");
+            LOG.info("Time to build cache of  [{}] files took [{}] sec",
+                allFiles.size(), ((t3 - startTime) / 1000));
         }
     }
 }



Mime
View raw message