Search in sources :

Example 1 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class CacheMetricsImpl method getEntriesStat.

/**
 * Calculates entries count/partitions count metrics using one iteration over local partitions for all metrics
 */
public EntriesStatMetrics getEntriesStat() {
    int owningPartCnt = 0;
    int movingPartCnt = 0;
    long offHeapEntriesCnt = 0L;
    long offHeapPrimaryEntriesCnt = 0L;
    long offHeapBackupEntriesCnt = 0L;
    long heapEntriesCnt = 0L;
    int size = 0;
    long sizeLong = 0L;
    boolean isEmpty;
    try {
        AffinityTopologyVersion topVer = cctx.affinity().affinityTopologyVersion();
        if (AffinityTopologyVersion.NONE.equals(topVer))
            return unknownEntriesStat();
        final GridCacheAdapter<?, ?> cache = cctx.cache();
        if (cache != null) {
            offHeapEntriesCnt = cache.offHeapEntriesCount();
            size = cache.localSize(null);
            sizeLong = cache.localSizeLong(null);
        }
        if (cctx.isLocal()) {
            if (cache != null) {
                offHeapPrimaryEntriesCnt = offHeapEntriesCnt;
                heapEntriesCnt = cache.sizeLong();
            }
        } else {
            IntSet primaries = ImmutableIntSet.wrap(cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer));
            IntSet backups = ImmutableIntSet.wrap(cctx.affinity().backupPartitions(cctx.localNodeId(), topVer));
            if (cctx.isNear() && cache != null)
                heapEntriesCnt = cache.nearSize();
            for (GridDhtLocalPartition part : cctx.topology().currentLocalPartitions()) {
                // Partitions count.
                GridDhtPartitionState partState = part.state();
                if (partState == GridDhtPartitionState.OWNING)
                    owningPartCnt++;
                if (partState == GridDhtPartitionState.MOVING)
                    movingPartCnt++;
                // Offheap entries count
                if (cache == null)
                    continue;
                long cacheSize = part.dataStore().cacheSize(cctx.cacheId());
                if (primaries.contains(part.id()))
                    offHeapPrimaryEntriesCnt += cacheSize;
                else if (backups.contains(part.id()))
                    offHeapBackupEntriesCnt += cacheSize;
                heapEntriesCnt += part.publicSize(cctx.cacheId());
            }
        }
    } catch (Exception e) {
        return unknownEntriesStat();
    }
    isEmpty = (offHeapEntriesCnt == 0);
    EntriesStatMetrics stat = new EntriesStatMetrics();
    stat.offHeapEntriesCount(offHeapEntriesCnt);
    stat.offHeapPrimaryEntriesCount(offHeapPrimaryEntriesCnt);
    stat.offHeapBackupEntriesCount(offHeapBackupEntriesCnt);
    stat.heapEntriesCount(heapEntriesCnt);
    stat.size(size);
    stat.cacheSize(sizeLong);
    stat.keySize(size);
    stat.isEmpty(isEmpty);
    stat.totalPartitionsCount(owningPartCnt + movingPartCnt);
    stat.rebalancingPartitionsCount(movingPartCnt);
    return stat;
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IntSet(org.apache.ignite.internal.util.collection.IntSet) ImmutableIntSet(org.apache.ignite.internal.util.collection.ImmutableIntSet) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Example 2 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method assignPartitionStates.

/**
 * Collects and determines new owners of partitions for all nodes for given {@code top}.
 *
 * @param top Topology to assign.
 * @param resetOwners True if need to reset partition state considering of counter, false otherwise.
 * @return Partitions supply info list.
 */
