You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by qh...@apache.org on 2015/09/21 05:01:22 UTC
incubator-kylin git commit: KYLIN-941 fix a concurrent issue
Repository: incubator-kylin
Updated Branches:
refs/heads/2.x-staging 35c57b28d -> db6febc83
KYLIN-941 fix a concurrent issue
Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/db6febc8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/db6febc8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/db6febc8
Branch: refs/heads/2.x-staging
Commit: db6febc832d9f21c3bed263ff4681d9b5bdd0146
Parents: 35c57b2
Author: qianhao.zhou <qi...@ebay.com>
Authored: Fri Sep 18 15:14:53 2015 +0800
Committer: qianhao.zhou <qi...@ebay.com>
Committed: Mon Sep 21 11:00:04 2015 +0800
----------------------------------------------------------------------
.../apache/kylin/engine/spark/SparkCubing.java | 70 ++++++--------------
.../engine/spark/cube/BufferedCuboidWriter.java | 67 +++----------------
2 files changed, 30 insertions(+), 107 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/db6febc8/engine-spark/src/main/java/org/apache/kylin/engine/spark/SparkCubing.java
----------------------------------------------------------------------
diff --git a/engine-spark/src/main/java/org/apache/kylin/engine/spark/SparkCubing.java b/engine-spark/src/main/java/org/apache/kylin/engine/spark/SparkCubing.java
index 8862717..244997e 100644
--- a/engine-spark/src/main/java/org/apache/kylin/engine/spark/SparkCubing.java
+++ b/engine-spark/src/main/java/org/apache/kylin/engine/spark/SparkCubing.java
@@ -17,26 +17,12 @@
*/
package org.apache.kylin.engine.spark;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.IOException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.BitSet;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.UUID;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.LinkedBlockingQueue;
-
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+import com.google.common.primitives.UnsignedBytes;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
@@ -62,14 +48,9 @@ import org.apache.kylin.cube.CubeUpdate;
import org.apache.kylin.cube.cuboid.Cuboid;
import org.apache.kylin.cube.cuboid.CuboidScheduler;
import org.apache.kylin.cube.inmemcubing.AbstractInMemCubeBuilder;
-import org.apache.kylin.cube.inmemcubing.InMemCubeBuilder;
+import org.apache.kylin.cube.inmemcubing.DoggedCubeBuilder;
import org.apache.kylin.cube.kv.RowConstants;
-import org.apache.kylin.cube.model.CubeDesc;
-import org.apache.kylin.cube.model.CubeJoinedFlatTableDesc;
-import org.apache.kylin.cube.model.DimensionDesc;
-import org.apache.kylin.cube.model.HBaseColumnDesc;
-import org.apache.kylin.cube.model.HBaseColumnFamilyDesc;
-import org.apache.kylin.cube.model.RowKeyDesc;
+import org.apache.kylin.cube.model.*;
import org.apache.kylin.cube.util.CubingUtils;
import org.apache.kylin.dict.Dictionary;
import org.apache.kylin.dict.DictionaryGenerator;
@@ -92,23 +73,19 @@ import org.apache.spark.SparkFiles;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
-import org.apache.spark.api.java.function.FlatMapFunction;
-import org.apache.spark.api.java.function.Function;
-import org.apache.spark.api.java.function.Function2;
-import org.apache.spark.api.java.function.PairFlatMapFunction;
-import org.apache.spark.api.java.function.PairFunction;
+import org.apache.spark.api.java.function.*;
import org.apache.spark.sql.DataFrame;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.hive.HiveContext;
-
import scala.Tuple2;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
-import com.google.common.primitives.UnsignedBytes;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.*;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
/**
*/
@@ -349,10 +326,9 @@ public class SparkCubing extends AbstractSparkApplication {
LinkedBlockingQueue<List<String>> blockingQueue = new LinkedBlockingQueue();
System.out.println("load properties finished");
- AbstractInMemCubeBuilder inMemCubeBuilder = new InMemCubeBuilder(cubeInstance.getDescriptor(), dictionaryMap);
- inMemCubeBuilder.setReserveMemoryMB(2400);
+ AbstractInMemCubeBuilder inMemCubeBuilder = new DoggedCubeBuilder(cubeInstance.getDescriptor(), dictionaryMap);
final SparkCuboidWriter sparkCuboidWriter = new BufferedCuboidWriter(new DefaultTupleConverter(cubeDesc, columnLengthMap));
- final Future<?> future = Executors.newCachedThreadPool().submit(inMemCubeBuilder.buildAsRunnable(blockingQueue, sparkCuboidWriter));
+ Executors.newCachedThreadPool().submit(inMemCubeBuilder.buildAsRunnable(blockingQueue, sparkCuboidWriter));
try {
while (listIterator.hasNext()) {
for (List<String> row : listIterator.next()) {
@@ -360,7 +336,6 @@ public class SparkCubing extends AbstractSparkApplication {
}
}
blockingQueue.put(Collections.<String>emptyList());
- future.get();
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -462,14 +437,7 @@ public class SparkCubing extends AbstractSparkApplication {
}
aggs.reset();
for (byte[] v : list) {
- try {
- codec.decode(ByteBuffer.wrap(v), input);
- } catch (BufferUnderflowException e) {
- e.printStackTrace();
- System.out.println("buffer under flow v.length:" + v.length);
- System.out.println("value:" + Arrays.toString(v));
- throw e;
- }
+ codec.decode(ByteBuffer.wrap(v), input);
aggs.aggregate(input);
}
aggs.collectStates(result);
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/db6febc8/engine-spark/src/main/java/org/apache/kylin/engine/spark/cube/BufferedCuboidWriter.java
----------------------------------------------------------------------
diff --git a/engine-spark/src/main/java/org/apache/kylin/engine/spark/cube/BufferedCuboidWriter.java b/engine-spark/src/main/java/org/apache/kylin/engine/spark/cube/BufferedCuboidWriter.java
index 6656e9b..4ab8975 100644
--- a/engine-spark/src/main/java/org/apache/kylin/engine/spark/cube/BufferedCuboidWriter.java
+++ b/engine-spark/src/main/java/org/apache/kylin/engine/spark/cube/BufferedCuboidWriter.java
@@ -33,7 +33,6 @@ import java.util.concurrent.LinkedBlockingQueue;
public class BufferedCuboidWriter implements SparkCuboidWriter {
private final LinkedBlockingQueue<Tuple2<byte[], byte[]>> blockingQueue;
- private final ExecutorService executorService = Executors.newSingleThreadExecutor();
private final TupleConverter tupleConverter;
public BufferedCuboidWriter(TupleConverter tupleConverter) {
@@ -41,71 +40,27 @@ public class BufferedCuboidWriter implements SparkCuboidWriter {
this.tupleConverter = tupleConverter;
}
- volatile Throwable error;
-
- class RunnableWrapper implements Runnable {
-
- private final Runnable runnable;
-
- RunnableWrapper(Runnable runnable) {
- this.runnable = runnable;
- }
-
- @Override
- public void run() {
- try {
- runnable.run();
- } catch (Throwable e) {
- e.printStackTrace();
- error = e;
- }
- }
- }
-
- private void checkError() {
- if (error != null) {
- if (error instanceof RuntimeException) {
- throw (RuntimeException) error;
- } else {
- throw new RuntimeException(error);
- }
- }
- }
-
@Override
public void write(final long cuboidId, final GTRecord record) throws IOException {
- checkError();
- executorService.submit(new RunnableWrapper(new Runnable() {
- @Override
- public void run() {
- try {
- blockingQueue.put(tupleConverter.convert(cuboidId, record));
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- }));
+ try {
+ blockingQueue.put(tupleConverter.convert(cuboidId, record));
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
}
@Override
public void flush() {
- checkError();
}
@Override
public void close() {
- checkError();
- executorService.submit(new RunnableWrapper(new Runnable() {
- @Override
- public void run() {
- try {
- blockingQueue.put(new Tuple2(new byte[0], new byte[0]));
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- }));
- executorService.shutdown();
+ try {
+ blockingQueue.put(new Tuple2(new byte[0], new byte[0]));
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } finally {
+ }
}
@Override