Repository: helix Updated Branches: refs/heads/helix-0.6.x a80ba8ebd -> e924a4c4e
[HELIX-584] SimpleDateFormat should not be used as singleton due to its race conditions. Project: http://git-wip-us.apache.org/repos/asf/helix/repo Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/e924a4c4 Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/e924a4c4 Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/e924a4c4 Branch: refs/heads/helix-0.6.x Commit: e924a4c4ee1f1c52dcf6b478bbc88d3050e9d0f8 Parents: a80ba8e Author: Lei Xia <[email protected]> Authored: Fri Mar 20 15:55:24 2015 -0700 Committer: Lei Xia <[email protected]> Committed: Fri Mar 20 16:02:05 2015 -0700 ---------------------------------------------------------------------- .../main/java/org/apache/helix/task/TaskDriver.java | 2 +- .../main/java/org/apache/helix/task/TaskUtil.java | 2 +- .../java/org/apache/helix/task/WorkflowConfig.java | 15 +++++++++------ .../helix/integration/TestBucketizedResource.java | 5 +++-- .../task/TestTaskRebalancerStopResume.java | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/helix/blob/e924a4c4/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java b/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java index b8ca141..f0670cf 100644 --- a/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java +++ b/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java @@ -659,7 +659,7 @@ public class TaskDriver { // find a task for (String resource : _admin.getResourcesInCluster(_clusterName)) { IdealState is = _admin.getResourceIdealState(_clusterName, resource); - if (is.getStateModelDefRef().equals(TaskConstants.STATE_MODEL_NAME)) { + if (is != null && is.getStateModelDefRef().equals(TaskConstants.STATE_MODEL_NAME)) { _accessor.updateProperty(_accessor.keyBuilder().idealStates(resource), is); break; } http://git-wip-us.apache.org/repos/asf/helix/blob/e924a4c4/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java b/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java index a37dd6f..2235b80 100644 --- a/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java +++ b/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java @@ -362,7 +362,7 @@ public class TaskUtil { Date startTime = null; if (cfg.containsKey(WorkflowConfig.START_TIME)) { try { - startTime = WorkflowConfig.DEFAULT_DATE_FORMAT.parse(cfg.get(WorkflowConfig.START_TIME)); + startTime = WorkflowConfig.getDefaultDateFormat().parse(cfg.get(WorkflowConfig.START_TIME)); } catch (ParseException e) { LOG.error("Unparseable date " + cfg.get(WorkflowConfig.START_TIME), e); return null; http://git-wip-us.apache.org/repos/asf/helix/blob/e924a4c4/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java b/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java index 4129fea..06d92fc 100644 --- a/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java +++ b/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java @@ -41,11 +41,6 @@ public class WorkflowConfig { /* Default values */ public static final long DEFAULT_EXPIRY = 24 * 60 * 60 * 1000; - public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat( - "MM-dd-yyyy HH:mm:ss"); - static { - DEFAULT_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); - } /* Member variables */ private final JobDag _jobDag; @@ -87,6 +82,14 @@ public class WorkflowConfig { return _scheduleConfig != null && _scheduleConfig.isRecurring(); } + public static SimpleDateFormat getDefaultDateFormat() { + SimpleDateFormat defaultDateFormat = new SimpleDateFormat( + "MM-dd-yyyy HH:mm:ss"); + defaultDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + + return defaultDateFormat; + } + public Map<String, String> getResourceConfigMap() throws Exception { Map<String, String> cfgMap = new HashMap<String, String>(); cfgMap.put(WorkflowConfig.DAG, getJobDag().toJson()); @@ -99,7 +102,7 @@ public class WorkflowConfig { if (scheduleConfig != null) { Date startTime = scheduleConfig.getStartTime(); if (startTime != null) { - String formattedTime = WorkflowConfig.DEFAULT_DATE_FORMAT.format(startTime); + String formattedTime = WorkflowConfig.getDefaultDateFormat().format(startTime); cfgMap.put(WorkflowConfig.START_TIME, formattedTime); } if (scheduleConfig.isRecurring()) { http://git-wip-us.apache.org/repos/asf/helix/blob/e924a4c4/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java b/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java index c1b8ba5..56f9d59 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java @@ -269,8 +269,8 @@ public class TestBucketizedResource extends ZkIntegrationTestBase { // wait callback to finish int waitTime =0; do { - Thread.sleep(1000); - waitTime += 1000; + Thread.sleep(100); + waitTime += 100; if (waitTime > 30000) { break; } @@ -293,6 +293,7 @@ public class TestBucketizedResource extends ZkIntegrationTestBase { ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName)); Assert.assertTrue(result); + Thread.sleep(200); Assert.assertTrue(listener.cbCnt > 0); // clean up http://git-wip-us.apache.org/repos/asf/helix/blob/e924a4c4/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java index fd709d8..e75e2c9 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java +++ b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java @@ -373,7 +373,7 @@ public class TestTaskRebalancerStopResume extends ZkIntegrationTestBase { { Map<String, String> cfgMap = new HashMap<String, String>(); cfgMap.put(WorkflowConfig.EXPIRY, String.valueOf(50000)); - cfgMap.put(WorkflowConfig.START_TIME, WorkflowConfig.DEFAULT_DATE_FORMAT.format( + cfgMap.put(WorkflowConfig.START_TIME, WorkflowConfig.getDefaultDateFormat().format( Calendar.getInstance().getTime())); cfgMap.put(WorkflowConfig.RECURRENCE_INTERVAL, String.valueOf(60)); cfgMap.put(WorkflowConfig.RECURRENCE_UNIT, "SECONDS");
