jackylk opened a new pull request #3672: [WIP] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672 ### Why is this PR needed? ### What changes were proposed in this PR? ### Does this PR introduce any user interface change? - No - Yes. (please explain the change and update document) ### Is any new testcase added? - No - Yes ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
CarbonDataQA1 commented on issue #3672: [WIP] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600197350 Build Failed with Spark 2.4.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.4/785/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [WIP] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600198179 Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/2491/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [WIP] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600415706 Build Failed with Spark 2.4.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.4/788/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [WIP] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600415950 Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/2494/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [WIP] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600416849 Build Failed with Spark 2.4.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.4/789/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [WIP] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600425394 Build Failed with Spark 2.4.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.4/790/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [WIP] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600425720 Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/2495/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600475515 Build Failed with Spark 2.4.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.4/793/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600481546 Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/2498/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600512373 Build Failed with Spark 2.4.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.4/796/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600512896 Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/2501/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600536014 Build Failed with Spark 2.4.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.4/797/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600536402 Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/2502/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600657042 Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/2504/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
CarbonDataQA1 commented on issue #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#issuecomment-600658646 Build Success with Spark 2.4.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.4/799/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
ajantha-bhat commented on a change in pull request #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#discussion_r394867202 ########## File path: core/src/main/java/org/apache/carbondata/core/indexstore/blockletindex/BlockletDataRefNode.java ########## @@ -133,35 +139,107 @@ public short blockletIndex() { } @Override - public DimensionRawColumnChunk[] readDimensionChunks(FileReader fileReader, int[][] blockIndexes) + public DimensionRawColumnChunk[] readDimensionChunks(FileReader fileReader, int[][] columnIndexes) throws IOException { - DimensionColumnChunkReader dimensionChunksReader = getDimensionColumnChunkReader(fileReader); - return dimensionChunksReader.readRawDimensionChunks(fileReader, blockIndexes); + TableBlockInfo blockInfo = blockInfos.get(index); + if (ColumnChunkCache.isEnabledForTable(tableId)) { + DimensionRawColumnChunk[] chunks = new DimensionRawColumnChunk[ + blockInfo.getDetailInfo().getBlockletInfo().getDimensionChunkOffsets().size()]; + for (int[] columnIndex : columnIndexes) { + int columnIndexStart = columnIndex[0]; + int columnIndexEnd = columnIndex[1]; + for (int j = columnIndexStart; j <= columnIndexEnd; j++) { + ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey( + blockInfo.getFilePath(), + blockInfo.getDetailInfo().getBlockletInfo().getDimensionChunkOffsets().get(j)); + Optional<AbstractRawColumnChunk> chunkOp = ColumnChunkCache.get(tableId, key); + if (chunkOp.isPresent()) { + chunks[j] = (DimensionRawColumnChunk) chunkOp.get(); + } else { + chunks[j] = readDimensionChunkWithoutCache(fileReader, j); + ColumnChunkCache.put(tableId, key, chunks[j]); + } + } + } + return chunks; + } else { + DimensionColumnChunkReader dimensionChunksReader = getDimensionColumnChunkReader(fileReader); + return dimensionChunksReader.readRawDimensionChunks(fileReader, columnIndexes); + } } @Override public DimensionRawColumnChunk readDimensionChunk(FileReader fileReader, int columnIndex) throws IOException { - DimensionColumnChunkReader dimensionChunksReader = getDimensionColumnChunkReader(fileReader); - return dimensionChunksReader.readRawDimensionChunk(fileReader, columnIndex); + TableBlockInfo blockInfo = blockInfos.get(index); + ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey( + blockInfo.getFilePath(), + blockInfo.getDetailInfo().getBlockletInfo().getDimensionChunkOffsets().get(columnIndex)); + Optional<AbstractRawColumnChunk> columnChunkOp = ColumnChunkCache.get(tableId, key); + if (columnChunkOp.isPresent()) { + return (DimensionRawColumnChunk) columnChunkOp.get(); + } + DimensionRawColumnChunk chunk = readDimensionChunkWithoutCache(fileReader, columnIndex); + ColumnChunkCache.put(tableId, key, chunk); + return chunk; + } + + private DimensionRawColumnChunk readDimensionChunkWithoutCache( + FileReader fileReader, int columnIndex) throws IOException { + DimensionColumnChunkReader reader = getDimensionColumnChunkReader(fileReader); + return reader.readRawDimensionChunk(fileReader, columnIndex); + } + + private MeasureRawColumnChunk readMeasureChunkWithoutCache( + FileReader fileReader, int columnIndex) throws IOException { + MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader); + return measureColumnChunkReader.readRawMeasureChunk(fileReader, columnIndex); } @Override - public MeasureRawColumnChunk[] readMeasureChunks(FileReader fileReader, int[][] columnIndexRange) + public MeasureRawColumnChunk[] readMeasureChunks(FileReader fileReader, int[][] columnIndexes) throws IOException { - MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader); - MeasureRawColumnChunk[] measureRawColumnChunks = - measureColumnChunkReader.readRawMeasureChunks(fileReader, columnIndexRange); - return measureRawColumnChunks; + TableBlockInfo blockInfo = blockInfos.get(index); + if (ColumnChunkCache.isEnabledForTable(tableId)) { + MeasureRawColumnChunk[] chunks = new MeasureRawColumnChunk[ + blockInfo.getDetailInfo().getBlockletInfo().getMeasureChunkOffsets().size()]; + for (int[] columnIndex : columnIndexes) { + int columnIndexStart = columnIndex[0]; + int columnIndexEnd = columnIndex[1]; + for (int j = columnIndexStart; j <= columnIndexEnd; j++) { + ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey( + blockInfo.getFilePath(), + blockInfo.getDetailInfo().getBlockletInfo().getMeasureChunkOffsets().get(j)); + Optional<AbstractRawColumnChunk> chunkOp = ColumnChunkCache.get(tableId, key); + if (chunkOp.isPresent()) { + chunks[j] = (MeasureRawColumnChunk) chunkOp.get(); + } else { + chunks[j] = readMeasureChunkWithoutCache(fileReader, j); + ColumnChunkCache.put(tableId, key, chunks[j]); + } + } + } + return chunks; + } else { + MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader); + return measureColumnChunkReader.readRawMeasureChunks(fileReader, columnIndexes); + } } @Override public MeasureRawColumnChunk readMeasureChunk(FileReader fileReader, int columnIndex) throws IOException { - MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader); - MeasureRawColumnChunk measureRawColumnChunk = - measureColumnChunkReader.readRawMeasureChunk(fileReader, columnIndex); - return measureRawColumnChunk; + TableBlockInfo blockInfo = blockInfos.get(index); + ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey( + blockInfo.getFilePath(), Review comment: If the task distribution is '`blocklet`' instead of `block` to get the splits in the driver. Two splits may have same block but different blocklet id. In that cache will be overwritten for the last blokclet. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
ajantha-bhat commented on a change in pull request #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#discussion_r394868505 ########## File path: core/src/main/java/org/apache/carbondata/core/indexstore/blockletindex/BlockletDataRefNode.java ########## @@ -133,35 +139,107 @@ public short blockletIndex() { } @Override - public DimensionRawColumnChunk[] readDimensionChunks(FileReader fileReader, int[][] blockIndexes) + public DimensionRawColumnChunk[] readDimensionChunks(FileReader fileReader, int[][] columnIndexes) throws IOException { - DimensionColumnChunkReader dimensionChunksReader = getDimensionColumnChunkReader(fileReader); - return dimensionChunksReader.readRawDimensionChunks(fileReader, blockIndexes); + TableBlockInfo blockInfo = blockInfos.get(index); + if (ColumnChunkCache.isEnabledForTable(tableId)) { + DimensionRawColumnChunk[] chunks = new DimensionRawColumnChunk[ + blockInfo.getDetailInfo().getBlockletInfo().getDimensionChunkOffsets().size()]; + for (int[] columnIndex : columnIndexes) { + int columnIndexStart = columnIndex[0]; + int columnIndexEnd = columnIndex[1]; + for (int j = columnIndexStart; j <= columnIndexEnd; j++) { + ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey( + blockInfo.getFilePath(), + blockInfo.getDetailInfo().getBlockletInfo().getDimensionChunkOffsets().get(j)); + Optional<AbstractRawColumnChunk> chunkOp = ColumnChunkCache.get(tableId, key); + if (chunkOp.isPresent()) { + chunks[j] = (DimensionRawColumnChunk) chunkOp.get(); + } else { + chunks[j] = readDimensionChunkWithoutCache(fileReader, j); + ColumnChunkCache.put(tableId, key, chunks[j]); + } + } + } + return chunks; + } else { + DimensionColumnChunkReader dimensionChunksReader = getDimensionColumnChunkReader(fileReader); + return dimensionChunksReader.readRawDimensionChunks(fileReader, columnIndexes); + } } @Override public DimensionRawColumnChunk readDimensionChunk(FileReader fileReader, int columnIndex) throws IOException { - DimensionColumnChunkReader dimensionChunksReader = getDimensionColumnChunkReader(fileReader); - return dimensionChunksReader.readRawDimensionChunk(fileReader, columnIndex); + TableBlockInfo blockInfo = blockInfos.get(index); + ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey( + blockInfo.getFilePath(), + blockInfo.getDetailInfo().getBlockletInfo().getDimensionChunkOffsets().get(columnIndex)); + Optional<AbstractRawColumnChunk> columnChunkOp = ColumnChunkCache.get(tableId, key); + if (columnChunkOp.isPresent()) { + return (DimensionRawColumnChunk) columnChunkOp.get(); + } + DimensionRawColumnChunk chunk = readDimensionChunkWithoutCache(fileReader, columnIndex); + ColumnChunkCache.put(tableId, key, chunk); + return chunk; + } + + private DimensionRawColumnChunk readDimensionChunkWithoutCache( + FileReader fileReader, int columnIndex) throws IOException { + DimensionColumnChunkReader reader = getDimensionColumnChunkReader(fileReader); + return reader.readRawDimensionChunk(fileReader, columnIndex); + } + + private MeasureRawColumnChunk readMeasureChunkWithoutCache( + FileReader fileReader, int columnIndex) throws IOException { + MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader); + return measureColumnChunkReader.readRawMeasureChunk(fileReader, columnIndex); } @Override - public MeasureRawColumnChunk[] readMeasureChunks(FileReader fileReader, int[][] columnIndexRange) + public MeasureRawColumnChunk[] readMeasureChunks(FileReader fileReader, int[][] columnIndexes) throws IOException { - MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader); - MeasureRawColumnChunk[] measureRawColumnChunks = - measureColumnChunkReader.readRawMeasureChunks(fileReader, columnIndexRange); - return measureRawColumnChunks; + TableBlockInfo blockInfo = blockInfos.get(index); + if (ColumnChunkCache.isEnabledForTable(tableId)) { + MeasureRawColumnChunk[] chunks = new MeasureRawColumnChunk[ + blockInfo.getDetailInfo().getBlockletInfo().getMeasureChunkOffsets().size()]; + for (int[] columnIndex : columnIndexes) { + int columnIndexStart = columnIndex[0]; + int columnIndexEnd = columnIndex[1]; + for (int j = columnIndexStart; j <= columnIndexEnd; j++) { + ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey( + blockInfo.getFilePath(), + blockInfo.getDetailInfo().getBlockletInfo().getMeasureChunkOffsets().get(j)); + Optional<AbstractRawColumnChunk> chunkOp = ColumnChunkCache.get(tableId, key); + if (chunkOp.isPresent()) { + chunks[j] = (MeasureRawColumnChunk) chunkOp.get(); + } else { + chunks[j] = readMeasureChunkWithoutCache(fileReader, j); + ColumnChunkCache.put(tableId, key, chunks[j]); + } + } + } + return chunks; + } else { + MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader); + return measureColumnChunkReader.readRawMeasureChunks(fileReader, columnIndexes); + } } @Override public MeasureRawColumnChunk readMeasureChunk(FileReader fileReader, int columnIndex) throws IOException { - MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader); - MeasureRawColumnChunk measureRawColumnChunk = - measureColumnChunkReader.readRawMeasureChunk(fileReader, columnIndex); - return measureRawColumnChunk; + TableBlockInfo blockInfo = blockInfos.get(index); + ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey( + blockInfo.getFilePath(), Review comment: I mean we cannot use blockInfo.getFilePath() as a cache key in case of `bocklet` distribution ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
ajantha-bhat commented on a change in pull request #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#discussion_r394871039 ########## File path: core/src/main/java/org/apache/carbondata/core/indexstore/columncache/ColumnChunkCache.java ########## @@ -0,0 +1,168 @@ +/* + * 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.carbondata.core.indexstore.columncache; + +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; + +import org.apache.carbondata.common.logging.LogServiceFactory; +import org.apache.carbondata.core.datastore.chunk.AbstractRawColumnChunk; +import org.apache.carbondata.core.metadata.schema.table.CarbonTable; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; +import org.apache.log4j.Logger; + +/** + * Column Chunk level data cache for table which is enabled for this feature. + */ +public class ColumnChunkCache { + + private static Logger LOG = + LogServiceFactory.getLogService(ColumnChunkCache.class.getCanonicalName()); + + // A global cache for all tables which is enabled for this feature. + // The cached object is raw column chunks including raw binary data, so we can + // leverage this cache to avoid IO read from underlying storage. + private static Map<String, Cache<CacheKey, AbstractRawColumnChunk>> cacheForEachTable = + new ConcurrentHashMap<>(); + + /** + * Enable or disable the column chunk cache for specified table, based on the whether the + * corresponding table property is set + */ + public static void setCacheForTable(CarbonTable carbonTable) { + String tableId = carbonTable.getTableId(); + boolean shouldEnable = carbonTable.isColumnCacheEnabled(); + boolean alreadyEnabled = cacheForEachTable.containsKey(tableId); + if (alreadyEnabled && !shouldEnable) { + cacheForEachTable.get(tableId).invalidateAll(); + cacheForEachTable.remove(tableId); + } else if (!alreadyEnabled && shouldEnable) { + Cache<CacheKey, AbstractRawColumnChunk> cache = createCacheForTable(tableId); + cacheForEachTable.put(tableId, cache); + } + } + + private static Cache<CacheKey, AbstractRawColumnChunk> createCacheForTable(String tableId) { + return CacheBuilder.newBuilder() + // expire after 10 minutes after last accessed + .expireAfterAccess(10, TimeUnit.MINUTES) Review comment: On what basis we can fix it to 10 minutes ? It should be agian configurable? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
In reply to this post by GitBox
ajantha-bhat commented on a change in pull request #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#discussion_r394872157 ########## File path: core/src/main/java/org/apache/carbondata/core/indexstore/columncache/ColumnChunkCache.java ########## @@ -0,0 +1,168 @@ +/* + * 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.carbondata.core.indexstore.columncache; + +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; + +import org.apache.carbondata.common.logging.LogServiceFactory; +import org.apache.carbondata.core.datastore.chunk.AbstractRawColumnChunk; +import org.apache.carbondata.core.metadata.schema.table.CarbonTable; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; +import org.apache.log4j.Logger; + +/** + * Column Chunk level data cache for table which is enabled for this feature. + */ +public class ColumnChunkCache { + + private static Logger LOG = + LogServiceFactory.getLogService(ColumnChunkCache.class.getCanonicalName()); + + // A global cache for all tables which is enabled for this feature. + // The cached object is raw column chunks including raw binary data, so we can + // leverage this cache to avoid IO read from underlying storage. + private static Map<String, Cache<CacheKey, AbstractRawColumnChunk>> cacheForEachTable = + new ConcurrentHashMap<>(); + + /** + * Enable or disable the column chunk cache for specified table, based on the whether the + * corresponding table property is set + */ + public static void setCacheForTable(CarbonTable carbonTable) { + String tableId = carbonTable.getTableId(); + boolean shouldEnable = carbonTable.isColumnCacheEnabled(); + boolean alreadyEnabled = cacheForEachTable.containsKey(tableId); + if (alreadyEnabled && !shouldEnable) { + cacheForEachTable.get(tableId).invalidateAll(); + cacheForEachTable.remove(tableId); + } else if (!alreadyEnabled && shouldEnable) { + Cache<CacheKey, AbstractRawColumnChunk> cache = createCacheForTable(tableId); + cacheForEachTable.put(tableId, cache); + } + } + + private static Cache<CacheKey, AbstractRawColumnChunk> createCacheForTable(String tableId) { + return CacheBuilder.newBuilder() + // expire after 10 minutes after last accessed + .expireAfterAccess(10, TimeUnit.MINUTES) + // max number of entries + .maximumSize(1000) + .removalListener(new RemovalListener<CacheKey, AbstractRawColumnChunk>() { + @Override + public void onRemoval(RemovalNotification<CacheKey, AbstractRawColumnChunk> entry) { + AbstractRawColumnChunk chunk = entry.getValue(); + if (chunk != null) { + chunk.setCached(false); + chunk.freeMemory(); + if (LOG.isInfoEnabled()) { + CacheKey key = entry.getKey(); + LOG.info(String.format("column cache removed: key %s", key.toString())); + } + } + } + }).build(); + } + + /** + * Return true if column chunk cache is enabled for specified table + */ + public static boolean isEnabledForTable(String tableId) { + return tableId != null && cacheForEachTable.containsKey(tableId); + } + + /** + * Put column chunk into the cache + */ + public static void put(String tableId, CacheKey key, AbstractRawColumnChunk chunk) { + if (isEnabledForTable(tableId)) { + cacheForEachTable.get(tableId).put(key, chunk); Review comment: Concurrent query performance will be impacted with this as this is a system-level cache. concurrent hash map will have a lock. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
Free forum by Nabble | Edit this page |