tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [13/19] git commit: TAJO-916: SubQuery::computeStatFromTasks occasionally fail. (Hyoungjun Kim via hyunsik)
Date Tue, 15 Jul 2014 07:16:52 GMT
TAJO-916: SubQuery::computeStatFromTasks occasionally fail. (Hyoungjun Kim via hyunsik)

Closes #69


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/fe557ad2
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/fe557ad2
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/fe557ad2

Branch: refs/heads/index_support
Commit: fe557ad24a70f6d698cc85f0bb75765906eb3641
Parents: 0a39818
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Mon Jul 14 18:19:07 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Mon Jul 14 18:19:30 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 ++
 .../tajo/catalog/statistics/TableStats.java     |  9 +---
 .../tajo/catalog/statistics/TestTableStat.java  | 55 ++++++++++++++++++++
 3 files changed, 59 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/fe557ad2/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 26d3341..3c326dc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -82,6 +82,9 @@ Release 0.9.0 - unreleased
 
   BUG FIXES
 
+    TAJO-916: SubQuery::computeStatFromTasks occasionally fail.
+    (Hyoungjun Kim via hyunsik)
+
     TAJO-869: Sometimes, the unit test of testTaskRunnerHistory is failed.
     (jinho)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/fe557ad2/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/statistics/TableStats.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/statistics/TableStats.java
b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/statistics/TableStats.java
index c04545c..dd358ae 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/statistics/TableStats.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/statistics/TableStats.java
@@ -36,8 +36,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 public class TableStats implements ProtoObject<TableStatsProto>, Cloneable, GsonObject
{
-  private TableStatsProto.Builder builder = TableStatsProto.newBuilder();
-
   @Expose private Long numRows = null; // required
   @Expose private Long numBytes = null; // required
   @Expose private Integer numBlocks = null; // optional
@@ -178,7 +176,6 @@ public class TableStats implements ProtoObject<TableStatsProto>,
Cloneable, Gson
 
   public Object clone() throws CloneNotSupportedException {
     TableStats stat = (TableStats) super.clone();
-    stat.builder = CatalogProtos.TableStatsProto.newBuilder();
     stat.numRows = numRows != null ? numRows : null;
     stat.numBytes = numBytes != null ? numBytes : null;
     stat.numBlocks = numBlocks != null ? numBlocks : null;
@@ -241,11 +238,7 @@ public class TableStats implements ProtoObject<TableStatsProto>,
Cloneable, Gson
 
   @Override
   public TableStatsProto getProto() {
-    if (builder == null) {
-      builder = CatalogProtos.TableStatsProto.newBuilder();
-    } else {
-      builder.clear();
-    }
+    TableStatsProto.Builder builder = CatalogProtos.TableStatsProto.newBuilder();
 
     builder.setNumRows(this.numRows);
     builder.setNumBytes(this.numBytes);

http://git-wip-us.apache.org/repos/asf/tajo/blob/fe557ad2/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/statistics/TestTableStat.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/statistics/TestTableStat.java
b/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/statistics/TestTableStat.java
index c258f16..b649dd7 100644
--- a/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/statistics/TestTableStat.java
+++ b/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/statistics/TestTableStat.java
@@ -20,11 +20,19 @@ package org.apache.tajo.catalog.statistics;
 
 import org.apache.tajo.catalog.Column;
 import org.apache.tajo.catalog.json.CatalogGsonHelper;
+import org.apache.tajo.catalog.proto.CatalogProtos.TableStatsProto;
 import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.TextDatum;
 import org.junit.Test;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 public class TestTableStat {
   @Test
@@ -76,4 +84,51 @@ public class TestTableStat {
       assertEquals(s1.getColumnStats().get(i), s2.getColumnStats().get(i));
     }
   }
+
+  @Test
+  public void testGetProtoThreadSafe() throws Exception {
+    final TableStats tableStats = new TableStats();
+
+    List<ColumnStats> columnStatsList = new ArrayList<ColumnStats>();
+    for (int i = 0; i < 3; i++) {
+      Column column = new Column("col_" + (i + 1), Type.TEXT);
+      ColumnStats columnStats = new ColumnStats(column);
+      columnStats.setMinValue(new TextDatum(i + ""));
+      columnStats.setMaxValue(new TextDatum((100 - i) + ""));
+
+      columnStatsList.add(columnStats);
+    }
+    tableStats.setColumnStats(columnStatsList);
+
+    int numThread = 10;
+    final CountDownLatch latch = new CountDownLatch(numThread);
+    final AtomicBoolean success = new AtomicBoolean(true);
+    for (int i = 0; i < numThread; i++) {
+      Thread t = new Thread() {
+        public void run() {
+          for (int j = 0; j < 100; j++) {
+            try {
+              TableStatsProto proto = tableStats.getProto();
+              if (tableStats.getColumnStats().size() != proto.getColStatList().size()) {
+                success.set(false);
+                break;
+              }
+            } catch (Exception e) {
+              success.set(false);
+            }
+          }
+
+          latch.countDown();
+        }
+      };
+
+      t.start();
+    }
+
+    latch.await();
+
+    if (!success.get()) {
+      fail("TableStats returns different column ststs");
+    }
+  }
 }


Mime
View raw message