private List<SupplyPartitionInfo> assignPartitionStates(GridDhtPartitionTopology top, boolean resetOwners) {
    Map<Integer, CounterWithNodes> maxCntrs = new HashMap<>();
    Map<Integer, TreeSet<Long>> varCntrs = new HashMap<>();
    for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : msgs.entrySet()) {
        CachePartitionPartialCountersMap nodeCntrs = e.getValue().partitionUpdateCounters(top.groupId(), top.partitions());
        assert nodeCntrs != null;
        for (int i = 0; i < nodeCntrs.size(); i++) {
            int p = nodeCntrs.partitionAt(i);
            UUID remoteNodeId = e.getKey();
            GridDhtPartitionState state = top.partitionState(remoteNodeId, p);
            if (state != GridDhtPartitionState.OWNING && state != GridDhtPartitionState.MOVING)
                continue;
            long cntr = state == GridDhtPartitionState.MOVING ? nodeCntrs.initialUpdateCounterAt(i) : nodeCntrs.updateCounterAt(i);
            varCntrs.computeIfAbsent(p, key -> new TreeSet<>()).add(cntr);
            if (state != GridDhtPartitionState.OWNING)
                continue;
            CounterWithNodes maxCntr = maxCntrs.get(p);
            if (maxCntr == null || cntr > maxCntr.cnt)
                maxCntrs.put(p, new CounterWithNodes(cntr, e.getValue().partitionSizes(top.groupId()).get(p), remoteNodeId));
            else if (cntr == maxCntr.cnt)
                maxCntr.nodes.add(remoteNodeId);
        }
    }
    // Also must process counters from the local node.
    for (GridDhtLocalPartition part : top.currentLocalPartitions()) {
        GridDhtPartitionState state = top.partitionState(cctx.localNodeId(), part.id());
        if (state != GridDhtPartitionState.OWNING && state != GridDhtPartitionState.MOVING)
            continue;
        final long cntr = state == GridDhtPartitionState.MOVING ? part.initialUpdateCounter() : part.updateCounter();
        varCntrs.computeIfAbsent(part.id(), key -> new TreeSet<>()).add(cntr);
        if (state != GridDhtPartitionState.OWNING)
            continue;
        CounterWithNodes maxCntr = maxCntrs.get(part.id());
        if (maxCntr == null && cntr == 0) {
            CounterWithNodes cntrObj = new CounterWithNodes(0, 0L, cctx.localNodeId());
            for (UUID nodeId : msgs.keySet()) {
                if (top.partitionState(nodeId, part.id()) == GridDhtPartitionState.OWNING)
                    cntrObj.nodes.add(nodeId);
            }
            maxCntrs.put(part.id(), cntrObj);
        } else if (maxCntr == null || cntr > maxCntr.cnt)
            maxCntrs.put(part.id(), new CounterWithNodes(cntr, part.fullSize(), cctx.localNodeId()));
        else if (cntr == maxCntr.cnt)
            maxCntr.nodes.add(cctx.localNodeId());
    }
    Set<Integer> haveHistory = new HashSet<>();
    List<SupplyPartitionInfo> list = assignHistoricalSuppliers(top, maxCntrs, varCntrs, haveHistory);
    if (resetOwners)
        resetOwnersByCounter(top, maxCntrs, haveHistory);
    return list;
}
Also used : GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) NoopSpan(org.apache.ignite.internal.processors.tracing.NoopSpan) Map(java.util.Map) GridIoPolicy(org.apache.ignite.internal.managers.communication.GridIoPolicy) ExchangeContext(org.apache.ignite.internal.processors.cache.ExchangeContext) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) Latch(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.latch.Latch) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) Set(java.util.Set) ChangeGlobalStateFinishMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateFinishMessage) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IGNITE_PARTITION_RELEASE_FUTURE_DUMP_THRESHOLD(org.apache.ignite.IgniteSystemProperties.IGNITE_PARTITION_RELEASE_FUTURE_DUMP_THRESHOLD) CountDownLatch(java.util.concurrent.CountDownLatch) SnapshotDiscoveryMessage(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotDiscoveryMessage) EternalExpiryPolicy(javax.cache.expiry.EternalExpiryPolicy) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT(org.apache.ignite.IgniteSystemProperties.IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT) SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) ExchangeRecord(org.apache.ignite.internal.pagemem.wal.record.ExchangeRecord) SecurityUtils.remoteSecurityContext(org.apache.ignite.internal.processors.security.SecurityUtils.remoteSecurityContext) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) EVT_DISCOVERY_CUSTOM_EVT(org.apache.ignite.internal.events.DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) IgniteLogger(org.apache.ignite.IgniteLogger) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) LinkedHashMap(java.util.LinkedHashMap) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) S(org.apache.ignite.internal.util.typedef.internal.S) IgniteDiagnosticAware(org.apache.ignite.internal.IgniteDiagnosticAware) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) Stream.concat(java.util.stream.Stream.concat) LinkedHashSet(java.util.LinkedHashSet) DynamicCacheChangeFailureMessage(org.apache.ignite.internal.processors.cache.DynamicCacheChangeFailureMessage) IOException(java.io.IOException) T2(org.apache.ignite.internal.util.typedef.T2) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) Lock(java.util.concurrent.locks.Lock) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) DatabaseLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.DatabaseLifecycleListener) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) ATTR_DYNAMIC_CACHE_START_ROLLBACK_SUPPORTED(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_DYNAMIC_CACHE_START_ROLLBACK_SUPPORTED) CacheMode(org.apache.ignite.cache.CacheMode) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) DynamicCacheChangeRequest(org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest) ExchangeDiscoveryEvents.serverLeftEvent(org.apache.ignite.internal.processors.cache.ExchangeDiscoveryEvents.serverLeftEvent) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) IgniteSystemProperties.getBoolean(org.apache.ignite.IgniteSystemProperties.getBoolean) TimeBag(org.apache.ignite.internal.util.TimeBag) StateChangeRequest(org.apache.ignite.internal.processors.cache.StateChangeRequest) GridDhtPartitionsStateValidator(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator) SYSTEM_POOL(org.apache.ignite.internal.managers.communication.GridIoPolicy.SYSTEM_POOL) IgniteChangeGlobalStateSupport(org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) X(org.apache.ignite.internal.util.typedef.X) GridPlainCallable(org.apache.ignite.internal.util.lang.GridPlainCallable) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) FailureType(org.apache.ignite.failure.FailureType) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) SpanTags(org.apache.ignite.internal.processors.tracing.SpanTags) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IgniteSnapshotManager.isSnapshotOperation(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.isSnapshotOperation) NavigableSet(java.util.NavigableSet) IgniteDiagnosticPrepareContext(org.apache.ignite.internal.IgniteDiagnosticPrepareContext) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IgniteUtils.doInParallelUninterruptibly(org.apache.ignite.internal.util.IgniteUtils.doInParallelUninterruptibly) IgniteSystemProperties.getLong(org.apache.ignite.IgniteSystemProperties.getLong) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) CU(org.apache.ignite.internal.util.typedef.internal.CU) IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT_LIMIT(org.apache.ignite.IgniteSystemProperties.IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT_LIMIT) Optional(java.util.Optional) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ExchangeDiscoveryEvents(org.apache.ignite.internal.processors.cache.ExchangeDiscoveryEvents) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Span(org.apache.ignite.internal.processors.tracing.Span) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) HashMap(java.util.HashMap) WalStateAbstractMessage(org.apache.ignite.internal.processors.cache.WalStateAbstractMessage) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridClientPartitionTopology) FailureContext(org.apache.ignite.failure.FailureContext) IgniteUtils.doInParallel(org.apache.ignite.internal.util.IgniteUtils.doInParallel) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) CachePartitionExchangeWorkerTask(org.apache.ignite.internal.processors.cache.CachePartitionExchangeWorkerTask) GridDhtTopologyFutureAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFutureAdapter) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) Collections.emptySet(java.util.Collections.emptySet) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) ExchangeDiscoveryEvents.serverJoinEvent(org.apache.ignite.internal.processors.cache.ExchangeDiscoveryEvents.serverJoinEvent) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) PARTIAL_COUNTERS_MAP_SINCE(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap.PARTIAL_COUNTERS_MAP_SINCE) GridToStringInclude(org.apache.ignite.internal.util.tostring.GridToStringInclude) TimeUnit(java.util.concurrent.TimeUnit) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) Collections(java.util.Collections) GridCacheUtils(org.apache.ignite.internal.processors.cache.GridCacheUtils) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) UUID(java.util.UUID) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 3 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class GridCacheQueryManager method scanIterator.

