tez-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ss...@apache.org
Subject git commit: TEZ-575. Change ID classes to be thread safe. (sseth)
Date Tue, 22 Oct 2013 22:37:49 GMT
Updated Branches:
  refs/heads/master d8adaf3b9 -> 569185b0f


TEZ-575. Change ID classes to be thread safe. (sseth)


Project: http://git-wip-us.apache.org/repos/asf/incubator-tez/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tez/commit/569185b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tez/tree/569185b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tez/diff/569185b0

Branch: refs/heads/master
Commit: 569185b0f51c8253d9d97f33b48cba7bb0627c1f
Parents: d8adaf3
Author: Siddharth Seth <sseth@apache.org>
Authored: Tue Oct 22 15:37:24 2013 -0700
Committer: Siddharth Seth <sseth@apache.org>
Committed: Tue Oct 22 15:37:24 2013 -0700

----------------------------------------------------------------------
 .../java/org/apache/tez/client/TezClient.java   | 16 +++++----
 .../org/apache/tez/dag/records/TezDAGID.java    | 38 ++++++++++++--------
 .../org/apache/tez/dag/records/TezTaskID.java   | 18 ++++++----
 .../org/apache/tez/dag/records/TezVertexID.java | 18 ++++++----
 4 files changed, 55 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/569185b0/tez-api/src/main/java/org/apache/tez/client/TezClient.java
