From 73d39ca0234d39a9b6ce846db8b68db140240562 Mon Sep 17 00:00:00 2001 From: jhkim Date: Fri, 26 Sep 2014 14:41:36 +0900 Subject: [PATCH] TAJO-1074: Query calculates wrong progress before subquery init --- .../java/org/apache/tajo/cli/TajoCli.java | 2 +- .../apache/tajo/master/querymaster/Query.java | 12 +--- .../java/org/apache/tajo/util/JSPUtil.java | 2 +- .../master/querymaster/TestQueryProgress.java | 67 +++++++++++++++++++ 4 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 tajo-core/src/test/java/org/apache/tajo/master/querymaster/TestQueryProgress.java diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java b/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java index d5040bd403..51c8c9f84d 100644 --- a/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java +++ b/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java @@ -587,7 +587,7 @@ private void waitForQueryCompleted(QueryId queryId) { if (TajoClient.isInCompleteState(status.getState()) && status.getState() != QueryState.QUERY_KILL_WAIT) { break; } else { - Thread.sleep(Math.min(100 * progressRetries, 1000)); + Thread.sleep(Math.min(200 * progressRetries, 1000)); progressRetries += 2; } } diff --git a/tajo-core/src/main/java/org/apache/tajo/master/querymaster/Query.java b/tajo-core/src/main/java/org/apache/tajo/master/querymaster/Query.java index 7063197b49..c2cf54e8e5 100644 --- a/tajo-core/src/main/java/org/apache/tajo/master/querymaster/Query.java +++ b/tajo-core/src/main/java/org/apache/tajo/master/querymaster/Query.java @@ -245,26 +245,18 @@ public float getProgress() { synchronized(subqueries) { tempSubQueries.addAll(subqueries.values()); } + float [] subProgresses = new float[tempSubQueries.size()]; - boolean finished = true; for (SubQuery subquery: tempSubQueries) { if (subquery.getState() != SubQueryState.NEW) { subProgresses[idx] = subquery.getProgress(); - if (finished && subquery.getState() != SubQueryState.SUCCEEDED) { - finished = false; - } } else { subProgresses[idx] = 0.0f; - finished = false; } idx++; } - if (finished) { - return 1.0f; - } - - float totalProgress = 0; + float totalProgress = 0.0f; float proportion = 1.0f / (float)(getExecutionBlockCursor().size() - 1); // minus one is due to for (int i = 0; i < subProgresses.length; i++) { diff --git a/tajo-core/src/main/java/org/apache/tajo/util/JSPUtil.java b/tajo-core/src/main/java/org/apache/tajo/util/JSPUtil.java index 8aebab0e81..fb7ba26f61 100644 --- a/tajo-core/src/main/java/org/apache/tajo/util/JSPUtil.java +++ b/tajo-core/src/main/java/org/apache/tajo/util/JSPUtil.java @@ -218,7 +218,7 @@ public int compare(FunctionDesc f1, FunctionDesc f2) { }); } - static final DecimalFormat PERCENT_FORMAT = new DecimalFormat("###.0"); + static final DecimalFormat PERCENT_FORMAT = new DecimalFormat("###.#"); public static String percentFormat(float value) { return PERCENT_FORMAT.format(value * 100.0f); } diff --git a/tajo-core/src/test/java/org/apache/tajo/master/querymaster/TestQueryProgress.java b/tajo-core/src/test/java/org/apache/tajo/master/querymaster/TestQueryProgress.java new file mode 100644 index 0000000000..0efc7960a3 --- /dev/null +++ b/tajo-core/src/test/java/org/apache/tajo/master/querymaster/TestQueryProgress.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tajo.master.querymaster; + +import org.apache.tajo.*; +import org.apache.tajo.client.QueryStatus; +import org.apache.tajo.client.TajoClient; +import org.apache.tajo.conf.TajoConf; +import org.apache.tajo.ipc.ClientProtos; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import static org.junit.Assert.*; + +@Category(IntegrationTest.class) +public class TestQueryProgress { + private static TajoTestingCluster cluster; + private static TajoConf conf; + private static TajoClient client; + + @BeforeClass + public static void setUp() throws Exception { + cluster = TpchTestBase.getInstance().getTestingCluster(); + conf = cluster.getConfiguration(); + client = new TajoClient(conf); + } + + @Test(timeout = 10000) + public final void testQueryProgress() throws Exception { + ClientProtos.SubmitQueryResponse res = client.executeQuery("select l_orderkey from lineitem group by l_orderkey"); + QueryId queryId = new QueryId(res.getQueryId()); + + float prevProgress = 0; + while (true) { + QueryStatus status = client.getQueryStatus(queryId); + if (status == null) continue; + + float progress = status.getProgress(); + + if (prevProgress > progress) { + fail("Previous progress: " + prevProgress + ", Current progress : " + progress); + } + prevProgress = progress; + assertTrue(progress <= 1.0f); + + if (TajoClient.isInCompleteState(status.getState())) break; + } + } +}