/**
 * @param qry Query.
 * @param transformer Transformer.
 * @param locNode Local node.
 * @return Full-scan row iterator.
 * @throws IgniteCheckedException If failed to get iterator.
 */
@SuppressWarnings({ "unchecked" })
private GridCloseableIterator scanIterator(final GridCacheQueryAdapter<?> qry, IgniteClosure transformer, boolean locNode) throws IgniteCheckedException {
    assert !cctx.mvccEnabled() || qry.mvccSnapshot() != null;
    final IgniteBiPredicate<K, V> keyValFilter = qry.scanFilter();
    final InternalScanFilter<K, V> intFilter = keyValFilter != null ? new InternalScanFilter<>(keyValFilter) : null;
    try {
        if (keyValFilter instanceof PlatformCacheEntryFilter)
            ((PlatformCacheEntryFilter) keyValFilter).cacheContext(cctx);
        else
            injectResources(keyValFilter);
        Integer part = cctx.isLocal() ? null : qry.partition();
        if (part != null && (part < 0 || part >= cctx.affinity().partitions()))
            return new GridEmptyCloseableIterator() {

                @Override
                public void close() throws IgniteCheckedException {
                    if (intFilter != null)
                        intFilter.close();
                    super.close();
                }
            };
        AffinityTopologyVersion topVer = GridQueryProcessor.getRequestAffinityTopologyVersion();
        if (topVer == null)
            topVer = cctx.affinity().affinityTopologyVersion();
        final boolean backups = qry.includeBackups() || cctx.isReplicated();
        final GridDhtLocalPartition locPart;
        final GridIterator<CacheDataRow> it;
        if (part != null) {
            final GridDhtCacheAdapter dht = cctx.isNear() ? cctx.near().dht() : cctx.dht();
            GridDhtLocalPartition locPart0 = dht.topology().localPartition(part, topVer, false);
            if (locPart0 == null || locPart0.state() != OWNING || !locPart0.reserve()) {
                throw locPart0 != null && locPart0.state() == LOST ? new CacheInvalidStateException("Failed to execute scan query because cache partition has been " + "lost [cacheName=" + cctx.name() + ", part=" + part + "]") : new GridDhtUnreservedPartitionException(part, cctx.affinity().affinityTopologyVersion(), "Partition can not be reserved");
            }
            locPart = locPart0;
            it = cctx.offheap().cachePartitionIterator(cctx.cacheId(), part, qry.mvccSnapshot(), qry.isDataPageScanEnabled());
        } else {
            locPart = null;
            if (!cctx.isLocal()) {
                final GridDhtCacheAdapter dht = cctx.isNear() ? cctx.near().dht() : cctx.dht();
                Set<Integer> lostParts = dht.topology().lostPartitions();
                if (!lostParts.isEmpty()) {
                    throw new CacheInvalidStateException("Failed to execute scan query because cache partition " + "has been lost [cacheName=" + cctx.name() + ", part=" + lostParts.iterator().next() + "]");
                }
            }
            it = cctx.offheap().cacheIterator(cctx.cacheId(), true, backups, topVer, qry.mvccSnapshot(), qry.isDataPageScanEnabled());
        }
        ScanQueryIterator iter = new ScanQueryIterator(it, qry, topVer, locPart, SecurityUtils.sandboxedProxy(cctx.kernalContext(), IgniteBiPredicate.class, keyValFilter), SecurityUtils.sandboxedProxy(cctx.kernalContext(), IgniteClosure.class, transformer), locNode, locNode ? locIters : null, cctx, log);
        if (locNode) {
            ScanQueryIterator old = locIters.addx(iter);
            assert old == null;
        }
        return iter;
    } catch (IgniteCheckedException | RuntimeException e) {
        if (intFilter != null)
            intFilter.close();
        throw e;
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) IgniteClosure(org.apache.ignite.lang.IgniteClosure) GridDhtUnreservedPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnreservedPartitionException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) GridEmptyCloseableIterator(org.apache.ignite.internal.util.GridEmptyCloseableIterator) PlatformCacheEntryFilter(org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException)