----------------------------------------------------------------------
diff --git a/tez-api/src/main/java/org/apache/tez/client/TezClient.java b/tez-api/src/main/java/org/apache/tez/client/TezClient.java
index df260ec..5754900 100644
--- a/tez-api/src/main/java/org/apache/tez/client/TezClient.java
+++ b/tez-api/src/main/java/org/apache/tez/client/TezClient.java
@@ -126,11 +126,15 @@ public class TezClient {
   // DO NOT CHANGE THIS. This code is replicated from TezDAGID.java
   private static final char SEPARATOR = '_';
   private static final String DAG = "dag";
-  private static final NumberFormat idFormat = NumberFormat.getInstance();
-  static {
-    idFormat.setGroupingUsed(false);
-    idFormat.setMinimumIntegerDigits(6);
-  }
+  private static final ThreadLocal<NumberFormat> idFormat = new ThreadLocal<NumberFormat>()
{
+    @Override
+    public NumberFormat initialValue() {
+      NumberFormat fmt = NumberFormat.getInstance();
+      fmt.setGroupingUsed(false);
+      fmt.setMinimumIntegerDigits(6);
+      return fmt;
+    }
+  };
 
   String getDefaultTezDAGID(ApplicationId appId) {
      return (new StringBuilder(DAG)).append(SEPARATOR).
@@ -138,7 +142,7 @@ public class TezClient {
                    append(SEPARATOR).
                    append(appId.getId()).
                    append(SEPARATOR).
-                   append(idFormat.format(1)).toString();
+                   append(idFormat.get().format(1)).toString();
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/569185b0/tez-common/src/main/java/org/apache/tez/dag/records/TezDAGID.java
----------------------------------------------------------------------
diff --git a/tez-common/src/main/java/org/apache/tez/dag/records/TezDAGID.java b/tez-common/src/main/java/org/apache/tez/dag/records/TezDAGID.java
index 37b6a6e..227207a 100644
--- a/tez-common/src/main/java/org/apache/tez/dag/records/TezDAGID.java
+++ b/tez-common/src/main/java/org/apache/tez/dag/records/TezDAGID.java
@@ -103,17 +103,25 @@ public class TezDAGID extends TezID {
 
   // DO NOT CHANGE THIS. DAGClient replicates this code to create DAG id string
   public static final String DAG = "dag";
-  protected static final NumberFormat tezAppIdFormat =
-      NumberFormat.getInstance();
-  protected static final NumberFormat tezDagIdFormat =
-      NumberFormat.getInstance();
-
-  static {
-    tezAppIdFormat.setGroupingUsed(false);
-    tezAppIdFormat.setMinimumIntegerDigits(4);
-    tezDagIdFormat.setGroupingUsed(false);
-    tezDagIdFormat.setMinimumIntegerDigits(1);
-  }
+  protected static final ThreadLocal<NumberFormat> tezAppIdFormat = new ThreadLocal<NumberFormat>()
{
+    @Override
+    public NumberFormat initialValue() {
+      NumberFormat fmt = NumberFormat.getInstance();
+      fmt.setGroupingUsed(false);
+      fmt.setMinimumIntegerDigits(4);
+      return fmt;
+    }
+  };
+  
+  protected static final ThreadLocal<NumberFormat> tezDagIdFormat = new ThreadLocal<NumberFormat>()
{
+    @Override
+    public NumberFormat initialValue() {
+      NumberFormat fmt = NumberFormat.getInstance();
+      fmt.setGroupingUsed(false);
+      fmt.setMinimumIntegerDigits(1);
+      return fmt;
+    }
+  };
 
   @Override
   public String toString() {
@@ -124,9 +132,9 @@ public class TezDAGID extends TezID {
     try {
       String[] split = dagId.split("_");
       String rmId = split[1];
-      int appId = tezAppIdFormat.parse(split[2]).intValue();
+      int appId = tezAppIdFormat.get().parse(split[2]).intValue();
       int id;
-      id = tezDagIdFormat.parse(split[3]).intValue();
+      id = tezDagIdFormat.get().parse(split[3]).intValue();
       return new TezDAGID(rmId, appId, id);
     } catch (Exception e) {
       e.printStackTrace();
@@ -143,9 +151,9 @@ public class TezDAGID extends TezID {
     return builder.append(SEPARATOR).
                  append(applicationId.getClusterTimestamp()).
                  append(SEPARATOR).
-                 append(tezAppIdFormat.format(applicationId.getId())).
+                 append(tezAppIdFormat.get().format(applicationId.getId())).
                  append(SEPARATOR).
-                 append(tezDagIdFormat.format(id));
+                 append(tezDagIdFormat.get().format(id));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/569185b0/tez-common/src/main/java/org/apache/tez/dag/records/TezTaskID.java
----------------------------------------------------------------------
diff --git a/tez-common/src/main/java/org/apache/tez/dag/records/TezTaskID.java b/tez-common/src/main/java/org/apache/tez/dag/records/TezTaskID.java
index 7489ea4..6b2fc2e 100644
--- a/tez-common/src/main/java/org/apache/tez/dag/records/TezTaskID.java
+++ b/tez-common/src/main/java/org/apache/tez/dag/records/TezTaskID.java
@@ -40,12 +40,16 @@ import org.apache.tez.dag.records.TezVertexID;
 @InterfaceStability.Stable
 public class TezTaskID extends TezID {
   public static final String TASK = "task";
-  protected static final NumberFormat idFormat =
-      NumberFormat.getInstance();
-  static {
-    idFormat.setGroupingUsed(false);
-    idFormat.setMinimumIntegerDigits(6);
-  }
+  
+  protected static final ThreadLocal<NumberFormat> idFormat = new ThreadLocal<NumberFormat>()
{
+    @Override
+    public NumberFormat initialValue() {
+      NumberFormat fmt = NumberFormat.getInstance();
+      fmt.setGroupingUsed(false);
+      fmt.setMinimumIntegerDigits(6);
+      return fmt;
+    }
+  };
 
   private TezVertexID vertexId;
 
@@ -104,7 +108,7 @@ public class TezTaskID extends TezID {
   protected StringBuilder appendTo(StringBuilder builder) {
     return vertexId.appendTo(builder).
                  append(SEPARATOR).
-                 append(idFormat.format(id));
+                 append(idFormat.get().format(id));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/569185b0/tez-common/src/main/java/org/apache/tez/dag/records/TezVertexID.java
----------------------------------------------------------------------
diff --git a/tez-common/src/main/java/org/apache/tez/dag/records/TezVertexID.java b/tez-common/src/main/java/org/apache/tez/dag/records/TezVertexID.java
index 55e93b5..e24f35e 100644
--- a/tez-common/src/main/java/org/apache/tez/dag/records/TezVertexID.java
+++ b/tez-common/src/main/java/org/apache/tez/dag/records/TezVertexID.java
@@ -41,12 +41,16 @@ import org.apache.hadoop.classification.InterfaceStability;
 @InterfaceStability.Stable
 public class TezVertexID extends TezID {
   public static final String VERTEX = "vertex";
-  protected static final NumberFormat idFormat =
-      NumberFormat.getInstance();
-  static {
-    idFormat.setGroupingUsed(false);
-    idFormat.setMinimumIntegerDigits(2);
-  }
+  protected static final ThreadLocal<NumberFormat> idFormat = new ThreadLocal<NumberFormat>()
{
+
+    @Override
+    public NumberFormat initialValue() {
+      NumberFormat fmt = NumberFormat.getInstance();
+      fmt.setGroupingUsed(false);
+      fmt.setMinimumIntegerDigits(2);
+      return fmt;
+    }
+  };
 
   private TezDAGID dagId;
 
@@ -114,7 +118,7 @@ public class TezVertexID extends TezID {
   protected StringBuilder appendTo(StringBuilder builder) {
     return dagId.appendTo(builder).
         append(SEPARATOR).
-        append(idFormat.format(id));
+        append(idFormat.get().format(id));
   }
 
   @Override


Mime
View raw message