目录
BytesToBytesMap
重要成员属性
longArray
是一个KV pair:
存放key指针(K)和key的hashcode(V)。
数据组织形式
页内的数据组织形式
BytesToBytesMap的内部类MapIterator实现了Iterator接口:
next()方法中,先判断如果该页没有records,则跳转到下一页。如果当前页不为空,则返回Location对象。
Location中记录了key和value的Offset和size等信息。
@Override
public Location next() {
if (recordsInPage == 0) {
advanceToNextPage();
}
numRecords--;
if (currentPage != null) {
int totalLength = UnsafeAlignedOffset.getSize(pageBaseObject, offsetInPage);
loc.with(currentPage, offsetInPage);
// [total size] [key size] [key] [value] [pointer to next]
offsetInPage += UnsafeAlignedOffset.getUaoSize() + totalLength + 8;
recordsInPage --;
return loc;
} else {
assert(reader != null);
if (!reader.hasNext()) {
advanceToNextPage();
}
try {
reader.loadNext();
} catch (IOException e) {
try {
reader.close();
} catch(IOException e2) {
logger.error("Error while closing spill reader", e2);
}
// Scala iterator does not handle exception
Platform.throwException(e);
}
loc.with(reader.getBaseObject(), reader.getBaseOffset(), reader.getRecordLength());
return loc;
}
}
从advanceToNextPage()中,可以看到,当跳转到下一页时,currentPage是由一个baseObject和offset组成。
baseObject的初始偏移量位置,记录了records数量,同时占用了uaoSize大小的内存空间。
当currentPage不为空时,将会更新location中描述当前 KV pair 的偏移量和size。loc.with(currentPage, offsetInPage)中可以窥见:
private void updateAd