totalNumElements = 0;
this.aggregators = aggs;
this.env = env;
final int estValueSize = aggregators.getEstimatedByteSize();
final TenantCache tenantCache = GlobalCache.getTenantCache(env, tenantId);
// Compute Map initial map
final Configuration conf = env.getConfiguration();
final long maxCacheSizeConf = conf.getLong(GROUPBY_MAX_CACHE_SIZE_ATTRIB, DEFAULT_GROUPBY_MAX_CACHE_MAX);
final int numSpillFilesConf = conf.getInt(GROUPBY_SPILL_FILES_ATTRIB, DEFAULT_GROUPBY_SPILL_FILES);
final int maxSizeNum = (int)(maxCacheSizeConf / estValueSize);
final int minSizeNum = (SPGBY_CACHE_MIN_SIZE / estValueSize);
// use upper and lower bounds for the cache size
final int maxCacheSize = Math.max(minSizeNum, Math.min(maxSizeNum, estSizeNum));
final long estSize = GroupedAggregateRegionObserver.sizeOfUnorderedGroupByMap(maxCacheSize, estValueSize);
try {
this.chunk = tenantCache.getMemoryManager().allocate(estSize);
} catch (InsufficientMemoryException ime) {
logger.error("Requested Map size exceeds memory limit, please decrease max size via config paramter: "
+ GROUPBY_MAX_CACHE_SIZE_ATTRIB);
throw ime;
}