Example 4 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class GridCacheContext method checkAndReservePartition.

/**
 * @param part Partition.
 * @param topVer Topology version.
 * @return {@code True} if partition is available locally.
 */
private boolean checkAndReservePartition(int part, AffinityTopologyVersion topVer) {
    assert affinityNode();
    GridDhtPartitionTopology top = topology();
    if (isReplicated() && !group().persistenceEnabled()) {
        boolean rebFinished = top.rebalanceFinished(topVer);
        if (rebFinished)
            return true;
        GridDhtLocalPartition locPart = top.localPartition(part, topVer, false, false);
        // No need to reserve a partition for REPLICATED cache because this partition cannot be evicted.
        return locPart != null && locPart.state() == OWNING;
    } else {
        GridDhtLocalPartition locPart = top.localPartition(part, topVer, false, false);
        if (locPart != null && locPart.reserve()) {
            boolean canRead = true;
            try {
                canRead = locPart.state() == OWNING;
                return canRead;
            } finally {
                if (!canRead)
                    locPart.release();
            }
        } else
            return false;
    }
}
Also used : GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Example 5 with GridDhtLocalPartition

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.

the class GridCacheContext method releaseForFastLocalGet.

/**
 * Releases the partition that was reserved by a call to
 * {@link #reserveForFastLocalGet(int, AffinityTopologyVersion)}.
 *
 * @param part Partition to release.
 * @param topVer Topology version.
 */
public void releaseForFastLocalGet(int part, AffinityTopologyVersion topVer) {
    assert affinityNode();
    if (!isReplicated() || group().persistenceEnabled()) {
        GridDhtLocalPartition locPart = topology().localPartition(part, topVer, false);
        assert locPart != null && locPart.state() == OWNING : "partition evicted after reserveForFastLocalGet " + "[part=" + part + ", locPart=" + locPart + ", topVer=" + topVer + ']';
        locPart.release();
    }
}
Also used : GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Aggregations

GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)95 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)19 IgniteEx (org.apache.ignite.internal.IgniteEx)19 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)19 ArrayList (java.util.ArrayList)18 Map (java.util.Map)18 Test (org.junit.Test)18 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)16 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)15 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)15 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)13 AtomicLong (java.util.concurrent.atomic.AtomicLong)13 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)13 Ignite (org.apache.ignite.Ignite)12 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)12 IgniteException (org.apache.ignite.IgniteException)11