KYLIN-2322 disable subtree cache Signed-off-by: Li Yang <liy...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/487f2d99 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/487f2d99 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/487f2d99 Branch: refs/heads/sparkcubing-rebase Commit: 487f2d99dfe76566c5ff366e316bc531a694050c Parents: e62d878 Author: xiefan46 <958034...@qq.com> Authored: Tue Jan 3 16:13:29 2017 +0800 Committer: Li Yang <liy...@apache.org> Committed: Wed Jan 4 13:43:48 2017 +0800 ---------------------------------------------------------------------- .../org/apache/kylin/dict/CacheDictionary.java | 2 +- .../apache/kylin/dict/TrieDictionaryForest.java | 31 ++++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/487f2d99/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java ---------------------------------------------------------------------- diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java b/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java index 575358e..1b3bfa1 100644 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java @@ -30,7 +30,7 @@ import java.util.concurrent.ConcurrentHashMap; abstract public class CacheDictionary<T> extends Dictionary<T> { private static final long serialVersionUID = 1L; - transient protected boolean enableValueCache = true; + transient protected boolean enableValueCache = false; transient private SoftReference<Map> valueToIdCache; http://git-wip-us.apache.org/repos/asf/kylin/blob/487f2d99/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java ---------------------------------------------------------------------- diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java index c655854..065c3df 100755 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; - import org.apache.kylin.common.util.ByteArray; import org.apache.kylin.common.util.Bytes; import org.apache.kylin.common.util.BytesUtil; @@ -57,13 +56,17 @@ public class TrieDictionaryForest<T> extends CacheDictionary<T> { public TrieDictionaryForest(ArrayList<TrieDictionary<T>> trees, ArrayList<ByteArray> valueDivide, // ArrayList<Integer> accuOffset, BytesConverter<T> bytesConverter, int baseId) { + init(trees, valueDivide, accuOffset, bytesConverter, baseId); + } + + private void init(ArrayList<TrieDictionary<T>> trees, ArrayList<ByteArray> valueDivide, ArrayList<Integer> accuOffset, BytesConverter<T> bytesConverter, int baseId) { this.trees = trees; this.valueDivide = valueDivide; this.accuOffset = accuOffset; this.bytesConvert = bytesConverter; this.baseId = baseId; initMaxValue(); - enableCache(); + initForestCache(); } @Override @@ -100,7 +103,6 @@ public class TrieDictionaryForest<T> extends CacheDictionary<T> { return maxValue; } - @Override protected int getIdFromValueBytesImpl(byte[] value, int offset, int len, int roundingFlag) throws IllegalArgumentException { @@ -140,8 +142,6 @@ public class TrieDictionaryForest<T> extends CacheDictionary<T> { return id; } - - @Override protected int getValueBytesFromIdImpl(int id, byte[] returnValue, int offset) throws IllegalArgumentException { int index = (trees.size() == 1) ? 0 : findIndexById(id); @@ -228,19 +228,20 @@ public class TrieDictionaryForest<T> extends CacheDictionary<T> { try { @SuppressWarnings("unused") int headSize = in.readInt(); - this.baseId = in.readInt(); + int baseId = in.readInt(); String converterName = in.readUTF(); + BytesConverter<T> bytesConverter = null; if (converterName.isEmpty() == false) - this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).newInstance(); + bytesConverter = ClassUtil.forName(converterName, BytesConverter.class).newInstance(); //init accuOffset int accuSize = in.readInt(); - this.accuOffset = new ArrayList<>(); + ArrayList<Integer> accuOffset = new ArrayList<>(); for (int i = 0; i < accuSize; i++) { accuOffset.add(in.readInt()); } //init valueDivide int valueDivideSize = in.readInt(); - this.valueDivide = new ArrayList<>(); + ArrayList<ByteArray> valueDivide = new ArrayList<>(); for (int i = 0; i < valueDivideSize; i++) { int length = in.readInt(); byte[] buffer = new byte[length]; @@ -248,14 +249,13 @@ public class TrieDictionaryForest<T> extends CacheDictionary<T> { valueDivide.add(new ByteArray(buffer, 0, buffer.length)); } int treeSize = in.readInt(); - this.trees = new ArrayList<>(); + ArrayList<TrieDictionary<T>> trees = new ArrayList<>(); for (int i = 0; i < treeSize; i++) { TrieDictionary<T> dict = new TrieDictionary<>(); dict.readFields(in); trees.add(dict); } - initMaxValue(); - enableCache(); + init(trees, valueDivide, accuOffset, bytesConverter, baseId); } catch (Exception e) { if (e instanceof RuntimeException) throw (RuntimeException) e; @@ -368,4 +368,11 @@ public class TrieDictionaryForest<T> extends CacheDictionary<T> { } } + private void initForestCache() { + enableCache(); + for (TrieDictionary<T> tree : trees) { //disable duplicate cache + tree.disableCache(); + } + } + }