Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid excessive garbage in map#clear() for TS [HZ-3620] #26127

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.hazelcast.map.impl.operation.steps.ClearOpSteps;
import com.hazelcast.map.impl.operation.steps.engine.State;
import com.hazelcast.map.impl.operation.steps.engine.Step;
import com.hazelcast.map.impl.recordstore.DefaultRecordStore;
import com.hazelcast.spi.impl.operationservice.BackupAwareOperation;
import com.hazelcast.spi.impl.operationservice.MutatingOperation;
import com.hazelcast.spi.impl.operationservice.Operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
import com.hazelcast.map.impl.operation.steps.engine.Step;
import com.hazelcast.map.impl.record.Record;
import com.hazelcast.map.impl.recordstore.DefaultRecordStore;
import com.hazelcast.map.impl.recordstore.RecordStore;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

Expand All @@ -45,21 +48,32 @@ public void runStep(State state) {
ArrayList<Data> keys = new ArrayList<>();
ArrayList<Record> records = new ArrayList<>();
// we don't remove locked keys. These are clearable records.
recordStore.forEach(new BiConsumer<>() {
final Set<Data> lockedKeySet = recordStore.getLockStore().getLockedKeys();

@Override
public void accept(Data dataKey, Record record) {
if (lockedKeySet != null && !lockedKeySet.contains(dataKey)) {
keys.add(recordStore.isTieredStorageEnabled() ? toHeapData(dataKey) : dataKey);
final Set<Data> lockedKeySet = recordStore.getLockStore().getLockedKeys();
final Iterator<Map.Entry<Data, Record>> iterator = recordStore.iterator();
boolean tieredStorageEnabled = recordStore.isTieredStorageEnabled();;

while (iterator.hasNext()) {
Map.Entry<Data, Record> entry = iterator.next();
Data dataKey = entry.getKey();
Record record = entry.getValue();

if (lockedKeySet != null && !lockedKeySet.contains(dataKey)) {
keys.add(tieredStorageEnabled ? toHeapData(dataKey) : dataKey);
if (!recordStore.isTieredStorageEnabled()) {
records.add(record);
}
}

if (keys.size() == BATCH_SIZE) {
// Batch filling is completed
break;
}
}, false);
}

state.setKeys(keys);
state.setRecords(records);
if (!tieredStorageEnabled) {
state.setRecords(records);
}
}

@Override
Expand Down Expand Up @@ -102,6 +116,17 @@ public void runStep(State state) {

@Override
public Step nextStep(State state) {
RecordStore recordStore = state.getRecordStore();
int currentSize = recordStore.size();
final Set<Data> lockedKeySet = ((DefaultRecordStore) recordStore).getLockStore().getLockedKeys();
int lockedSize = lockedKeySet.size();

if (currentSize - lockedSize > 0) {
// We still have entries to process
// Process them in the next batch
return CLEAR_MEMORY;
}

return UtilSteps.FINAL_STEP;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
*/
public interface IMapOpStep extends Step<State> {

/**
* The batch size of records handled in bulk operations.
*/
int BATCH_SIZE = 1000;

/**
* Decides when to offload based on configured map-store type.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore;
import com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry;
import com.hazelcast.map.impl.operation.MapOperation;
import com.hazelcast.map.impl.operation.steps.ClearOpSteps;
import com.hazelcast.map.impl.operation.steps.engine.Step;
import com.hazelcast.map.impl.querycache.QueryCacheContext;
import com.hazelcast.map.impl.querycache.publisher.MapPublisherRegistry;
import com.hazelcast.map.impl.querycache.publisher.PublisherContext;
Expand Down Expand Up @@ -112,6 +114,12 @@ public class DefaultRecordStore extends AbstractEvictableRecordStore {
*/
protected final Collection<Future<?>> loadingFutures = new ConcurrentLinkedQueue<>();

/**
* Defined by {@link com.hazelcast.spi.properties.ClusterProperty#WAN_REPLICATE_IMAP_EVICTIONS},
* if set to true then eviction operations by this RecordStore will be WAN replicated
*/
protected boolean wanReplicateEvictions;

/**
* A reference to the Json Metadata store. It is initialized lazily only if the
* store is needed.
Expand All @@ -131,11 +139,6 @@ public class DefaultRecordStore extends AbstractEvictableRecordStore {
* key loading.
*/
private boolean loadedOnPreMigration;
/**
* Defined by {@link com.hazelcast.spi.properties.ClusterProperty#WAN_REPLICATE_IMAP_EVICTIONS},
* if set to true then eviction operations by this RecordStore will be WAN replicated
*/
private boolean wanReplicateEvictions;

private final IPartitionService partitionService;
private final InterceptorRegistry interceptorRegistry;
Expand Down
Loading