Skip to content
Open
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 @@ -53,7 +53,7 @@ public GridCacheConcurrentMapImpl(GridCacheMapEntryFactory factory) {

/** {@inheritDoc} */
@Nullable @Override public GridCacheMapEntry getEntry(GridCacheContext ctx, KeyCacheObject key) {
CacheMapHolder hld = entriesMapIfExists(ctx.cacheIdBoxed());
CacheMapHolder hld = entriesMapIfExists(ctx.cacheId());

key = (KeyCacheObject)ctx.kernalContext().cacheObjects().prepareForCache(key, ctx);

Expand Down Expand Up @@ -87,7 +87,7 @@ protected final GridCacheMapEntry putEntryIfObsoleteOrAbsent(
final boolean skipReserve
) {
if (hld == null)
hld = entriesMapIfExists(ctx.cacheIdBoxed());
hld = entriesMapIfExists(ctx.cacheId());

GridCacheMapEntry cur = null;
GridCacheMapEntry created = null;
Expand Down Expand Up @@ -247,7 +247,7 @@ else if (sizeChange == -1)
* @param cacheId Cache ID.
* @return Map for given cache ID.
*/
@Nullable protected abstract CacheMapHolder entriesMapIfExists(Integer cacheId);
@Nullable protected abstract CacheMapHolder entriesMapIfExists(int cacheId);

/**
*
Expand Down Expand Up @@ -279,7 +279,7 @@ else if (sizeChange == -1)
@Override public boolean removeEntry(final GridCacheEntryEx entry) {
GridCacheContext ctx = entry.context();

CacheMapHolder hld = entriesMapIfExists(ctx.cacheIdBoxed());
CacheMapHolder hld = entriesMapIfExists(ctx.cacheId());

boolean rmv = hld != null && hld.map.remove(entry.key(), entry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ public class GridCacheContext<K, V> implements Externalizable {
/** Cache ID. */
private int cacheId;

/** Cache ID. */
private Integer cacheIdBoxed;

/** Cache type. */
private CacheType cacheType;

Expand Down Expand Up @@ -404,8 +401,6 @@ public GridCacheContext(

cacheId = CU.cacheId(cacheName);

cacheIdBoxed = cacheId;

plc = cacheType.ioPolicy();

Factory<ExpiryPolicy> factory = cacheCfg.getExpiryPolicyFactory();
Expand Down Expand Up @@ -596,13 +591,6 @@ public int cacheId() {
return cacheId;
}

/**
* @return Cache ID.
*/
public Integer cacheIdBoxed() {
return cacheIdBoxed;
}

/**
* @return {@code True} if should use system transactions which are isolated from user transactions.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public GridCacheLocalConcurrentMap(GridCacheContext cctx, GridCacheMapEntryFacto
}

/** {@inheritDoc} */
@Nullable @Override protected CacheMapHolder entriesMapIfExists(Integer cacheId) {
@Nullable @Override protected CacheMapHolder entriesMapIfExists(int cacheId) {
return entryMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
import org.apache.ignite.internal.util.GridLongList;
import org.apache.ignite.internal.util.GridSpinBusyLock;
import org.apache.ignite.internal.util.GridStripedLock;
import org.apache.ignite.internal.util.collection.CopyOnWriteIntMap;
import org.apache.ignite.internal.util.collection.ImmutableIntSet;
import org.apache.ignite.internal.util.collection.IntMap;
import org.apache.ignite.internal.util.collection.IntRWHashMap;
import org.apache.ignite.internal.util.collection.IntSet;
import org.apache.ignite.internal.util.lang.GridCloseableIterator;
import org.apache.ignite.internal.util.lang.GridCursor;
Expand Down Expand Up @@ -1226,7 +1226,7 @@ public static class CacheDataStoreImpl implements CacheDataStore {
private final LongAdder storageSize = new LongAdder();

/** */
private final IntMap<AtomicLong> cacheSizes = new IntRWHashMap<>();
private final IntMap<AtomicLong> cacheSizes = new CopyOnWriteIntMap<>();

/** */
private final IgniteLogger log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
import org.apache.ignite.internal.processors.query.QueryUtils;
import org.apache.ignite.internal.systemview.BinaryMetadataViewWalker;
import org.apache.ignite.internal.util.MutableSingletonList;
import org.apache.ignite.internal.util.collection.CopyOnWriteIntMap;
import org.apache.ignite.internal.util.collection.IntMap;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
import org.apache.ignite.internal.util.lang.GridMapEntry;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
Expand Down Expand Up @@ -168,7 +170,7 @@ public class CacheObjectBinaryProcessorImpl extends GridProcessorAdapter impleme
private BinaryMetadataTransport transport;

/** Cached affinity key field names. */
private final ConcurrentHashMap<Integer, T1<BinaryField>> affKeyFields = new ConcurrentHashMap<>();
private final IntMap<T1<BinaryField>> affKeyFields = new CopyOnWriteIntMap<>();

/** Dummy {@code CacheObjectValueContext} used for mocking. */
private CacheObjectValueContext fakeCacheObjCtx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
import org.apache.ignite.internal.processors.cache.transactions.TxCounters;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.util.GridLongList;
import org.apache.ignite.internal.util.collection.CopyOnWriteIntMap;
import org.apache.ignite.internal.util.collection.IntMap;
import org.apache.ignite.internal.util.collection.IntRWHashMap;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
import org.apache.ignite.internal.util.lang.GridIterator;
Expand Down Expand Up @@ -198,7 +198,7 @@ public GridDhtLocalPartition(

if (grp.sharedGroup()) {
singleCacheEntryMap = null;
cacheMaps = new IntRWHashMap<>();
cacheMaps = new CopyOnWriteIntMap<>();
}
else {
GridCacheContext cctx = grp.singleCacheContext();
Expand Down Expand Up @@ -276,7 +276,7 @@ private ConcurrentMap<KeyCacheObject, GridCacheMapEntry> createEntriesMap() {
}

/** {@inheritDoc} */
@Nullable @Override protected CacheMapHolder entriesMapIfExists(Integer cacheId) {
@Nullable @Override protected CacheMapHolder entriesMapIfExists(int cacheId) {
return grp.sharedGroup() ? cacheMaps.get(cacheId) : singleCacheEntryMap;
}

Expand All @@ -287,15 +287,15 @@ private ConcurrentMap<KeyCacheObject, GridCacheMapEntry> createEntriesMap() {
private CacheMapHolder cacheMapHolder(GridCacheContext cctx) {
assert grp.sharedGroup();

CacheMapHolder hld = cacheMaps.get(cctx.cacheIdBoxed());
CacheMapHolder hld = cacheMaps.get(cctx.cacheId());

if (hld != null)
return hld;

if (cctx.isNear())
cctx = cctx.near().dht().context();

CacheMapHolder old = cacheMaps.putIfAbsent(cctx.cacheIdBoxed(), hld = ctx.kernalContext().resource().resolve(
CacheMapHolder old = cacheMaps.putIfAbsent(cctx.cacheId(), hld = ctx.kernalContext().resource().resolve(
new CacheMapHolder(cctx, createEntriesMap())));

if (old != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.ignite.internal.processors.metric.impl.LongAdderWithDelegateMetric;
import org.apache.ignite.internal.processors.metric.impl.MetricUtils;
import org.apache.ignite.internal.processors.metric.impl.PeriodicHistogramMetricImpl;
import org.apache.ignite.internal.util.collection.IntHashMap;
import org.apache.ignite.internal.util.collection.CopyOnWriteIntMap;
import org.apache.ignite.internal.util.collection.IntMap;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
Expand Down Expand Up @@ -95,16 +95,8 @@ private static LongAdderMetricDelegate delegate(LongAdderMetric delegate) {
/** */
private final DataRegionMetricsProvider dataRegionMetricsProvider;

/**
* Cache group ID -> Cache group memory page metrics.
* <p>
* This is effectively a copy-on-write hash map, all write operations should create a new copy under the
* {@link #cacheGrpMetricsLock} lock.
*/
private volatile IntMap<PageMetrics> cacheGrpMetrics = new IntHashMap<>();

/** Lock for the {@link #cacheGrpMetrics} field. */
private final Object cacheGrpMetricsLock = new Object();
/** Cache group ID -> Cache group memory page metrics. */
private final IntMap<PageMetrics> cacheGrpMetrics = new CopyOnWriteIntMap<>();

/** Memory page metrics for the whole region. */
private final PageMetrics dataRegionPageMetrics;
Expand Down Expand Up @@ -606,31 +598,14 @@ public PageMetrics cacheGrpPageMetrics(int cacheGrpId) {
if (pageMetrics != null)
return pageMetrics;

synchronized (cacheGrpMetricsLock) {
IntMap<PageMetrics> locCacheGrpMetrics = cacheGrpMetrics;

// double check
PageMetrics doubleCheckPageMetrics = locCacheGrpMetrics.get(cacheGrpId);
if (doubleCheckPageMetrics != null)
return doubleCheckPageMetrics;

IntMap<PageMetrics> copy = new IntHashMap<>(locCacheGrpMetrics);

PageMetrics newMetrics = Optional.of(kernalCtx)
// both cache and group descriptor can be null
.map(GridKernalContext::cache)
.map(cache -> cache.cacheGroupDescriptors().get(cacheGrpId))
.map(decs -> createCacheGrpPageMetrics(decs.cacheOrGroupName()))
// return region-wide metrics for a non-existent cache group ID. This is needed in some scenarios
// when per-group data structures are used on a per-region basis and in tests.
.orElse(dataRegionPageMetrics);

copy.put(cacheGrpId, newMetrics);

cacheGrpMetrics = copy;

return newMetrics;
}
return cacheGrpMetrics.computeIfAbsent(cacheGrpId, id -> Optional.of(kernalCtx)
// both cache and group descriptor can be null
.map(GridKernalContext::cache)
.map(cache -> cache.cacheGroupDescriptors().get(id))
.map(decs -> createCacheGrpPageMetrics(decs.cacheOrGroupName()))
// return region-wide metrics for a non-existent cache group ID. This is needed in some scenarios
// when per-group data structures are used on a per-region basis and in tests.
.orElse(dataRegionPageMetrics));
}

/**
Expand All @@ -650,15 +625,7 @@ private PageMetrics createCacheGrpPageMetrics(String cacheGrpName) {
* Removes all memory page metrics associated with the given cache group.
*/
public void removeCacheGrpPageMetrics(Integer grpId) {
PageMetrics rmvMetrics;

synchronized (cacheGrpMetricsLock) {
IntMap<PageMetrics> copy = new IntHashMap<>(cacheGrpMetrics);

rmvMetrics = copy.remove(grpId);

cacheGrpMetrics = copy;
}
PageMetrics rmvMetrics = cacheGrpMetrics.remove(grpId);

// we don't decrease the total pages counter for historical reasons
// (it hasn't been done in previous implementations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ public class CopyOnWriteIntMap<V> implements IntMap<V> {
}

/** {@inheritDoc} */
@Override public synchronized @Nullable V computeIfAbsent(int key, IntFunction<? extends V> mappingFunction) {
@Override public @Nullable V computeIfAbsent(int key, IntFunction<? extends V> mappingFunction) {
V val = get(key);

return val != null ? val : computeIfAbsentUnderLock(key, mappingFunction);
}

/** Slow path of {@link #computeIfAbsent}: the mapping function runs under the map lock. */
private synchronized V computeIfAbsentUnderLock(int key, IntFunction<? extends V> mappingFunction) {
// The default implementation is a lookup followed by a put, the lock makes the pair atomic.
return IntMap.super.computeIfAbsent(key, mappingFunction);
}
Expand Down
Loading