Replace nextPosToSearchFrom with lowestPossiblyFreeChunk semantically, that allows to avoid searching free chunks though a full tier, when segment is tiered, again and again. Also, make chunk block reallocation in innerDefaultReplaceValue() and putValueDeletedEntry() check it doesn't overflow actualChunksPerSegmentTier

This commit is contained in:
leventov
2015-12-07 07:20:47 +03:00
parent 82988e7435
commit 2f58bfb399
15 changed files with 125 additions and 138 deletions
@@ -165,19 +165,14 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
"entry takes " + newSizeInChunks + " chunks, " +
m.maxChunksPerEntry + " is maximum.");
}
if (s.freeList.isRangeClear(pos + entrySizeInChunks, pos + newSizeInChunks)) {
s.freeList.setRange(pos + entrySizeInChunks, pos + newSizeInChunks);
if (s.realloc(pos, entrySizeInChunks, newSizeInChunks)) {
break newValueDoesNotFit;
}
relocation(newValue, newSizeOfEverythingBeforeValue);
return;
} else if (newSizeInChunks < entrySizeInChunks) {
// Freeing extra chunks
s.freeList.clearRange(pos + newSizeInChunks, pos + entrySizeInChunks);
// Do NOT reset nextPosToSearchFrom, because if value
// once was larger it could easily became larger again,
// But if these chunks will be taken by that time,
// this entry will need to be relocated.
s.free(pos + newSizeInChunks, entrySizeInChunks - newSizeInChunks);
}
// new size != old size => size is not constant => size is actually written =>
// to prevent (at least) this execution:
@@ -46,9 +46,7 @@ public abstract class QueryMapEntryStages<K, V> extends MapEntryStages<K, V> {
} else {
newSizeInChunks = entrySizeInChunks;
}
if (pos + newSizeInChunks < s.freeList.logicalSize() &&
s.freeList.isRangeClear(pos, pos + newSizeInChunks)) {
s.freeList.setRange(pos, pos + newSizeInChunks);
if (s.realloc(pos, 0, newSizeInChunks)) {
s.innerWriteLock.lock();
allocatedChunks.incrementSegmentEntriesIfNeeded();
if (newValueSizeIsDifferent) {