This is an automated email from the ASF dual-hosted git repository.

jackylk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/carbondata.git


The following commit(s) were added to refs/heads/master by this push:
     new fae47a3  [CARBONDATA-3859] Retry to read tablestatus before throwing 
EOFException or JsonSyntaxException or FileNotFoundException
fae47a3 is described below

commit fae47a39316d8340f16d93010ee7a744ce87f2c9
Author: haomarch <marchp...@126.com>
AuthorDate: Sat Jun 20 23:45:22 2020 +0800

    [CARBONDATA-3859] Retry to read tablestatus before throwing EOFException or 
JsonSyntaxException or FileNotFoundException
    
    Why is this PR needed?
    when storing table status file in object store, reading of table status 
file mayfail (receive EOFException or JsonSyntaxException or 
FileNotFoundException)
    when table status file is being modifying
    we shall retry multiple times and add the lock before throwing EOFException 
or JsonSyntaxException
    
    What changes were proposed in this PR?
    Add lock and retry mechanism to read tablestatus
    
    Does this PR introduce any user interface change?
    No
    
    Is any new testcase added?
    No
    
    This closes #3796
---
 .../core/statusmanager/SegmentStatusManager.java   | 79 +++++++++++++---------
 1 file changed, 47 insertions(+), 32 deletions(-)

diff --git 
a/core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java
 
b/core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java
index 480d6ae..16b2a4e 100755
--- 
a/core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java
+++ 
b/core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java
@@ -61,6 +61,7 @@ import org.apache.carbondata.core.util.path.CarbonTablePath;
 import static 
org.apache.carbondata.core.constants.CarbonCommonConstants.DEFAULT_CHARSET;
 
 import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.log4j.Logger;
 
@@ -76,7 +77,13 @@ public class SegmentStatusManager {
 
   private Configuration configuration;
 
-  private static final int READ_TABLE_STATUS_RETRY_COUNT = 3;
+  private static final int READ_TABLE_STATUS_RETRY_COUNT = CarbonLockUtil
+          
.getLockProperty(CarbonCommonConstants.NUMBER_OF_TRIES_FOR_CARBON_LOCK,
+                  
CarbonCommonConstants.NUMBER_OF_TRIES_FOR_CARBON_LOCK_DEFAULT);
+
+  private static final int READ_TABLE_STATUS_RETRY_TIMEOUT = CarbonLockUtil
+          .getLockProperty(CarbonCommonConstants.MAX_TIMEOUT_FOR_CARBON_LOCK,
+                  CarbonCommonConstants.MAX_TIMEOUT_FOR_CARBON_LOCK_DEFAULT);
 
   public SegmentStatusManager(AbsoluteTableIdentifier identifier) {
     this.identifier = identifier;
@@ -294,56 +301,64 @@ public class SegmentStatusManager {
       return null;
     }
 
-    // When storing table status file in object store, reading of table status 
file may
-    // fail (receive EOFException) when table status file is being modifying
-    // so here we retry multiple times before throwing EOFException
+    try {
+      dataInputStream = fileOperation.openForRead();
+      inStream = new InputStreamReader(dataInputStream, 
Charset.forName(DEFAULT_CHARSET));
+      buffReader = new BufferedReader(inStream);
+      return buffReader.readLine();
+    } catch (EOFException ex) {
+      throw ex;
+    } catch (IOException e) {
+      LOG.error("Failed to read table status file", e);
+      throw e;
+    } finally {
+      closeStreams(buffReader, inStream, dataInputStream);
+    }
+  }
+
+  /**
+   * Read table status file and decoded to segment meta arrays
+   *
+   * @param tableStatusPath table status file path
+   * @return segment metadata
+   * @throws IOException if IO errors
+   */
+  public static LoadMetadataDetails[] readTableStatusFile(String 
tableStatusPath)
+      throws IOException {
     int retry = READ_TABLE_STATUS_RETRY_COUNT;
+
+    // When storing table status file in object store, reading of table status 
file may
+    // fail (receive IOException or JsonSyntaxException)
+    // when table status file is being modifying
+    // so here we retry multiple times before
+    // throwing IOException or JsonSyntaxException
     while (retry > 0) {
       try {
-        dataInputStream = fileOperation.openForRead();
-        inStream = new InputStreamReader(dataInputStream, 
Charset.forName(DEFAULT_CHARSET));
-        buffReader = new BufferedReader(inStream);
-        return buffReader.readLine();
-      } catch (EOFException ex) {
+        String content = readFileAsString(tableStatusPath);
+        if (content == null) {
+          return new LoadMetadataDetails[0];
+        }
+        return new Gson().fromJson(content, LoadMetadataDetails[].class);
+      } catch (JsonSyntaxException | IOException ex) {
         retry--;
         if (retry == 0) {
           // we have retried several times, throw this exception to make the 
execution failed
-          LOG.error("Failed to read table status file after retry", ex);
+          LOG.error("Failed to read table status file:" + tableStatusPath);
           throw ex;
         }
         try {
+          LOG.warn("Failed to read table status file, retrycount:" + retry);
           // sleep for some time before retry
-          TimeUnit.MILLISECONDS.sleep(10);
+          TimeUnit.SECONDS.sleep(READ_TABLE_STATUS_RETRY_TIMEOUT);
         } catch (InterruptedException e) {
           // ignored
         }
-      } catch (IOException e) {
-        LOG.error("Failed to read table status file", e);
-        throw e;
-      } finally {
-        closeStreams(buffReader, inStream, dataInputStream);
       }
     }
     return null;
   }
 
   /**
-   * Read table status file and decoded to segment meta arrays
-   *
-   * @param tableStatusPath table status file path
-   * @return segment metadata
-   * @throws IOException if IO errors
-   */
-  public static LoadMetadataDetails[] readTableStatusFile(String 
tableStatusPath)
-      throws IOException {
-    String content = readFileAsString(tableStatusPath);
-    if (content == null) {
-      return new LoadMetadataDetails[0];
-    }
-    return new Gson().fromJson(content, LoadMetadataDetails[].class);
-  }
-
-  /**
    * This method will get the max segment id
    *
    * @param loadMetadataDetails

Reply via email to