Close wrapped value after each iteration in MapSegmentIteration

This commit is contained in:
leventov
2016-12-10 21:03:20 -06:00
parent e0b534af23
commit fafc50f89d
2 changed files with 11 additions and 16 deletions
@@ -137,6 +137,7 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
break;
}
} finally {
hookAfterEachIteration();
// if doReplaceValue() -> relocation() -> alloc() -> nextTier()
// was called, restore the tier we were iterating over
if (s.tier != currentTier) {
@@ -170,6 +171,9 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
return interrupted;
}
public void hookAfterEachIteration() {
}
@Override
public void forEachSegmentEntry(Consumer<? super E> action) {
forEachSegmentEntryWhile(e -> {
@@ -21,24 +21,26 @@ import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.stage.iter.HashSegmentIteration;
import net.openhft.chronicle.map.MapEntry;
import net.openhft.chronicle.map.impl.IterationContext;
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceDataHolder;
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
import net.openhft.chronicle.map.impl.stage.map.WrappedValueInstanceDataHolderAccess;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Staged
public abstract class MapSegmentIteration<K, V, R> extends HashSegmentIteration<K, MapEntry<K, V>>
implements MapEntry<K, V>, IterationContext<K, V, R> {
@StageRef MapEntryStages<K, V> entry;
@StageRef WrappedValueInstanceDataHolder<V> wrappedValueInstanceDataHolder;
@StageRef WrappedValueInstanceDataHolderAccess<K, V, ?> wrappedValueInstanceDataHolderAccess;
@Override
public void hookAfterEachIteration() {
wrappedValueInstanceDataHolder.closeValue();
}
@Override
public void doReplaceValue(Data<V> newValue) {
checkOnEachPublicOperation.checkOnEachPublicOperation();
@@ -54,15 +56,4 @@ public abstract class MapSegmentIteration<K, V, R> extends HashSegmentIteration<
public WrappedValueInstanceDataHolderAccess<K, V, ?> context() {
return wrappedValueInstanceDataHolderAccess;
}
//
// @Override
// public void recover(List<Set<Long>> usedTierIndexesBySegment) {
// for (int visitedSegmentIndex = 0; visitedSegmentIndex < usedTierIndexesBySegment.size();
// visitedSegmentIndex++) {
// Set<Long> intersection = new HashSet<>(
// usedTierIndexesBySegment.get(visitedSegmentIndex));
// intersection.retainAll(usedTierIndexes);
// if (Collections.dis)
// }
// }
}