Skip to content

Commit

Permalink
[HOTFIX] Implementing getMemorySize in BlockletDataMapIndexWrapper
Browse files Browse the repository at this point in the history
This closes #2330
  • Loading branch information
dhatchayani authored and ravipesala committed May 22, 2018
1 parent 9aa3a8c commit 16ed99a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public BlockletDataMapIndexWrapper get(TableBlockIndexUniqueIdentifier identifie
try {
SegmentIndexFileStore indexFileStore = new SegmentIndexFileStore();
Set<String> filesRead = new HashSet<>();
long memorySize = 0L;
String segmentFilePath = identifier.getIndexFilePath();
Map<String, BlockMetaInfo> carbonDataFileBlockMetaInfoMapping = BlockletDataMapUtil
.createCarbonDataFileBlockMetaInfoMapping(segmentFilePath);
Expand All @@ -89,7 +88,6 @@ public BlockletDataMapIndexWrapper get(TableBlockIndexUniqueIdentifier identifie
carbonDataFileBlockMetaInfoMapping);
BlockletDataMap blockletDataMap =
loadAndGetDataMap(identifier, indexFileStore, blockMetaInfoMap);
memorySize += blockletDataMap.getMemorySize();
dataMaps.add(blockletDataMap);
blockletDataMapIndexWrapper = new BlockletDataMapIndexWrapper(dataMaps);
} else {
Expand All @@ -103,13 +101,12 @@ public BlockletDataMapIndexWrapper get(TableBlockIndexUniqueIdentifier identifie
carbonDataFileBlockMetaInfoMapping);
BlockletDataMap blockletDataMap =
loadAndGetDataMap(blockIndexUniqueIdentifier, indexFileStore, blockMetaInfoMap);
memorySize += blockletDataMap.getMemorySize();
dataMaps.add(blockletDataMap);
}
blockletDataMapIndexWrapper = new BlockletDataMapIndexWrapper(dataMaps);
}
lruCache.put(identifier.getUniqueTableSegmentIdentifier(), blockletDataMapIndexWrapper,
memorySize);
blockletDataMapIndexWrapper.getMemorySize());
} catch (Throwable e) {
// clear all the memory used by datamaps loaded
for (DataMap dataMap : dataMaps) {
Expand Down Expand Up @@ -189,7 +186,6 @@ public void put(TableBlockIndexUniqueIdentifier tableBlockIndexUniqueIdentifier,
if (lock == null) {
lock = addAndGetSegmentLock(uniqueTableSegmentIdentifier);
}
long memorySize = 0L;
// As dataMap will use unsafe memory, it is not recommended to overwrite an existing entry
// as in that case clearing unsafe memory need to be taken card. If at all datamap entry
// in the cache need to be overwritten then use the invalidate interface
Expand All @@ -201,10 +197,9 @@ public void put(TableBlockIndexUniqueIdentifier tableBlockIndexUniqueIdentifier,
try {
for (BlockletDataMap blockletDataMap: dataMaps) {
blockletDataMap.convertToUnsafeDMStore();
memorySize += blockletDataMap.getMemorySize();
}
lruCache.put(tableBlockIndexUniqueIdentifier.getUniqueTableSegmentIdentifier(), wrapper,
memorySize);
wrapper.getMemorySize());
} catch (Throwable e) {
// clear all the memory acquired by data map in case of any failure
for (DataMap blockletDataMap : dataMaps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ public class BlockletDataMapIndexWrapper implements Cacheable, Serializable {

private List<BlockletDataMap> dataMaps;

// size of the wrapper. basically the total size of the datamaps this wrapper is holding
private long wrapperSize;

public BlockletDataMapIndexWrapper(List<BlockletDataMap> dataMaps) {
this.dataMaps = dataMaps;
this.wrapperSize = 0L;
// add the size of each and every datamap in this wrapper
for (BlockletDataMap dataMap : dataMaps) {
this.wrapperSize += dataMap.getMemorySize();
}
}

@Override public long getFileTimeStamp() {
Expand All @@ -43,7 +51,7 @@ public BlockletDataMapIndexWrapper(List<BlockletDataMap> dataMaps) {
}

@Override public long getMemorySize() {
return 0;
return wrapperSize;
}

public List<BlockletDataMap> getDataMaps() {
Expand Down

0 comments on commit 16ed99a

Please sign in to comment.