Skip to content

Commit

Permalink
Merge pull request #7874 from ahmetmircik/fix/3.6.2/mapContainerRefs
Browse files Browse the repository at this point in the history
[Backport] Fixes index creation in wrong map-container problem
  • Loading branch information
ahmetmircik committed Mar 31, 2016
2 parents 1d9bb77 + 01e398a commit 662b8da
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import com.hazelcast.spi.NodeEngine;
import com.hazelcast.spi.RemoteService;

import java.util.Map;

import static com.hazelcast.map.impl.MapConfigValidator.checkInMemoryFormat;
import static com.hazelcast.map.impl.MapService.SERVICE_NAME;

/**
* Defines remote service behavior of map service.
Expand Down Expand Up @@ -60,14 +57,6 @@ public DistributedObject createDistributedObject(String name) {
@Override
public void destroyDistributedObject(String name) {
mapServiceContext.destroyMap(name);
nodeEngine.getEventService().deregisterAllListeners(SERVICE_NAME, name);
Map<String, MapContainer> mapContainers = mapServiceContext.getMapContainers();
MapContainer mapContainer = mapContainers.get(name);
if (mapContainer != null) {
mapServiceContext.getNearCacheProvider().destroyNearCache(name);
mapContainer.getMapStoreContext().stop();
mapContainers.remove(name);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,6 @@ public interface MapServiceContext extends MapServiceContextInterceptorSupport,
Extractors getExtractors(String mapName);

void incrementOperationStats(long startTime, LocalMapStatsImpl localMapStats, String mapName, Operation operation);

void removeMapContainer(MapContainer mapContainer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,29 @@ public void flushMaps() {
}

@Override
public void destroyMap(final String mapName) {
localMapStatsProvider.destroyLocalMapStatsImpl(mapName);
final PartitionContainer[] containers = partitionContainers;
final Semaphore semaphore = new Semaphore(0);
public void destroyMap(String mapName) {
MapContainer mapContainer = mapContainers.get(mapName);
if (mapContainer == null) {
return;
}
mapContainer.getMapStoreContext().stop();
nearCacheProvider.destroyNearCache(mapName);
nodeEngine.getEventService().deregisterAllListeners(SERVICE_NAME, mapName);
localMapStatsProvider.destroyLocalMapStatsImpl(mapContainer.getName());

destroyPartitionsAndMapContainer(mapContainer);
}

private void destroyPartitionsAndMapContainer(MapContainer mapContainer) {
Semaphore semaphore = new Semaphore(0);
InternalOperationService operationService = (InternalOperationService) nodeEngine.getOperationService();
for (final PartitionContainer container : containers) {
MapPartitionDestroyTask partitionDestroyTask = new MapPartitionDestroyTask(container, mapName, semaphore);
for (PartitionContainer container : partitionContainers) {
MapPartitionDestroyTask partitionDestroyTask = new MapPartitionDestroyTask(container, mapContainer, semaphore);
operationService.execute(partitionDestroyTask);
}

try {
semaphore.tryAcquire(containers.length, DESTROY_TIMEOUT_SECONDS, TimeUnit.SECONDS);
semaphore.tryAcquire(partitionContainers.length, DESTROY_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
}
Expand Down Expand Up @@ -541,4 +552,9 @@ public RecordStore createRecordStore(MapContainer mapContainer, int partitionId,
ILogger logger = nodeEngine.getLogger(DefaultRecordStore.class);
return new DefaultRecordStore(mapContainer, partitionId, keyLoader, logger);
}

@Override
public void removeMapContainer(MapContainer mapContainer) {
mapContainers.remove(mapContainer.getName(), mapContainer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public RecordStore getExistingRecordStore(String mapName) {
return maps.get(mapName);
}

public void destroyMap(String name) {
public void destroyMap(MapContainer mapContainer) {
String name = mapContainer.getName();
RecordStore recordStore = maps.remove(name);
if (recordStore != null) {
recordStore.destroy();
Expand All @@ -135,6 +136,9 @@ public void destroyMap(String name) {
// this IMap partition.
clearLockStore(name);
}

MapServiceContext mapServiceContext = mapService.getMapServiceContext();
mapServiceContext.removeMapContainer(mapContainer);
}

private void clearLockStore(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
package com.hazelcast.map.impl.operation;


import com.hazelcast.map.impl.MapContainer;
import com.hazelcast.map.impl.PartitionContainer;
import com.hazelcast.spi.impl.PartitionSpecificRunnable;
import java.util.concurrent.Semaphore;

public class MapPartitionDestroyTask implements PartitionSpecificRunnable {
private final PartitionContainer partitionContainer;
private final String mapName;
private final MapContainer mapContainer;
private Semaphore semaphore;

public MapPartitionDestroyTask(PartitionContainer partitionContainer, String mapName, Semaphore semaphore) {
this.partitionContainer = partitionContainer;
this.mapName = mapName;
public MapPartitionDestroyTask(PartitionContainer container, MapContainer mapContainer, Semaphore semaphore) {
this.partitionContainer = container;
this.mapContainer = mapContainer;
this.semaphore = semaphore;
}

@Override
public void run() {
partitionContainer.destroyMap(mapName);
partitionContainer.destroyMap(mapContainer);
semaphore.release();
}

Expand Down

0 comments on commit 662b8da

Please sign in to comment.